-
Notifications
You must be signed in to change notification settings - Fork 132
/
schema.php
169 lines (124 loc) · 3.37 KB
/
schema.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace Schema;
function version_6($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN lazy_loading INTEGER DEFAULT 0');
}
function version_17($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN items_sorting_direction TEXT DEFAULT "desc"');
}
function version_16($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN auth_google_token TEXT DEFAULT ""');
$pdo->exec('ALTER TABLE config ADD COLUMN auth_mozilla_token TEXT DEFAULT ""');
}
function version_15($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN download_content INTEGER DEFAULT 0');
}
function version_14($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN feed_token TEXT DEFAULT "'.\Model\generate_token().'"');
}
function version_13($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1');
}
function version_12($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_token().'"');
}
function version_11($pdo)
{
$rq = $pdo->prepare('
SELECT
items.id, items.url AS item_url, feeds.site_url
FROM items
LEFT JOIN feeds ON feeds.id=items.feed_id
');
$rq->execute();
$items = $rq->fetchAll(\PDO::FETCH_ASSOC);
foreach ($items as $item) {
if ($item['id'] !== $item['item_url']) {
$id = hash('crc32b', $item['id'].$item['site_url']);
}
else {
$id = hash('crc32b', $item['item_url'].$item['site_url']);
}
$rq = $pdo->prepare('UPDATE items SET id=? WHERE id=?');
$rq->execute(array($id, $item['id']));
}
}
function version_10($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN theme TEXT DEFAULT "original"');
}
function version_9($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN items_per_page INTEGER DEFAULT 100');
}
function version_8($pdo)
{
$pdo->exec('ALTER TABLE items ADD COLUMN bookmark INTEGER DEFAULT 0');
}
function version_7($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN nocontent INTEGER DEFAULT 0');
}
function version_6($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN autoflush INTEGER DEFAULT 0');
}
function version_5($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER');
}
function version_4($pdo)
{
$pdo->exec('CREATE INDEX idx_status ON items(status)');
}
function version_3($pdo)
{
$pdo->exec("ALTER TABLE config ADD COLUMN language TEXT DEFAULT 'en_US'");
}
function version_2($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN last_modified TEXT');
$pdo->exec('ALTER TABLE feeds ADD COLUMN etag TEXT');
}
function version_1($pdo)
{
$pdo->exec("
CREATE TABLE config (
username TEXT DEFAULT 'admin',
password TEXT
)
");
$pdo->exec("
INSERT INTO config
(password)
VALUES ('".\password_hash('admin', PASSWORD_BCRYPT)."')
");
$pdo->exec('
CREATE TABLE feeds (
id INTEGER PRIMARY KEY,
site_url TEXT,
feed_url TEXT UNIQUE,
title TEXT COLLATE NOCASE
)
');
$pdo->exec('
CREATE TABLE items (
id TEXT PRIMARY KEY,
url TEXT,
title TEXT,
author TEXT,
content TEXT,
updated INTEGER,
status TEXT,
feed_id INTEGER,
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)
');
}