]> git.mxchange.org Git - friendica.git/blob - database.sql
Use a combined unique index
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2020.12-dev (Red Hot Poker)
3 -- DB_UPDATE_VERSION 1382
4 -- ------------------------------------------
5
6
7 --
8 -- TABLE gserver
9 --
10 CREATE TABLE IF NOT EXISTS `gserver` (
11         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
12         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
13         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
14         `version` varchar(255) NOT NULL DEFAULT '' COMMENT '',
15         `site_name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
16         `info` text COMMENT '',
17         `register_policy` tinyint NOT NULL DEFAULT 0 COMMENT '',
18         `registered-users` int unsigned NOT NULL DEFAULT 0 COMMENT 'Number of registered users',
19         `directory-type` tinyint DEFAULT 0 COMMENT 'Type of directory service (Poco, Mastodon)',
20         `poco` varchar(255) NOT NULL DEFAULT '' COMMENT '',
21         `noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
22         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
23         `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
24         `relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
25         `relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
26         `detection-method` tinyint unsigned COMMENT 'Method that had been used to detect that server',
27         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
28         `last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
29         `last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
30         `last_failure` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
31         `failed` boolean COMMENT 'Connection failed',
32          PRIMARY KEY(`id`),
33          UNIQUE INDEX `nurl` (`nurl`(190))
34 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers';
35
36 --
37 -- TABLE user
38 --
39 CREATE TABLE IF NOT EXISTS `user` (
40         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
41         `parent-uid` mediumint unsigned COMMENT 'The parent user that has full control about this user',
42         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
43         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
44         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
45         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
46         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
47         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
48         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
49         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
50         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
51         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
52         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
53         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
54         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
55         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
56         `pubkey` text COMMENT 'RSA public key 4096 bit',
57         `prvkey` text COMMENT 'RSA private key 4096 bit',
58         `spubkey` text COMMENT '',
59         `sprvkey` text COMMENT '',
60         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
61         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
62         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
63         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
64         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
65         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
66         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
67         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
68         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
69         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
70         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
71         `pwdreset` varchar(255) COMMENT 'Password reset request token',
72         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
73         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
74         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
75         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
76         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
77         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
78         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
79         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
80         `allow_cid` mediumtext COMMENT 'default permission for this user',
81         `allow_gid` mediumtext COMMENT 'default permission for this user',
82         `deny_cid` mediumtext COMMENT 'default permission for this user',
83         `deny_gid` mediumtext COMMENT 'default permission for this user',
84         `openidserver` text COMMENT '',
85          PRIMARY KEY(`uid`),
86          INDEX `nickname` (`nickname`(32)),
87          INDEX `parent-uid` (`parent-uid`),
88         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
89 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
90
91 --
92 -- TABLE contact
93 --
94 CREATE TABLE IF NOT EXISTS `contact` (
95         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
96         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
97         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
98         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
99         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
100         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
101         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
102         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
103         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
104         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
105         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
106         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
107         `location` varchar(255) DEFAULT '' COMMENT '',
108         `about` text COMMENT '',
109         `keywords` text COMMENT 'public keywords (interests) of the contact',
110         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
111         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
112         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
113         `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '',
114         `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
115         `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
116         `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
117         `site-pubkey` text COMMENT '',
118         `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
119         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
120         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
121         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
122         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
123         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
124         `pubkey` text COMMENT 'RSA public key 4096 bit',
125         `prvkey` text COMMENT 'RSA private key 4096 bit',
126         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
127         `request` varchar(255) COMMENT '',
128         `notify` varchar(255) COMMENT '',
129         `poll` varchar(255) COMMENT '',
130         `confirm` varchar(255) COMMENT '',
131         `subscribe` varchar(255) COMMENT '',
132         `poco` varchar(255) COMMENT '',
133         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT '',
134         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT '',
135         `usehub` boolean NOT NULL DEFAULT '0' COMMENT '',
136         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
137         `hub-verify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
138         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
139         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
140         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
141         `failed` boolean COMMENT 'Connection failed',
142         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
143         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
144         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
145         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
146         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
147         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
148         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
149         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
150         `block_reason` text COMMENT 'Node-wide block reason',
151         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
152         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
153         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum',
154         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group',
155         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT '',
156         `manually-approve` boolean COMMENT '',
157         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
158         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
159         `pending` boolean NOT NULL DEFAULT '1' COMMENT '',
160         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
161         `rating` tinyint NOT NULL DEFAULT 0 COMMENT '',
162         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
163         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
164         `baseurl` varchar(255) DEFAULT '' COMMENT 'baseurl of the contact',
165         `gsid` int unsigned COMMENT 'Global Server ID',
166         `reason` text COMMENT '',
167         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT '',
168         `info` mediumtext COMMENT '',
169         `profile-id` int unsigned COMMENT 'Deprecated',
170         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
171         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
172         `notify_new_posts` boolean NOT NULL DEFAULT '0' COMMENT '',
173         `fetch_further_information` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
174         `ffi_keyword_denylist` text COMMENT '',
175          PRIMARY KEY(`id`),
176          INDEX `uid_name` (`uid`,`name`(190)),
177          INDEX `self_uid` (`self`,`uid`),
178          INDEX `alias_uid` (`alias`(128),`uid`),
179          INDEX `pending_uid` (`pending`,`uid`),
180          INDEX `blocked_uid` (`blocked`,`uid`),
181          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
182          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
183          INDEX `addr_uid` (`addr`(128),`uid`),
184          INDEX `nurl_uid` (`nurl`(128),`uid`),
185          INDEX `nick_uid` (`nick`(128),`uid`),
186          INDEX `attag_uid` (`attag`(96),`uid`),
187          INDEX `dfrn-id` (`dfrn-id`(64)),
188          INDEX `issued-id` (`issued-id`(64)),
189          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
190          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
191          INDEX `uid_lastitem` (`uid`,`last-item`),
192          INDEX `gsid` (`gsid`),
193         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
194         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
195 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
196
197 --
198 -- TABLE item-uri
199 --
200 CREATE TABLE IF NOT EXISTS `item-uri` (
201         `id` int unsigned NOT NULL auto_increment,
202         `uri` varbinary(255) NOT NULL COMMENT 'URI of an item',
203         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
204          PRIMARY KEY(`id`),
205          UNIQUE INDEX `uri` (`uri`),
206          INDEX `guid` (`guid`)
207 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
208
209 --
210 -- TABLE tag
211 --
212 CREATE TABLE IF NOT EXISTS `tag` (
213         `id` int unsigned NOT NULL auto_increment COMMENT '',
214         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
215         `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
216          PRIMARY KEY(`id`),
217          UNIQUE INDEX `type_name_url` (`name`,`url`),
218          INDEX `url` (`url`)
219 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
220
221 --
222 -- TABLE clients
223 --
224 CREATE TABLE IF NOT EXISTS `clients` (
225         `client_id` varchar(20) NOT NULL COMMENT '',
226         `pw` varchar(20) NOT NULL DEFAULT '' COMMENT '',
227         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
228         `name` text COMMENT '',
229         `icon` text COMMENT '',
230         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
231          PRIMARY KEY(`client_id`),
232          INDEX `uid` (`uid`),
233         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
234 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
235
236 --
237 -- TABLE permissionset
238 --
239 CREATE TABLE IF NOT EXISTS `permissionset` (
240         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
241         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
242         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
243         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
244         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
245         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
246          PRIMARY KEY(`id`),
247          INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`uid`,`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)),
248         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
249 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
250
251 --
252 -- TABLE verb
253 --
254 CREATE TABLE IF NOT EXISTS `verb` (
255         `id` smallint unsigned NOT NULL auto_increment,
256         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
257          PRIMARY KEY(`id`)
258 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
259
260 --
261 -- TABLE 2fa_app_specific_password
262 --
263 CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
264         `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
265         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
266         `description` varchar(255) COMMENT 'Description of the usage of the password',
267         `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
268         `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
269         `last_used` datetime COMMENT 'Datetime the password was last used',
270          PRIMARY KEY(`id`),
271          INDEX `uid_description` (`uid`,`description`(190)),
272         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
273 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
274
275 --
276 -- TABLE 2fa_recovery_codes
277 --
278 CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` (
279         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
280         `code` varchar(50) NOT NULL COMMENT 'Recovery code string',
281         `generated` datetime NOT NULL COMMENT 'Datetime the code was generated',
282         `used` datetime COMMENT 'Datetime the code was used',
283          PRIMARY KEY(`uid`,`code`),
284         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
285 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes';
286
287 --
288 -- TABLE addon
289 --
290 CREATE TABLE IF NOT EXISTS `addon` (
291         `id` int unsigned NOT NULL auto_increment COMMENT '',
292         `name` varchar(50) NOT NULL DEFAULT '' COMMENT 'addon base (file)name',
293         `version` varchar(50) NOT NULL DEFAULT '' COMMENT 'currently unused',
294         `installed` boolean NOT NULL DEFAULT '0' COMMENT 'currently always 1',
295         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'currently unused',
296         `timestamp` int unsigned NOT NULL DEFAULT 0 COMMENT 'file timestamp to check for reloads',
297         `plugin_admin` boolean NOT NULL DEFAULT '0' COMMENT '1 = has admin config, 0 = has no admin config',
298          PRIMARY KEY(`id`),
299          UNIQUE INDEX `name` (`name`)
300 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registered addons';
301
302 --
303 -- TABLE apcontact
304 --
305 CREATE TABLE IF NOT EXISTS `apcontact` (
306         `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
307         `uuid` varchar(255) COMMENT '',
308         `type` varchar(20) NOT NULL COMMENT '',
309         `following` varchar(255) COMMENT '',
310         `followers` varchar(255) COMMENT '',
311         `inbox` varchar(255) NOT NULL COMMENT '',
312         `outbox` varchar(255) COMMENT '',
313         `sharedinbox` varchar(255) COMMENT '',
314         `manually-approve` boolean COMMENT '',
315         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
316         `name` varchar(255) COMMENT '',
317         `about` text COMMENT '',
318         `photo` varchar(255) COMMENT '',
319         `addr` varchar(255) COMMENT '',
320         `alias` varchar(255) COMMENT '',
321         `pubkey` text COMMENT '',
322         `subscribe` varchar(255) COMMENT '',
323         `baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
324         `gsid` int unsigned COMMENT 'Global Server ID',
325         `generator` varchar(255) COMMENT 'Name of the contact\'s system',
326         `following_count` int unsigned DEFAULT 0 COMMENT 'Number of following contacts',
327         `followers_count` int unsigned DEFAULT 0 COMMENT 'Number of followers',
328         `statuses_count` int unsigned DEFAULT 0 COMMENT 'Number of posts',
329         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
330          PRIMARY KEY(`url`),
331          INDEX `addr` (`addr`(32)),
332          INDEX `alias` (`alias`(190)),
333          INDEX `followers` (`followers`(190)),
334          INDEX `baseurl` (`baseurl`(190)),
335          INDEX `sharedinbox` (`sharedinbox`(190)),
336          INDEX `gsid` (`gsid`),
337         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
338 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
339
340 --
341 -- TABLE attach
342 --
343 CREATE TABLE IF NOT EXISTS `attach` (
344         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
345         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
346         `hash` varchar(64) NOT NULL DEFAULT '' COMMENT 'hash',
347         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'filename of original',
348         `filetype` varchar(64) NOT NULL DEFAULT '' COMMENT 'mimetype',
349         `filesize` int unsigned NOT NULL DEFAULT 0 COMMENT 'size in bytes',
350         `data` longblob NOT NULL COMMENT 'file data',
351         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
352         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
353         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>',
354         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
355         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
356         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
357         `backend-class` tinytext COMMENT 'Storage backend class',
358         `backend-ref` text COMMENT 'Storage backend data reference',
359          PRIMARY KEY(`id`),
360          INDEX `uid` (`uid`),
361         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
362 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='file attachments';
363
364 --
365 -- TABLE auth_codes
366 --
367 CREATE TABLE IF NOT EXISTS `auth_codes` (
368         `id` varchar(40) NOT NULL COMMENT '',
369         `client_id` varchar(20) NOT NULL DEFAULT '' COMMENT '',
370         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
371         `expires` int NOT NULL DEFAULT 0 COMMENT '',
372         `scope` varchar(250) NOT NULL DEFAULT '' COMMENT '',
373          PRIMARY KEY(`id`),
374          INDEX `client_id` (`client_id`),
375         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE
376 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
377
378 --
379 -- TABLE cache
380 --
381 CREATE TABLE IF NOT EXISTS `cache` (
382         `k` varbinary(255) NOT NULL COMMENT 'cache key',
383         `v` mediumtext COMMENT 'cached serialized value',
384         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
385         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
386          PRIMARY KEY(`k`),
387          INDEX `k_expires` (`k`,`expires`)
388 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
389
390 --
391 -- TABLE challenge
392 --
393 CREATE TABLE IF NOT EXISTS `challenge` (
394         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
395         `challenge` varchar(255) NOT NULL DEFAULT '' COMMENT '',
396         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
397         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
398         `type` varchar(255) NOT NULL DEFAULT '' COMMENT '',
399         `last_update` varchar(255) NOT NULL DEFAULT '' COMMENT '',
400          PRIMARY KEY(`id`)
401 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
402
403 --
404 -- TABLE config
405 --
406 CREATE TABLE IF NOT EXISTS `config` (
407         `id` int unsigned NOT NULL auto_increment COMMENT '',
408         `cat` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
409         `k` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
410         `v` mediumtext COMMENT '',
411          PRIMARY KEY(`id`),
412          UNIQUE INDEX `cat_k` (`cat`,`k`)
413 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='main configuration storage';
414
415 --
416 -- TABLE contact-relation
417 --
418 CREATE TABLE IF NOT EXISTS `contact-relation` (
419         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact the related contact had interacted with',
420         `relation-cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'related contact who had interacted with the contact',
421         `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction',
422         `follow-updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last update of the contact relationship',
423         `follows` boolean NOT NULL DEFAULT '0' COMMENT '',
424          PRIMARY KEY(`cid`,`relation-cid`),
425          INDEX `relation-cid` (`relation-cid`),
426         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
427         FOREIGN KEY (`relation-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
428 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Contact relations';
429
430 --
431 -- TABLE conv
432 --
433 CREATE TABLE IF NOT EXISTS `conv` (
434         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
435         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this conversation',
436         `recips` text COMMENT 'sender_handle;recipient_handle',
437         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
438         `creator` varchar(255) NOT NULL DEFAULT '' COMMENT 'handle of creator',
439         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation timestamp',
440         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'edited timestamp',
441         `subject` text COMMENT 'subject of initial message',
442          PRIMARY KEY(`id`),
443          INDEX `uid` (`uid`),
444         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
445 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
446
447 --
448 -- TABLE conversation
449 --
450 CREATE TABLE IF NOT EXISTS `conversation` (
451         `item-uri` varbinary(255) NOT NULL COMMENT 'Original URI of the item - unrelated to the table with the same name',
452         `reply-to-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'URI to which this item is a reply',
453         `conversation-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation URI',
454         `conversation-href` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation link',
455         `protocol` tinyint unsigned NOT NULL DEFAULT 255 COMMENT 'The protocol of the item',
456         `direction` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'How the message arrived here: 1=push, 2=pull',
457         `source` mediumtext COMMENT 'Original source',
458         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Receiving date',
459          PRIMARY KEY(`item-uri`),
460          INDEX `conversation-uri` (`conversation-uri`),
461          INDEX `received` (`received`)
462 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Raw data and structure information for messages';
463
464 --
465 -- TABLE delayed-post
466 --
467 CREATE TABLE IF NOT EXISTS `delayed-post` (
468         `id` int unsigned NOT NULL auto_increment,
469         `uri` varchar(255) COMMENT 'URI of the post that will be posted later',
470         `uid` mediumint unsigned COMMENT 'Owner User id',
471         `delayed` datetime COMMENT 'delay time',
472          PRIMARY KEY(`id`),
473          UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
474         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
475 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be posted at a later time';
476
477 --
478 -- TABLE diaspora-interaction
479 --
480 CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
481         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
482         `interaction` mediumtext COMMENT 'The Diaspora interaction',
483          PRIMARY KEY(`uri-id`),
484         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
485 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
486
487 --
488 -- TABLE event
489 --
490 CREATE TABLE IF NOT EXISTS `event` (
491         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
492         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
493         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
494         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact_id (ID of the contact in contact table)',
495         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
496         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
497         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
498         `start` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event start time',
499         `finish` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event end time',
500         `summary` text COMMENT 'short description or title of the event',
501         `desc` text COMMENT 'event description',
502         `location` text COMMENT 'event location',
503         `type` varchar(20) NOT NULL DEFAULT '' COMMENT 'event or birthday',
504         `nofinish` boolean NOT NULL DEFAULT '0' COMMENT 'if event does have no end this is 1',
505         `adjust` boolean NOT NULL DEFAULT '1' COMMENT 'adjust to timezone of the recipient (0 or 1)',
506         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '0 or 1',
507         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
508         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
509         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
510         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
511          PRIMARY KEY(`id`),
512          INDEX `uid_start` (`uid`,`start`),
513          INDEX `cid` (`cid`),
514         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
515         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
516 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events';
517
518 --
519 -- TABLE fcontact
520 --
521 CREATE TABLE IF NOT EXISTS `fcontact` (
522         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
523         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id',
524         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
525         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
526         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
527         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
528         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
529         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
530         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
531         `notify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
532         `poll` varchar(255) NOT NULL DEFAULT '' COMMENT '',
533         `confirm` varchar(255) NOT NULL DEFAULT '' COMMENT '',
534         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
535         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
536         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
537         `pubkey` text COMMENT '',
538         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
539          PRIMARY KEY(`id`),
540          INDEX `addr` (`addr`(32)),
541          UNIQUE INDEX `url` (`url`(190))
542 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
543
544 --
545 -- TABLE fsuggest
546 --
547 CREATE TABLE IF NOT EXISTS `fsuggest` (
548         `id` int unsigned NOT NULL auto_increment COMMENT '',
549         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
550         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
551         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
552         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
553         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
554         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
555         `note` text COMMENT '',
556         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
557          PRIMARY KEY(`id`),
558          INDEX `cid` (`cid`),
559          INDEX `uid` (`uid`),
560         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
561         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
562 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff';
563
564 --
565 -- TABLE group
566 --
567 CREATE TABLE IF NOT EXISTS `group` (
568         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
569         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
570         `visible` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the member list is not private',
571         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the group has been deleted',
572         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'human readable name of group',
573          PRIMARY KEY(`id`),
574          INDEX `uid` (`uid`),
575         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
576 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, group info';
577
578 --
579 -- TABLE group_member
580 --
581 CREATE TABLE IF NOT EXISTS `group_member` (
582         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
583         `gid` int unsigned NOT NULL DEFAULT 0 COMMENT 'groups.id of the associated group',
584         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id of the member assigned to the associated group',
585          PRIMARY KEY(`id`),
586          INDEX `contactid` (`contact-id`),
587          UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`),
588         FOREIGN KEY (`gid`) REFERENCES `group` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
589         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
590 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, member info';
591
592 --
593 -- TABLE gserver-tag
594 --
595 CREATE TABLE IF NOT EXISTS `gserver-tag` (
596         `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
597         `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
598          PRIMARY KEY(`gserver-id`,`tag`),
599          INDEX `tag` (`tag`),
600         FOREIGN KEY (`gserver-id`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
601 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Tags that the server has subscribed';
602
603 --
604 -- TABLE hook
605 --
606 CREATE TABLE IF NOT EXISTS `hook` (
607         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
608         `hook` varbinary(100) NOT NULL DEFAULT '' COMMENT 'name of hook',
609         `file` varbinary(200) NOT NULL DEFAULT '' COMMENT 'relative filename of hook handler',
610         `function` varbinary(200) NOT NULL DEFAULT '' COMMENT 'function name of hook handler',
611         `priority` smallint unsigned NOT NULL DEFAULT 0 COMMENT 'not yet implemented - can be used to sort conflicts in hook handling by calling handlers in priority order',
612          PRIMARY KEY(`id`),
613          UNIQUE INDEX `hook_file_function` (`hook`,`file`,`function`)
614 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='addon hook registry';
615
616 --
617 -- TABLE host
618 --
619 CREATE TABLE IF NOT EXISTS `host` (
620         `id` tinyint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
621         `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'The hostname',
622          PRIMARY KEY(`id`),
623          UNIQUE INDEX `name` (`name`)
624 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Hostname';
625
626 --
627 -- TABLE inbox-status
628 --
629 CREATE TABLE IF NOT EXISTS `inbox-status` (
630         `url` varbinary(255) NOT NULL COMMENT 'URL of the inbox',
631         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date of this entry',
632         `success` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful delivery',
633         `failure` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed delivery',
634         `previous` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Previous delivery date',
635         `archive` boolean NOT NULL DEFAULT '0' COMMENT 'Is the inbox archived?',
636         `shared` boolean NOT NULL DEFAULT '0' COMMENT 'Is it a shared inbox?',
637          PRIMARY KEY(`url`)
638 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Status of ActivityPub inboxes';
639
640 --
641 -- TABLE intro
642 --
643 CREATE TABLE IF NOT EXISTS `intro` (
644         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
645         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
646         `fid` int unsigned COMMENT '',
647         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
648         `knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
649         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
650         `note` text COMMENT '',
651         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
652         `datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
653         `blocked` boolean NOT NULL DEFAULT '1' COMMENT '',
654         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '',
655          PRIMARY KEY(`id`),
656          INDEX `contact-id` (`contact-id`),
657          INDEX `uid` (`uid`),
658         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
659         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
660 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
661
662 --
663 -- TABLE item
664 --
665 CREATE TABLE IF NOT EXISTS `item` (
666         `id` int unsigned NOT NULL auto_increment,
667         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this item',
668         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
669         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
670         `uri-hash` varchar(80) NOT NULL DEFAULT '' COMMENT 'RIPEMD-128 hash from uri',
671         `parent` int unsigned COMMENT 'item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item',
672         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT 'uri of the top-level parent to this item',
673         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the top-level parent uri',
674         `thr-parent` varchar(255) NOT NULL DEFAULT '' COMMENT 'If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri',
675         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
676         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
677         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
678         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last comment/reply to this item',
679         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
680         `changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date that something in the conversation changed, indicating clients should fetch the conversation again',
681         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
682         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
683         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
684         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
685         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
686         `icid` int unsigned COMMENT 'Id of the item-content table entry that contains the whole item content',
687         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
688         `extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
689         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
690         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
691         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
692         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
693         `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
694         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
695         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
696         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
697         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
698         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
699         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
700         `starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
701         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
702         `mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
703         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
704         `psid` int unsigned COMMENT 'ID of the permission set of this post',
705         `resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type',
706         `event-id` int unsigned COMMENT 'Used to link to the event.id',
707         `iaid` int unsigned COMMENT 'Deprecated',
708         `attach` mediumtext COMMENT 'Deprecated',
709         `allow_cid` mediumtext COMMENT 'Deprecated',
710         `allow_gid` mediumtext COMMENT 'Deprecated',
711         `deny_cid` mediumtext COMMENT 'Deprecated',
712         `deny_gid` mediumtext COMMENT 'Deprecated',
713         `postopts` text COMMENT 'Deprecated',
714         `inform` mediumtext COMMENT 'Deprecated',
715         `type` varchar(20) COMMENT 'Deprecated',
716         `bookmark` boolean COMMENT 'Deprecated',
717         `file` mediumtext COMMENT 'Deprecated',
718         `location` varchar(255) COMMENT 'Deprecated',
719         `coord` varchar(255) COMMENT 'Deprecated',
720         `tag` mediumtext COMMENT 'Deprecated',
721         `plink` varchar(255) COMMENT 'Deprecated',
722         `title` varchar(255) COMMENT 'Deprecated',
723         `content-warning` varchar(255) COMMENT 'Deprecated',
724         `body` mediumtext COMMENT 'Deprecated',
725         `app` varchar(255) COMMENT 'Deprecated',
726         `verb` varchar(100) COMMENT 'Deprecated',
727         `object-type` varchar(100) COMMENT 'Deprecated',
728         `object` text COMMENT 'Deprecated',
729         `target-type` varchar(100) COMMENT 'Deprecated',
730         `target` text COMMENT 'Deprecated',
731         `author-name` varchar(255) COMMENT 'Deprecated',
732         `author-link` varchar(255) COMMENT 'Deprecated',
733         `author-avatar` varchar(255) COMMENT 'Deprecated',
734         `owner-name` varchar(255) COMMENT 'Deprecated',
735         `owner-link` varchar(255) COMMENT 'Deprecated',
736         `owner-avatar` varchar(255) COMMENT 'Deprecated',
737         `rendered-hash` varchar(32) COMMENT 'Deprecated',
738         `rendered-html` mediumtext COMMENT 'Deprecated',
739          PRIMARY KEY(`id`),
740          INDEX `guid` (`guid`(191)),
741          INDEX `uri` (`uri`(191)),
742          INDEX `parent` (`parent`),
743          INDEX `parent-uri` (`parent-uri`(191)),
744          INDEX `extid` (`extid`(191)),
745          INDEX `uid_id` (`uid`,`id`),
746          INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
747          INDEX `uid_received` (`uid`,`received`),
748          INDEX `uid_commented` (`uid`,`commented`),
749          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
750          INDEX `uid_network_received` (`uid`,`network`,`received`),
751          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
752          INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
753          INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
754          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
755          INDEX `authorid_received` (`author-id`,`received`),
756          INDEX `ownerid` (`owner-id`),
757          INDEX `contact-id` (`contact-id`),
758          INDEX `uid_uri` (`uid`,`uri`(190)),
759          INDEX `resource-id` (`resource-id`),
760          INDEX `deleted_changed` (`deleted`,`changed`),
761          INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
762          INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
763          INDEX `mention_uid_id` (`mention`,`uid`,`id`),
764          INDEX `uid_eventid` (`uid`,`event-id`),
765          INDEX `icid` (`icid`),
766          INDEX `iaid` (`iaid`),
767          INDEX `vid` (`vid`),
768          INDEX `psid_wall` (`psid`,`wall`),
769          INDEX `uri-id` (`uri-id`),
770          INDEX `parent-uri-id` (`parent-uri-id`),
771          INDEX `thr-parent-id` (`thr-parent-id`),
772          INDEX `causer-id` (`causer-id`),
773         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
774         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
775         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
776         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
777         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
778         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
779         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
780         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
781         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
782         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
783 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
784
785 --
786 -- TABLE item-activity
787 --
788 CREATE TABLE IF NOT EXISTS `item-activity` (
789         `id` int unsigned NOT NULL auto_increment,
790         `uri` varchar(255) COMMENT '',
791         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
792         `uri-hash` varchar(80) NOT NULL DEFAULT '' COMMENT 'RIPEMD-128 hash from uri',
793         `activity` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
794          PRIMARY KEY(`id`),
795          UNIQUE INDEX `uri-hash` (`uri-hash`),
796          INDEX `uri` (`uri`(191)),
797          INDEX `uri-id` (`uri-id`),
798         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
799 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activities for items';
800
801 --
802 -- TABLE item-content
803 --
804 CREATE TABLE IF NOT EXISTS `item-content` (
805         `id` int unsigned NOT NULL auto_increment,
806         `uri` varchar(255) COMMENT '',
807         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
808         `uri-plink-hash` varchar(80) NOT NULL DEFAULT '' COMMENT 'RIPEMD-128 hash from uri',
809         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
810         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
811         `body` mediumtext COMMENT 'item body content',
812         `raw-body` mediumtext COMMENT 'Body without embedded media links',
813         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
814         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
815         `language` text COMMENT 'Language information about this post',
816         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
817         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
818         `rendered-html` mediumtext COMMENT 'item.body converted to html',
819         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
820         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
821         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
822         `target` text COMMENT 'JSON encoded target structure if used',
823         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
824         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams verb',
825          PRIMARY KEY(`id`),
826          UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`),
827          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
828          INDEX `uri` (`uri`(191)),
829          INDEX `plink` (`plink`(191)),
830          INDEX `uri-id` (`uri-id`),
831         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
832 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
833
834 --
835 -- TABLE locks
836 --
837 CREATE TABLE IF NOT EXISTS `locks` (
838         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
839         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
840         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
841         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
842         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
843          PRIMARY KEY(`id`),
844          INDEX `name_expires` (`name`,`expires`)
845 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
846
847 --
848 -- TABLE mail
849 --
850 CREATE TABLE IF NOT EXISTS `mail` (
851         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
852         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
853         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
854         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
855         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
856         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
857         `contact-id` varchar(255) COMMENT 'contact.id',
858         `convid` int unsigned COMMENT 'conv.id',
859         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
860         `body` mediumtext COMMENT '',
861         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
862         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
863         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
864         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
865         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
866         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
867         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
868          PRIMARY KEY(`id`),
869          INDEX `uid_seen` (`uid`,`seen`),
870          INDEX `convid` (`convid`),
871          INDEX `uri` (`uri`(64)),
872          INDEX `parent-uri` (`parent-uri`(64)),
873          INDEX `contactid` (`contact-id`(32)),
874         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
875 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
876
877 --
878 -- TABLE mailacct
879 --
880 CREATE TABLE IF NOT EXISTS `mailacct` (
881         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
882         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
883         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
884         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
885         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
886         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
887         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
888         `pass` text COMMENT '',
889         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
890         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
891         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
892         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
893         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
894          PRIMARY KEY(`id`),
895          INDEX `uid` (`uid`),
896         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
897 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
898
899 --
900 -- TABLE manage
901 --
902 CREATE TABLE IF NOT EXISTS `manage` (
903         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
904         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
905         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
906          PRIMARY KEY(`id`),
907          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
908          INDEX `mid` (`mid`),
909         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
910         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
911 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
912
913 --
914 -- TABLE notify
915 --
916 CREATE TABLE IF NOT EXISTS `notify` (
917         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
918         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
919         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
920         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
921         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
922         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
923         `msg` mediumtext COMMENT '',
924         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
925         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
926         `iid` int unsigned COMMENT 'item.id',
927         `parent` int unsigned COMMENT '',
928         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
929         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
930         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
931         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
932         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
933         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
934         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
935          PRIMARY KEY(`id`),
936          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
937          INDEX `uid_date` (`uid`,`date`),
938          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
939          INDEX `uri-id` (`uri-id`),
940          INDEX `parent-uri-id` (`parent-uri-id`),
941         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
942         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
943         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
944 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
945
946 --
947 -- TABLE notify-threads
948 --
949 CREATE TABLE IF NOT EXISTS `notify-threads` (
950         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
951         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
952         `master-parent-item` int unsigned COMMENT '',
953         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
954         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
955         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
956          PRIMARY KEY(`id`),
957          INDEX `master-parent-item` (`master-parent-item`),
958          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
959          INDEX `receiver-uid` (`receiver-uid`),
960          INDEX `notify-id` (`notify-id`),
961         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
962         FOREIGN KEY (`master-parent-item`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
963         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
964         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
965 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
966
967 --
968 -- TABLE oembed
969 --
970 CREATE TABLE IF NOT EXISTS `oembed` (
971         `url` varbinary(255) NOT NULL COMMENT 'page url',
972         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
973         `content` mediumtext COMMENT 'OEmbed data of the page',
974         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
975          PRIMARY KEY(`url`,`maxwidth`),
976          INDEX `created` (`created`)
977 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
978
979 --
980 -- TABLE openwebauth-token
981 --
982 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
983         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
984         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
985         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
986         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
987         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
988         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
989          PRIMARY KEY(`id`),
990          INDEX `uid` (`uid`),
991         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
992 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
993
994 --
995 -- TABLE parsed_url
996 --
997 CREATE TABLE IF NOT EXISTS `parsed_url` (
998         `url` varbinary(255) NOT NULL COMMENT 'page url',
999         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
1000         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
1001         `content` mediumtext COMMENT 'page data',
1002         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
1003          PRIMARY KEY(`url`,`guessing`,`oembed`),
1004          INDEX `created` (`created`)
1005 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
1006
1007 --
1008 -- TABLE participation
1009 --
1010 CREATE TABLE IF NOT EXISTS `participation` (
1011         `iid` int unsigned NOT NULL COMMENT '',
1012         `server` varchar(60) NOT NULL COMMENT '',
1013         `cid` int unsigned NOT NULL COMMENT '',
1014         `fid` int unsigned NOT NULL COMMENT '',
1015          PRIMARY KEY(`iid`,`server`),
1016          INDEX `cid` (`cid`),
1017          INDEX `fid` (`fid`),
1018         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1019         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1020         FOREIGN KEY (`fid`) REFERENCES `fcontact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1021 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Storage for participation messages from Diaspora';
1022
1023 --
1024 -- TABLE pconfig
1025 --
1026 CREATE TABLE IF NOT EXISTS `pconfig` (
1027         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
1028         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1029         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
1030         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
1031         `v` mediumtext COMMENT 'Value',
1032          PRIMARY KEY(`id`),
1033          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
1034         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1035 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
1036
1037 --
1038 -- TABLE photo
1039 --
1040 CREATE TABLE IF NOT EXISTS `photo` (
1041         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1042         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1043         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1044         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
1045         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
1046         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
1047         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
1048         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1049         `desc` text COMMENT '',
1050         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
1051         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1052         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
1053         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1054         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1055         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1056         `data` mediumblob NOT NULL COMMENT '',
1057         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1058         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
1059         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
1060         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
1061         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
1062         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
1063         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
1064         `backend-class` tinytext COMMENT 'Storage backend class',
1065         `backend-ref` text COMMENT 'Storage backend data reference',
1066         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1067          PRIMARY KEY(`id`),
1068          INDEX `contactid` (`contact-id`),
1069          INDEX `uid_contactid` (`uid`,`contact-id`),
1070          INDEX `uid_profile` (`uid`,`profile`),
1071          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
1072          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
1073          INDEX `resource-id` (`resource-id`),
1074         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1075         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1076 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1077
1078 --
1079 -- TABLE post-category
1080 --
1081 CREATE TABLE IF NOT EXISTS `post-category` (
1082         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1083         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1084         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1085         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1086          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1087          INDEX `uri-id` (`tid`),
1088          INDEX `uid` (`uid`),
1089         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1090         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1091         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1092 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1093
1094 --
1095 -- TABLE post-delivery-data
1096 --
1097 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1098         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1099         `postopts` text COMMENT 'External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery',
1100         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1101         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1102         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1103         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1104         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1105         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1106         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1107         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1108         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1109          PRIMARY KEY(`uri-id`),
1110         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1111 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1112
1113 --
1114 -- TABLE post-media
1115 --
1116 CREATE TABLE IF NOT EXISTS `post-media` (
1117         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1118         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1119         `url` varbinary(511) NOT NULL COMMENT 'Media URL',
1120         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1121         `mimetype` varchar(60) COMMENT '',
1122         `height` smallint unsigned COMMENT 'Height of the media',
1123         `width` smallint unsigned COMMENT 'Width of the media',
1124         `size` int unsigned COMMENT 'Media size',
1125         `preview` varbinary(255) COMMENT 'Preview URL',
1126         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1127         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1128         `description` text COMMENT '',
1129          PRIMARY KEY(`id`),
1130          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1131         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1132 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1133
1134 --
1135 -- TABLE post-tag
1136 --
1137 CREATE TABLE IF NOT EXISTS `post-tag` (
1138         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1139         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1140         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1141         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1142          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1143          INDEX `tid` (`tid`),
1144          INDEX `cid` (`cid`),
1145         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1146         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1147         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1148 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1149
1150 --
1151 -- TABLE post-user
1152 --
1153 CREATE TABLE IF NOT EXISTS `post-user` (
1154         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1155         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1156         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1157         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1158         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1159         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1160         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1161         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1162         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1163          PRIMARY KEY(`uid`,`uri-id`),
1164          INDEX `uri-id` (`uri-id`),
1165          INDEX `contact-id` (`contact-id`),
1166          INDEX `psid` (`psid`),
1167         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1168         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1169         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1170         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1171 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1172
1173 --
1174 -- TABLE process
1175 --
1176 CREATE TABLE IF NOT EXISTS `process` (
1177         `pid` int unsigned NOT NULL COMMENT '',
1178         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1179         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1180          PRIMARY KEY(`pid`),
1181          INDEX `command` (`command`)
1182 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1183
1184 --
1185 -- TABLE profile
1186 --
1187 CREATE TABLE IF NOT EXISTS `profile` (
1188         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1189         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1190         `profile-name` varchar(255) COMMENT 'Deprecated',
1191         `is-default` boolean COMMENT 'Deprecated',
1192         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1193         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1194         `pdesc` varchar(255) COMMENT 'Deprecated',
1195         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1196         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1197         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1198         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1199         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1200         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1201         `hometown` varchar(255) COMMENT 'Deprecated',
1202         `gender` varchar(32) COMMENT 'Deprecated',
1203         `marital` varchar(255) COMMENT 'Deprecated',
1204         `with` text COMMENT 'Deprecated',
1205         `howlong` datetime COMMENT 'Deprecated',
1206         `sexual` varchar(255) COMMENT 'Deprecated',
1207         `politic` varchar(255) COMMENT 'Deprecated',
1208         `religion` varchar(255) COMMENT 'Deprecated',
1209         `pub_keywords` text COMMENT '',
1210         `prv_keywords` text COMMENT '',
1211         `likes` text COMMENT 'Deprecated',
1212         `dislikes` text COMMENT 'Deprecated',
1213         `about` text COMMENT 'Profile description',
1214         `summary` varchar(255) COMMENT 'Deprecated',
1215         `music` text COMMENT 'Deprecated',
1216         `book` text COMMENT 'Deprecated',
1217         `tv` text COMMENT 'Deprecated',
1218         `film` text COMMENT 'Deprecated',
1219         `interest` text COMMENT 'Deprecated',
1220         `romance` text COMMENT 'Deprecated',
1221         `work` text COMMENT 'Deprecated',
1222         `education` text COMMENT 'Deprecated',
1223         `contact` text COMMENT 'Deprecated',
1224         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1225         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1226         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1227         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1228         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1229         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1230          PRIMARY KEY(`id`),
1231          INDEX `uid_is-default` (`uid`,`is-default`),
1232          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1233         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1234 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1235
1236 --
1237 -- TABLE profile_check
1238 --
1239 CREATE TABLE IF NOT EXISTS `profile_check` (
1240         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1241         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1242         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1243         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1244         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1245         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1246          PRIMARY KEY(`id`),
1247          INDEX `uid` (`uid`),
1248          INDEX `cid` (`cid`),
1249         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1250         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1251 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1252
1253 --
1254 -- TABLE profile_field
1255 --
1256 CREATE TABLE IF NOT EXISTS `profile_field` (
1257         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1258         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1259         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1260         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1261         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1262         `value` text COMMENT 'Value of the field',
1263         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1264         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1265          PRIMARY KEY(`id`),
1266          INDEX `uid` (`uid`),
1267          INDEX `order` (`order`),
1268          INDEX `psid` (`psid`),
1269         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1270         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1271 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1272
1273 --
1274 -- TABLE push_subscriber
1275 --
1276 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1277         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1278         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1279         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1280         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1281         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1282         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1283         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1284         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1285         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1286         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1287          PRIMARY KEY(`id`),
1288          INDEX `next_try` (`next_try`),
1289          INDEX `uid` (`uid`),
1290         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1291 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1292
1293 --
1294 -- TABLE register
1295 --
1296 CREATE TABLE IF NOT EXISTS `register` (
1297         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1298         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1299         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1300         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1301         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1302         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1303         `note` text COMMENT '',
1304          PRIMARY KEY(`id`),
1305          INDEX `uid` (`uid`),
1306         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1307 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1308
1309 --
1310 -- TABLE search
1311 --
1312 CREATE TABLE IF NOT EXISTS `search` (
1313         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1314         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1315         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1316          PRIMARY KEY(`id`),
1317          INDEX `uid` (`uid`),
1318         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1319 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1320
1321 --
1322 -- TABLE session
1323 --
1324 CREATE TABLE IF NOT EXISTS `session` (
1325         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1326         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1327         `data` text COMMENT '',
1328         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1329          PRIMARY KEY(`id`),
1330          INDEX `sid` (`sid`(64)),
1331          INDEX `expire` (`expire`)
1332 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1333
1334 --
1335 -- TABLE storage
1336 --
1337 CREATE TABLE IF NOT EXISTS `storage` (
1338         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1339         `data` longblob NOT NULL COMMENT 'file data',
1340          PRIMARY KEY(`id`)
1341 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1342
1343 --
1344 -- TABLE thread
1345 --
1346 CREATE TABLE IF NOT EXISTS `thread` (
1347         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID',
1348         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
1349         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1350         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1351         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1352         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1353         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1354         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1355         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1356         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1357         `changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1358         `wall` boolean NOT NULL DEFAULT '0' COMMENT '',
1359         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1360         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1361         `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
1362         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1363         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1364         `ignored` boolean NOT NULL DEFAULT '0' COMMENT '',
1365         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
1366         `unseen` boolean NOT NULL DEFAULT '1' COMMENT '',
1367         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '',
1368         `origin` boolean NOT NULL DEFAULT '0' COMMENT '',
1369         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1370         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1371         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1372         `bookmark` boolean COMMENT '',
1373          PRIMARY KEY(`iid`),
1374          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
1375          INDEX `uid_network_received` (`uid`,`network`,`received`),
1376          INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
1377          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
1378          INDEX `contactid` (`contact-id`),
1379          INDEX `ownerid` (`owner-id`),
1380          INDEX `authorid` (`author-id`),
1381          INDEX `uid_received` (`uid`,`received`),
1382          INDEX `uid_commented` (`uid`,`commented`),
1383          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1384          INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`),
1385          INDEX `uri-id` (`uri-id`),
1386         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1387         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1388         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1389         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1390         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1391         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1392 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1393
1394 --
1395 -- TABLE tokens
1396 --
1397 CREATE TABLE IF NOT EXISTS `tokens` (
1398         `id` varchar(40) NOT NULL COMMENT '',
1399         `secret` text COMMENT '',
1400         `client_id` varchar(20) NOT NULL DEFAULT '',
1401         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1402         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1403         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1404          PRIMARY KEY(`id`),
1405          INDEX `client_id` (`client_id`),
1406          INDEX `uid` (`uid`),
1407         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1408         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1409 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1410
1411 --
1412 -- TABLE userd
1413 --
1414 CREATE TABLE IF NOT EXISTS `userd` (
1415         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1416         `username` varchar(255) NOT NULL COMMENT '',
1417          PRIMARY KEY(`id`),
1418          INDEX `username` (`username`(32))
1419 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1420
1421 --
1422 -- TABLE user-contact
1423 --
1424 CREATE TABLE IF NOT EXISTS `user-contact` (
1425         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1426         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1427         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1428         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1429         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1430          PRIMARY KEY(`uid`,`cid`),
1431          INDEX `cid` (`cid`),
1432         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1433         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1434 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1435
1436 --
1437 -- TABLE user-item
1438 --
1439 CREATE TABLE IF NOT EXISTS `user-item` (
1440         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item id',
1441         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1442         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
1443         `ignored` boolean COMMENT 'Ignore this thread if set',
1444         `pinned` boolean COMMENT 'The item is pinned on the profile page',
1445         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1446          PRIMARY KEY(`uid`,`iid`),
1447          INDEX `uid_pinned` (`uid`,`pinned`),
1448          INDEX `iid_uid` (`iid`,`uid`),
1449         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1450         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1451 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
1452
1453 --
1454 -- TABLE worker-ipc
1455 --
1456 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1457         `key` int NOT NULL COMMENT '',
1458         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1459          PRIMARY KEY(`key`)
1460 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1461
1462 --
1463 -- TABLE workerqueue
1464 --
1465 CREATE TABLE IF NOT EXISTS `workerqueue` (
1466         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1467         `parameter` mediumtext COMMENT 'Task command',
1468         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1469         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1470         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1471         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1472         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1473         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1474         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1475          PRIMARY KEY(`id`),
1476          INDEX `done_parameter` (`done`,`parameter`(64)),
1477          INDEX `done_executed` (`done`,`executed`),
1478          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
1479          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1480          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1481          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1482          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1483 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1484
1485 --
1486 -- VIEW category-view
1487 --
1488 DROP VIEW `category-view`;
1489 CREATE VIEW `category-view` AS SELECT 
1490         `post-category`.`uri-id` AS `uri-id`,
1491         `post-category`.`uid` AS `uid`,
1492         `item-uri`.`uri` AS `uri`,
1493         `item-uri`.`guid` AS `guid`,
1494         `post-category`.`type` AS `type`,
1495         `post-category`.`tid` AS `tid`,
1496         `tag`.`name` AS `name`,
1497         `tag`.`url` AS `url`
1498         FROM `post-category`
1499                         INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id`
1500                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
1501
1502 --
1503 -- VIEW tag-view
1504 --
1505 DROP VIEW `tag-view`;
1506 CREATE VIEW `tag-view` AS SELECT 
1507         `post-tag`.`uri-id` AS `uri-id`,
1508         `item-uri`.`uri` AS `uri`,
1509         `item-uri`.`guid` AS `guid`,
1510         `post-tag`.`type` AS `type`,
1511         `post-tag`.`tid` AS `tid`,
1512         `post-tag`.`cid` AS `cid`,
1513         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
1514         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
1515         FROM `post-tag`
1516                         INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
1517                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
1518                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
1519
1520 --
1521 -- VIEW network-item-view
1522 --
1523 DROP VIEW `network-item-view`;
1524 CREATE VIEW `network-item-view` AS SELECT 
1525         `item`.`parent-uri-id` AS `uri-id`,
1526         `item`.`parent-uri` AS `uri`,
1527         `item`.`parent` AS `parent`,
1528         `item`.`received` AS `received`,
1529         `item`.`commented` AS `commented`,
1530         `item`.`created` AS `created`,
1531         `item`.`uid` AS `uid`,
1532         `item`.`starred` AS `starred`,
1533         `item`.`mention` AS `mention`,
1534         `item`.`network` AS `network`,
1535         `item`.`unseen` AS `unseen`,
1536         `item`.`gravity` AS `gravity`,
1537         `item`.`contact-id` AS `contact-id`,
1538         `ownercontact`.`contact-type` AS `contact-type`
1539         FROM `item`
1540                         INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
1541                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
1542                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1543                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1544                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1545                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
1546                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1547                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1548                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1549                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1550                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1551
1552 --
1553 -- VIEW network-thread-view
1554 --
1555 DROP VIEW `network-thread-view`;
1556 CREATE VIEW `network-thread-view` AS SELECT 
1557         `item`.`uri-id` AS `uri-id`,
1558         `item`.`uri` AS `uri`,
1559         `item`.`parent-uri-id` AS `parent-uri-id`,
1560         `thread`.`iid` AS `parent`,
1561         `thread`.`received` AS `received`,
1562         `thread`.`commented` AS `commented`,
1563         `thread`.`created` AS `created`,
1564         `thread`.`uid` AS `uid`,
1565         `thread`.`starred` AS `starred`,
1566         `thread`.`mention` AS `mention`,
1567         `thread`.`network` AS `network`,
1568         `thread`.`contact-id` AS `contact-id`,
1569         `ownercontact`.`contact-type` AS `contact-type`
1570         FROM `thread`
1571                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
1572                         STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
1573                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1574                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1575                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1576                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
1577                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1578                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1579                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1580                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1581                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1582
1583 --
1584 -- VIEW owner-view
1585 --
1586 DROP VIEW `owner-view`;
1587 CREATE VIEW `owner-view` AS SELECT 
1588         `contact`.`id` AS `id`,
1589         `contact`.`uid` AS `uid`,
1590         `contact`.`created` AS `created`,
1591         `contact`.`updated` AS `updated`,
1592         `contact`.`self` AS `self`,
1593         `contact`.`remote_self` AS `remote_self`,
1594         `contact`.`rel` AS `rel`,
1595         `contact`.`duplex` AS `duplex`,
1596         `contact`.`network` AS `network`,
1597         `contact`.`protocol` AS `protocol`,
1598         `contact`.`name` AS `name`,
1599         `contact`.`nick` AS `nick`,
1600         `contact`.`location` AS `location`,
1601         `contact`.`about` AS `about`,
1602         `contact`.`keywords` AS `keywords`,
1603         `contact`.`gender` AS `gender`,
1604         `contact`.`xmpp` AS `xmpp`,
1605         `contact`.`attag` AS `attag`,
1606         `contact`.`avatar` AS `avatar`,
1607         `contact`.`photo` AS `photo`,
1608         `contact`.`thumb` AS `thumb`,
1609         `contact`.`micro` AS `micro`,
1610         `contact`.`site-pubkey` AS `site-pubkey`,
1611         `contact`.`issued-id` AS `issued-id`,
1612         `contact`.`dfrn-id` AS `dfrn-id`,
1613         `contact`.`url` AS `url`,
1614         `contact`.`nurl` AS `nurl`,
1615         `contact`.`addr` AS `addr`,
1616         `contact`.`alias` AS `alias`,
1617         `contact`.`pubkey` AS `pubkey`,
1618         `contact`.`prvkey` AS `prvkey`,
1619         `contact`.`batch` AS `batch`,
1620         `contact`.`request` AS `request`,
1621         `contact`.`notify` AS `notify`,
1622         `contact`.`poll` AS `poll`,
1623         `contact`.`confirm` AS `confirm`,
1624         `contact`.`poco` AS `poco`,
1625         `contact`.`aes_allow` AS `aes_allow`,
1626         `contact`.`ret-aes` AS `ret-aes`,
1627         `contact`.`usehub` AS `usehub`,
1628         `contact`.`subhub` AS `subhub`,
1629         `contact`.`hub-verify` AS `hub-verify`,
1630         `contact`.`last-update` AS `last-update`,
1631         `contact`.`success_update` AS `success_update`,
1632         `contact`.`failure_update` AS `failure_update`,
1633         `contact`.`name-date` AS `name-date`,
1634         `contact`.`uri-date` AS `uri-date`,
1635         `contact`.`avatar-date` AS `avatar-date`,
1636         `contact`.`avatar-date` AS `picdate`,
1637         `contact`.`term-date` AS `term-date`,
1638         `contact`.`last-item` AS `last-item`,
1639         `contact`.`priority` AS `priority`,
1640         `user`.`blocked` AS `blocked`,
1641         `contact`.`block_reason` AS `block_reason`,
1642         `contact`.`readonly` AS `readonly`,
1643         `contact`.`writable` AS `writable`,
1644         `contact`.`forum` AS `forum`,
1645         `contact`.`prv` AS `prv`,
1646         `contact`.`contact-type` AS `contact-type`,
1647         `contact`.`manually-approve` AS `manually-approve`,
1648         `contact`.`hidden` AS `hidden`,
1649         `contact`.`archive` AS `archive`,
1650         `contact`.`pending` AS `pending`,
1651         `contact`.`deleted` AS `deleted`,
1652         `contact`.`unsearchable` AS `unsearchable`,
1653         `contact`.`sensitive` AS `sensitive`,
1654         `contact`.`baseurl` AS `baseurl`,
1655         `contact`.`reason` AS `reason`,
1656         `contact`.`closeness` AS `closeness`,
1657         `contact`.`info` AS `info`,
1658         `contact`.`profile-id` AS `profile-id`,
1659         `contact`.`bdyear` AS `bdyear`,
1660         `contact`.`bd` AS `bd`,
1661         `contact`.`notify_new_posts` AS `notify_new_posts`,
1662         `contact`.`fetch_further_information` AS `fetch_further_information`,
1663         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
1664         `user`.`parent-uid` AS `parent-uid`,
1665         `user`.`guid` AS `guid`,
1666         `user`.`nickname` AS `nickname`,
1667         `user`.`email` AS `email`,
1668         `user`.`openid` AS `openid`,
1669         `user`.`timezone` AS `timezone`,
1670         `user`.`language` AS `language`,
1671         `user`.`register_date` AS `register_date`,
1672         `user`.`login_date` AS `login_date`,
1673         `user`.`default-location` AS `default-location`,
1674         `user`.`allow_location` AS `allow_location`,
1675         `user`.`theme` AS `theme`,
1676         `user`.`pubkey` AS `upubkey`,
1677         `user`.`prvkey` AS `uprvkey`,
1678         `user`.`sprvkey` AS `sprvkey`,
1679         `user`.`spubkey` AS `spubkey`,
1680         `user`.`verified` AS `verified`,
1681         `user`.`blockwall` AS `blockwall`,
1682         `user`.`hidewall` AS `hidewall`,
1683         `user`.`blocktags` AS `blocktags`,
1684         `user`.`unkmail` AS `unkmail`,
1685         `user`.`cntunkmail` AS `cntunkmail`,
1686         `user`.`notify-flags` AS `notify-flags`,
1687         `user`.`page-flags` AS `page-flags`,
1688         `user`.`account-type` AS `account-type`,
1689         `user`.`prvnets` AS `prvnets`,
1690         `user`.`maxreq` AS `maxreq`,
1691         `user`.`expire` AS `expire`,
1692         `user`.`account_removed` AS `account_removed`,
1693         `user`.`account_expired` AS `account_expired`,
1694         `user`.`account_expires_on` AS `account_expires_on`,
1695         `user`.`expire_notification_sent` AS `expire_notification_sent`,
1696         `user`.`def_gid` AS `def_gid`,
1697         `user`.`allow_cid` AS `allow_cid`,
1698         `user`.`allow_gid` AS `allow_gid`,
1699         `user`.`deny_cid` AS `deny_cid`,
1700         `user`.`deny_gid` AS `deny_gid`,
1701         `user`.`openidserver` AS `openidserver`,
1702         `profile`.`publish` AS `publish`,
1703         `profile`.`net-publish` AS `net-publish`,
1704         `profile`.`hide-friends` AS `hide-friends`,
1705         `profile`.`prv_keywords` AS `prv_keywords`,
1706         `profile`.`pub_keywords` AS `pub_keywords`,
1707         `profile`.`address` AS `address`,
1708         `profile`.`locality` AS `locality`,
1709         `profile`.`region` AS `region`,
1710         `profile`.`postal-code` AS `postal-code`,
1711         `profile`.`country-name` AS `country-name`,
1712         `profile`.`homepage` AS `homepage`,
1713         `profile`.`dob` AS `dob`
1714         FROM `user`
1715                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
1716                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
1717
1718 --
1719 -- VIEW pending-view
1720 --
1721 DROP VIEW `pending-view`;
1722 CREATE VIEW `pending-view` AS SELECT 
1723         `register`.`id` AS `id`,
1724         `register`.`hash` AS `hash`,
1725         `register`.`created` AS `created`,
1726         `register`.`uid` AS `uid`,
1727         `register`.`password` AS `password`,
1728         `register`.`language` AS `language`,
1729         `register`.`note` AS `note`,
1730         `contact`.`self` AS `self`,
1731         `contact`.`name` AS `name`,
1732         `contact`.`url` AS `url`,
1733         `contact`.`micro` AS `micro`,
1734         `user`.`email` AS `email`,
1735         `contact`.`nick` AS `nick`
1736         FROM `register`
1737                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
1738                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
1739
1740 --
1741 -- VIEW tag-search-view
1742 --
1743 DROP VIEW `tag-search-view`;
1744 CREATE VIEW `tag-search-view` AS SELECT 
1745         `post-tag`.`uri-id` AS `uri-id`,
1746         `item`.`id` AS `iid`,
1747         `item`.`uri` AS `uri`,
1748         `item`.`guid` AS `guid`,
1749         `item`.`uid` AS `uid`,
1750         `item`.`private` AS `private`,
1751         `item`.`wall` AS `wall`,
1752         `item`.`origin` AS `origin`,
1753         `item`.`gravity` AS `gravity`,
1754         `item`.`received` AS `received`,
1755         `tag`.`name` AS `name`
1756         FROM `post-tag`
1757                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
1758                         INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
1759                         WHERE `post-tag`.`type` = 1;
1760
1761 --
1762 -- VIEW workerqueue-view
1763 --
1764 DROP VIEW `workerqueue-view`;
1765 CREATE VIEW `workerqueue-view` AS SELECT 
1766         `process`.`pid` AS `pid`,
1767         `workerqueue`.`priority` AS `priority`
1768         FROM `process`
1769                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
1770                         WHERE NOT `workerqueue`.`done`;
1771
1772