aboutsummaryrefslogtreecommitdiffhomepage
path: root/install/update_sqlite_from_0_to_1.php
blob: c88af540c5d1ef5519d8bdf1e558ba29f3633c10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

$db_path = 'sqlite:../db/poche.sqlite';
$handle = new PDO($db_path);
$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

# Requêtes à exécuter pour mettre à jour poche.sqlite en 1.x

# ajout d'un champ user_id sur la table entries
$sql = 'ALTER TABLE entries RENAME TO tempEntries;';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'CREATE TABLE entries (id INTEGER PRIMARY KEY, title TEXT, url TEXT, is_read NUMERIC DEFAULT 0, is_fav NUMERIC DEFAULT 0, content BLOB, user_id NUMERIC);';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'INSERT INTO entries (id, title, url, is_read, is_fav, content) SELECT id, title, url, is_read, is_fav, content FROM tempEntries;';
$query = $handle->prepare($sql);
$query->execute();

# Update tout pour mettre user_id = 1
$sql = 'UPDATE entries SET user_id = 1;';
$query = $handle->prepare($sql);
$query->execute();

# Changement des flags pour les lus / favoris
$sql = 'UPDATE entries SET is_read = 1 WHERE is_read = -1;';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'UPDATE entries SET is_fav = 1 WHERE is_fav = -1;';
$query = $handle->prepare($sql);
$query->execute();

# Création de la table users
$sql = 'CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT, password TEXT, name TEXT, email TEXT);';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'INSERT INTO users (username) SELECT value FROM config WHERE name = "login";';
$query = $handle->prepare($sql);
$query->execute();

$sql = "UPDATE users SET password = (SELECT value FROM config WHERE name = 'password')";
$query = $handle->prepare($sql);
$query->execute();

# Création de la table users_config
$sql = 'CREATE TABLE users_config (id INTEGER PRIMARY KEY, user_id NUMERIC, name TEXT, value TEXT);';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'INSERT INTO users_config (user_id, name, value) VALUES (1, "pager", "10");';
$query = $handle->prepare($sql);
$query->execute();

$sql = 'INSERT INTO users_config (user_id, name, value) VALUES (1, "language", "en_EN.UTF8");';
$query = $handle->prepare($sql);
$query->execute();

# Suppression de la table temporaire
$sql = 'DROP TABLE tempEntries;';
$query = $handle->prepare($sql);
$query->execute();

# Vidage de la table de config
$sql = 'DELETE FROM config;';
$query = $handle->prepare($sql);
$query->execute();

echo 'welcome to poche 1.0 !';