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