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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
<?php
define( 'UPDATE_VERSION' , 1029 );
/**
*
* update.php - automatic system update
*
* Automatically update database schemas and any other development changes such that
* copying the latest files from the source code repository will always perform a clean
* and painless upgrade.
*
* Each function in this file is named update_rnnnn() where nnnn is an increasing number
* which began counting at 1000.
*
* At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
* to the database schema or one which requires an upgrade path from the existing application,
* the DB_UPDATE_VERSION and the UPDATE_VERSION at the top of this file are incremented.
*
* The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
* and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
* in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
* up to current without requiring re-installation or manual intervention.
*
* Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
* The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
*
* If you change the database schema, the following are required:
* 1. Update the file database.sql to match the new schema.
* 2. Update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
* This function should modify the current database schema and perform any other steps necessary
* to ensure that upgrade is silent and free from requiring interaction.
* 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
* 4. TEST the upgrade prior to checkin and filing a pull request.
*
*/
function update_r1000() {
$r = q("ALTER TABLE `channel` ADD `channel_a_delegate` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT '0', ADD INDEX ( `channel_a_delegate` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1001() {
$r = q("CREATE TABLE if not exists `verify` (
`id` INT(10) UNSIGNED NOT NULL ,
`channel` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`type` CHAR( 32 ) NOT NULL DEFAULT '',
`token` CHAR( 255 ) NOT NULL DEFAULT '',
`meta` CHAR( 255 ) NOT NULL DEFAULT '',
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ");
$r2 = q("alter table `verify` add index (`channel`), add index (`type`), add index (`token`),
add index (`meta`), add index (`created`)");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1002() {
$r = q("ALTER TABLE `event` CHANGE `account` `aid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'");
$r2 = q("alter table `event` drop index `account`, add index (`aid`)");
q("drop table contact");
q("drop table deliverq");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1003() {
$r = q("ALTER TABLE `xchan` ADD `xchan_flags` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `xchan_network` ,
ADD INDEX ( `xchan_flags` ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1004() {
$r = q("CREATE TABLE if not exists `site` (
`site_url` CHAR( 255 ) NOT NULL ,
`site_flags` INT NOT NULL DEFAULT '0',
`site_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`site_directory` CHAR( 255 ) NOT NULL DEFAULT '',
PRIMARY KEY ( `site_url` )
) ENGINE = MYISAM ");
$r2 = q("alter table site add index (site_flags), add index (site_update), add index (site_directory) ");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1005() {
q("drop table guid");
q("drop table `notify-threads`");
return UPDATE_SUCCESS;
}
function update_r1006() {
$r = q("CREATE TABLE IF NOT EXISTS `xprof` (
`xprof_hash` char(255) NOT NULL,
`xprof_desc` char(255) NOT NULL DEFAULT '',
`xprof_dob` char(12) NOT NULL DEFAULT '',
`xprof_gender` char(255) NOT NULL DEFAULT '',
`xprof_marital` char(255) NOT NULL DEFAULT '',
`xprof_sexual` char(255) NOT NULL DEFAULT '',
`xprof_locale` char(255) NOT NULL DEFAULT '',
`xprof_region` char(255) NOT NULL DEFAULT '',
`xprof_postcode` char(32) NOT NULL DEFAULT '',
`xprof_country` char(255) NOT NULL DEFAULT '',
PRIMARY KEY (`xprof_hash`),
KEY `xprof_desc` (`xprof_desc`),
KEY `xprof_dob` (`xprof_dob`),
KEY `xprof_gender` (`xprof_gender`),
KEY `xprof_marital` (`xprof_marital`),
KEY `xprof_sexual` (`xprof_sexual`),
KEY `xprof_locale` (`xprof_locale`),
KEY `xprof_region` (`xprof_region`),
KEY `xprof_postcode` (`xprof_postcode`),
KEY `xprof_country` (`xprof_country`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
$r2 = q("CREATE TABLE IF NOT EXISTS `xtag` (
`xtag_hash` char(255) NOT NULL,
`xtag_term` char(255) NOT NULL DEFAULT '',
PRIMARY KEY (`xtag_hash`),
KEY `xtag_term` (`xtag_term`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1007() {
$r = q("ALTER TABLE `channel` ADD `channel_r_storage` INT UNSIGNED NOT NULL DEFAULT '128', ADD `channel_w_storage` INT UNSIGNED NOT NULL DEFAULT '128', add index ( channel_r_storage ), add index ( channel_w_storage )");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1008() {
$r = q("alter table profile drop prv_keywords, CHANGE `pub_keywords` `keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, drop index pub_keywords");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1009() {
$r = q("ALTER TABLE `xprof` ADD `xprof_keywords` TEXT NOT NULL");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1010() {
$r = q("ALTER TABLE `abook` ADD `abook_dob` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `abook_connnected` ,
ADD INDEX ( `abook_dob` )");
$r2 = q("ALTER TABLE `profile` ADD `dob_tz` CHAR( 255 ) NOT NULL DEFAULT 'UTC' AFTER `dob`");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1011() {
$r = q("ALTER TABLE `item` ADD `expires` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ,
ADD INDEX ( `expires` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1012() {
$r = q("ALTER TABLE `xchan` ADD `xchan_connurl` CHAR( 255 ) NOT NULL DEFAULT '' AFTER `xchan_url` ,
ADD INDEX ( `xchan_connurl` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1013() {
$r = q("CREATE TABLE if not exists `xlink` (
`xlink_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`xlink_xchan` CHAR( 255 ) NOT NULL DEFAULT '',
`xlink_link` CHAR( 255 ) NOT NULL DEFAULT '',
`xlink_updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MYISAM ");
$r2 = q("alter table xlink add index ( xlink_xchan ), add index ( xlink_link ), add index ( xlink_updated ) ");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1014() {
$r = q("ALTER TABLE `verify` CHANGE `id` `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1015() {
$r = q("ALTER TABLE `channel` ADD `channel_r_pages` INT UNSIGNED NOT NULL DEFAULT '128',
ADD `channel_w_pages` INT UNSIGNED NOT NULL DEFAULT '128'");
$r2 = q("ALTER TABLE `channel` ADD INDEX ( `channel_r_pages` ) , ADD INDEX ( `channel_w_pages` ) ");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1016() {
$r = q("CREATE TABLE IF NOT EXISTS `menu` (
`menu_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`menu_channel_id` int(10) unsigned NOT NULL DEFAULT '0',
`menu_desc` char(255) NOT NULL DEFAULT '',
PRIMARY KEY (`menu_id`),
KEY `menu_channel_id` (`menu_channel_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ");
$r2 = q("CREATE TABLE IF NOT EXISTS `menu_item` (
`mitem_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`mitem_link` char(255) NOT NULL DEFAULT '',
`mitem_desc` char(255) NOT NULL DEFAULT '',
`allow_cid` mediumtext NOT NULL,
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
`mitem_channel_id` int(10) unsigned NOT NULL,
`mitem_menu_id` int(10) unsigned NOT NULL DEFAULT '0',
`mitem_order` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`mitem_id`),
KEY `mitem_channel_id` (`mitem_channel_id`),
KEY `mitem_menu_id` (`mitem_menu_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ");
if($r && $r2)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1017() {
$r = q("ALTER TABLE `event` CHANGE `cid` `event_xchan` CHAR( 255 ) NOT NULL DEFAULT '', ADD INDEX ( `event_xchan` ), drop index cid ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1018() {
$r = q("ALTER TABLE `event` ADD `event_hash` CHAR( 255 ) NOT NULL DEFAULT '' AFTER `event_xchan` ,
ADD INDEX ( `event_hash` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1019() {
$r = q("ALTER TABLE `event` DROP `message_id` ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1020() {
$r = q("alter table photo drop `contact-id`, drop guid, drop index `resource-id`, add index ( `resource_id` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1021() {
$r = q("ALTER TABLE `abook` CHANGE `abook_connnected` `abook_connected` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
drop index `abook_connnected`, add index ( `abook_connected` ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1022() {
$r = q("alter table attach add index ( filename ), add index ( filetype ), add index ( filesize ), add index ( created ), add index ( edited ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1023() {
$r = q("ALTER TABLE `item` ADD `revision` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `lang` , add index ( revision ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1024() {
$r = q("ALTER TABLE `attach` ADD `revision` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `filesize` ,
ADD INDEX ( `revision` ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1025() {
$r = q("ALTER TABLE `attach` ADD `folder` CHAR( 64 ) NOT NULL DEFAULT '' AFTER `revision` ,
ADD `flags` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `folder` , add index ( folder ), add index ( flags )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1026() {
$r = q("ALTER TABLE `item` ADD `mimetype` CHAR( 255 ) NOT NULL DEFAULT '' AFTER `author_xchan` ,
ADD INDEX ( `mimetype` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1027() {
$r = q("ALTER TABLE `abook` ADD `abook_rating` INT NOT NULL DEFAULT '0' AFTER `abook_closeness` ,
ADD INDEX ( `abook_rating` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
function update_r1028() {
$r = q"ALTER TABLE `xlink` ADD `xlink_rating` INT NOT NULL DEFAULT '0' AFTER `xlink_link` ,
ADD INDEX ( `xlink_rating` ) ");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
|