]> git.mxchange.org Git - friendica.git/blob - database.sql
Reset the recursion depth at a different place
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2022.09-dev (Giant Rhubarb)
3 -- DB_UPDATE_VERSION 1474
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         `active-week-users` int unsigned COMMENT 'Number of active users in the last week',
20         `active-month-users` int unsigned COMMENT 'Number of active users in the last month',
21         `active-halfyear-users` int unsigned COMMENT 'Number of active users in the last six month',
22         `local-posts` int unsigned COMMENT 'Number of local posts',
23         `local-comments` int unsigned COMMENT 'Number of local comments',
24         `directory-type` tinyint DEFAULT 0 COMMENT 'Type of directory service (Poco, Mastodon)',
25         `poco` varchar(255) NOT NULL DEFAULT '' COMMENT '',
26         `noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
27         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
28         `protocol` tinyint unsigned COMMENT 'The protocol of the server',
29         `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
30         `relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
31         `relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
32         `detection-method` tinyint unsigned COMMENT 'Method that had been used to detect that server',
33         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
34         `last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
35         `last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last successful connection request',
36         `last_failure` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last failed connection request',
37         `failed` boolean COMMENT 'Connection failed',
38         `next_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Next connection request',
39          PRIMARY KEY(`id`),
40          UNIQUE INDEX `nurl` (`nurl`(190)),
41          INDEX `next_contact` (`next_contact`),
42          INDEX `network` (`network`)
43 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers';
44
45 --
46 -- TABLE user
47 --
48 CREATE TABLE IF NOT EXISTS `user` (
49         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
50         `parent-uid` mediumint unsigned COMMENT 'The parent user that has full control about this user',
51         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
52         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
53         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
54         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
55         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
56         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
57         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
58         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
59         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
60         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
61         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
62         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
63         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
64         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
65         `pubkey` text COMMENT 'RSA public key 4096 bit',
66         `prvkey` text COMMENT 'RSA private key 4096 bit',
67         `spubkey` text COMMENT '',
68         `sprvkey` text COMMENT '',
69         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
70         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
71         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
72         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
73         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
74         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
75         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
76         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
77         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
78         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
79         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
80         `pwdreset` varchar(255) COMMENT 'Password reset request token',
81         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
82         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
83         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
84         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
85         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
86         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
87         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
88         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
89         `allow_cid` mediumtext COMMENT 'default permission for this user',
90         `allow_gid` mediumtext COMMENT 'default permission for this user',
91         `deny_cid` mediumtext COMMENT 'default permission for this user',
92         `deny_gid` mediumtext COMMENT 'default permission for this user',
93         `openidserver` text COMMENT '',
94          PRIMARY KEY(`uid`),
95          INDEX `nickname` (`nickname`(32)),
96          INDEX `parent-uid` (`parent-uid`),
97          INDEX `guid` (`guid`),
98          INDEX `email` (`email`(64)),
99         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
100 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
101
102 --
103 -- TABLE item-uri
104 --
105 CREATE TABLE IF NOT EXISTS `item-uri` (
106         `id` int unsigned NOT NULL auto_increment,
107         `uri` varbinary(255) NOT NULL COMMENT 'URI of an item',
108         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
109          PRIMARY KEY(`id`),
110          UNIQUE INDEX `uri` (`uri`),
111          INDEX `guid` (`guid`)
112 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
113
114 --
115 -- TABLE contact
116 --
117 CREATE TABLE IF NOT EXISTS `contact` (
118         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
119         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
120         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
121         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
122         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
123         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
124         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
125         `location` varchar(255) DEFAULT '' COMMENT '',
126         `about` text COMMENT '',
127         `keywords` text COMMENT 'public keywords (interests) of the contact',
128         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
129         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
130         `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '',
131         `header` varchar(255) COMMENT 'Header picture',
132         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
133         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
134         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
135         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
136         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
137         `pubkey` text COMMENT 'RSA public key 4096 bit',
138         `prvkey` text COMMENT 'RSA private key 4096 bit',
139         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
140         `notify` varchar(255) COMMENT '',
141         `poll` varchar(255) COMMENT '',
142         `subscribe` varchar(255) COMMENT '',
143         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
144         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
145         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
146         `failed` boolean COMMENT 'Connection failed',
147         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
148         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
149         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
150         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
151         `block_reason` text COMMENT 'Node-wide block reason',
152         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
153         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay',
154         `manually-approve` boolean COMMENT 'Contact requests have to be approved manually',
155         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
156         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
157         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
158         `baseurl` varchar(255) DEFAULT '' COMMENT 'baseurl of the contact',
159         `gsid` int unsigned COMMENT 'Global Server ID',
160         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
161         `reason` text COMMENT '',
162         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
163         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
164         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
165         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
166         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
167         `hub-verify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
168         `rating` tinyint NOT NULL DEFAULT 0 COMMENT 'Automatically detected feed poll frequency',
169         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Feed poll priority',
170         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
171         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
172         `pending` boolean NOT NULL DEFAULT '1' COMMENT 'Contact request is pending',
173         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
174         `info` mediumtext 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         `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
179         `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
180         `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
181         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
182         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
183         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
184         `request` varchar(255) COMMENT '',
185         `confirm` varchar(255) COMMENT '',
186         `poco` varchar(255) COMMENT '',
187         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
188         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum. Deprecated, use \'contact-type\' = \'community\' and \'manually-approve\' = false instead',
189         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group. Deprecated, use \'contact-type\' = \'community\' and \'manually-approve\' = true instead',
190         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
191         `site-pubkey` text COMMENT 'Deprecated',
192         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
193         `duplex` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
194         `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT 'Deprecated',
195         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT 'Deprecated',
196         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
197         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
198         `usehub` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
199         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT 'Deprecated',
200         `profile-id` int unsigned COMMENT 'Deprecated',
201          PRIMARY KEY(`id`),
202          INDEX `uid_name` (`uid`,`name`(190)),
203          INDEX `self_uid` (`self`,`uid`),
204          INDEX `alias_uid` (`alias`(128),`uid`),
205          INDEX `pending_uid` (`pending`,`uid`),
206          INDEX `blocked_uid` (`blocked`,`uid`),
207          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
208          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
209          INDEX `batch_contact-type` (`batch`(64),`contact-type`),
210          INDEX `addr_uid` (`addr`(128),`uid`),
211          INDEX `nurl_uid` (`nurl`(128),`uid`),
212          INDEX `nick_uid` (`nick`(128),`uid`),
213          INDEX `attag_uid` (`attag`(96),`uid`),
214          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
215          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
216          INDEX `uid_lastitem` (`uid`,`last-item`),
217          INDEX `baseurl` (`baseurl`(64)),
218          INDEX `uid_contact-type` (`uid`,`contact-type`),
219          INDEX `uid_self_contact-type` (`uid`,`self`,`contact-type`),
220          INDEX `self_network_uid` (`self`,`network`,`uid`),
221          INDEX `gsid` (`gsid`),
222          INDEX `uri-id` (`uri-id`),
223         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
224         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
225         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
226 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
227
228 --
229 -- TABLE tag
230 --
231 CREATE TABLE IF NOT EXISTS `tag` (
232         `id` int unsigned NOT NULL auto_increment COMMENT '',
233         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
234         `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
235         `type` tinyint unsigned COMMENT 'Type of the tag (Unknown, General Collection, Follower Collection or Account)',
236          PRIMARY KEY(`id`),
237          UNIQUE INDEX `type_name_url` (`name`,`url`),
238          INDEX `url` (`url`)
239 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
240
241 --
242 -- TABLE permissionset
243 --
244 CREATE TABLE IF NOT EXISTS `permissionset` (
245         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
246         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
247         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
248         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
249         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
250         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
251          PRIMARY KEY(`id`),
252          INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`uid`,`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)),
253         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
254 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
255
256 --
257 -- TABLE verb
258 --
259 CREATE TABLE IF NOT EXISTS `verb` (
260         `id` smallint unsigned NOT NULL auto_increment,
261         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
262          PRIMARY KEY(`id`),
263          INDEX `name` (`name`)
264 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
265
266 --
267 -- TABLE 2fa_app_specific_password
268 --
269 CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
270         `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
271         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
272         `description` varchar(255) COMMENT 'Description of the usage of the password',
273         `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
274         `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
275         `last_used` datetime COMMENT 'Datetime the password was last used',
276          PRIMARY KEY(`id`),
277          INDEX `uid_description` (`uid`,`description`(190)),
278         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
279 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
280
281 --
282 -- TABLE 2fa_recovery_codes
283 --
284 CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` (
285         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
286         `code` varchar(50) NOT NULL COMMENT 'Recovery code string',
287         `generated` datetime NOT NULL COMMENT 'Datetime the code was generated',
288         `used` datetime COMMENT 'Datetime the code was used',
289          PRIMARY KEY(`uid`,`code`),
290         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
291 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes';
292
293 --
294 -- TABLE 2fa_trusted_browser
295 --
296 CREATE TABLE IF NOT EXISTS `2fa_trusted_browser` (
297         `cookie_hash` varchar(80) NOT NULL COMMENT 'Trusted cookie hash',
298         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
299         `user_agent` text COMMENT 'User agent string',
300         `trusted` boolean NOT NULL DEFAULT '1' COMMENT 'Whenever this browser should be trusted or not',
301         `created` datetime NOT NULL COMMENT 'Datetime the trusted browser was recorded',
302         `last_used` datetime COMMENT 'Datetime the trusted browser was last used',
303          PRIMARY KEY(`cookie_hash`),
304          INDEX `uid` (`uid`),
305         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
306 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication trusted browsers';
307
308 --
309 -- TABLE addon
310 --
311 CREATE TABLE IF NOT EXISTS `addon` (
312         `id` int unsigned NOT NULL auto_increment COMMENT '',
313         `name` varchar(50) NOT NULL DEFAULT '' COMMENT 'addon base (file)name',
314         `version` varchar(50) NOT NULL DEFAULT '' COMMENT 'currently unused',
315         `installed` boolean NOT NULL DEFAULT '0' COMMENT 'currently always 1',
316         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'currently unused',
317         `timestamp` int unsigned NOT NULL DEFAULT 0 COMMENT 'file timestamp to check for reloads',
318         `plugin_admin` boolean NOT NULL DEFAULT '0' COMMENT '1 = has admin config, 0 = has no admin config',
319          PRIMARY KEY(`id`),
320          INDEX `installed_name` (`installed`,`name`),
321          UNIQUE INDEX `name` (`name`)
322 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registered addons';
323
324 --
325 -- TABLE apcontact
326 --
327 CREATE TABLE IF NOT EXISTS `apcontact` (
328         `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
329         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the apcontact url',
330         `uuid` varchar(255) COMMENT '',
331         `type` varchar(20) NOT NULL COMMENT '',
332         `following` varchar(255) COMMENT '',
333         `followers` varchar(255) COMMENT '',
334         `inbox` varchar(255) NOT NULL COMMENT '',
335         `outbox` varchar(255) COMMENT '',
336         `sharedinbox` varchar(255) COMMENT '',
337         `featured` varchar(255) COMMENT 'Address for the collection of featured posts',
338         `featured-tags` varchar(255) COMMENT 'Address for the collection of featured tags',
339         `manually-approve` boolean COMMENT '',
340         `discoverable` boolean COMMENT 'Mastodon extension: true if profile is published in their directory',
341         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
342         `name` varchar(255) COMMENT '',
343         `about` text COMMENT '',
344         `xmpp` varchar(255) COMMENT 'XMPP address',
345         `matrix` varchar(255) COMMENT 'Matrix address',
346         `photo` varchar(255) COMMENT '',
347         `header` varchar(255) COMMENT 'Header picture',
348         `addr` varchar(255) COMMENT '',
349         `alias` varchar(255) COMMENT '',
350         `pubkey` text COMMENT '',
351         `subscribe` varchar(255) COMMENT '',
352         `baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
353         `gsid` int unsigned COMMENT 'Global Server ID',
354         `generator` varchar(255) COMMENT 'Name of the contact\'s system',
355         `following_count` int unsigned DEFAULT 0 COMMENT 'Number of following contacts',
356         `followers_count` int unsigned DEFAULT 0 COMMENT 'Number of followers',
357         `statuses_count` int unsigned DEFAULT 0 COMMENT 'Number of posts',
358         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
359          PRIMARY KEY(`url`),
360          INDEX `addr` (`addr`(32)),
361          INDEX `alias` (`alias`(190)),
362          INDEX `followers` (`followers`(190)),
363          INDEX `baseurl` (`baseurl`(190)),
364          INDEX `sharedinbox` (`sharedinbox`(190)),
365          INDEX `gsid` (`gsid`),
366          UNIQUE INDEX `uri-id` (`uri-id`),
367         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
368         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
369 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
370
371 --
372 -- TABLE application
373 --
374 CREATE TABLE IF NOT EXISTS `application` (
375         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
376         `client_id` varchar(64) NOT NULL COMMENT '',
377         `client_secret` varchar(64) NOT NULL COMMENT '',
378         `name` varchar(255) NOT NULL COMMENT '',
379         `redirect_uri` varchar(255) NOT NULL COMMENT '',
380         `website` varchar(255) COMMENT '',
381         `scopes` varchar(255) COMMENT '',
382         `read` boolean COMMENT 'Read scope',
383         `write` boolean COMMENT 'Write scope',
384         `follow` boolean COMMENT 'Follow scope',
385         `push` boolean COMMENT 'Push scope',
386          PRIMARY KEY(`id`),
387          UNIQUE INDEX `client_id` (`client_id`)
388 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application';
389
390 --
391 -- TABLE application-marker
392 --
393 CREATE TABLE IF NOT EXISTS `application-marker` (
394         `application-id` int unsigned NOT NULL COMMENT '',
395         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
396         `timeline` varchar(64) NOT NULL COMMENT 'Marker (home, notifications)',
397         `last_read_id` varchar(255) COMMENT 'Marker id for the timeline',
398         `version` smallint unsigned COMMENT 'Version number',
399         `updated_at` datetime COMMENT 'creation time',
400          PRIMARY KEY(`application-id`,`uid`,`timeline`),
401          INDEX `uid_id` (`uid`),
402         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
403         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
404 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Timeline marker';
405
406 --
407 -- TABLE application-token
408 --
409 CREATE TABLE IF NOT EXISTS `application-token` (
410         `application-id` int unsigned NOT NULL COMMENT '',
411         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
412         `code` varchar(64) NOT NULL COMMENT '',
413         `access_token` varchar(64) NOT NULL COMMENT '',
414         `created_at` datetime NOT NULL COMMENT 'creation time',
415         `scopes` varchar(255) COMMENT '',
416         `read` boolean COMMENT 'Read scope',
417         `write` boolean COMMENT 'Write scope',
418         `follow` boolean COMMENT 'Follow scope',
419         `push` boolean COMMENT 'Push scope',
420          PRIMARY KEY(`application-id`,`uid`),
421          INDEX `uid_id` (`uid`,`application-id`),
422         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
423         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
424 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth user token';
425
426 --
427 -- TABLE attach
428 --
429 CREATE TABLE IF NOT EXISTS `attach` (
430         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
431         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
432         `hash` varchar(64) NOT NULL DEFAULT '' COMMENT 'hash',
433         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'filename of original',
434         `filetype` varchar(64) NOT NULL DEFAULT '' COMMENT 'mimetype',
435         `filesize` int unsigned NOT NULL DEFAULT 0 COMMENT 'size in bytes',
436         `data` longblob NOT NULL COMMENT 'file data',
437         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
438         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
439         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>',
440         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
441         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
442         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
443         `backend-class` tinytext COMMENT 'Storage backend class',
444         `backend-ref` text COMMENT 'Storage backend data reference',
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='file attachments';
449
450 --
451 -- TABLE cache
452 --
453 CREATE TABLE IF NOT EXISTS `cache` (
454         `k` varbinary(255) NOT NULL COMMENT 'cache key',
455         `v` mediumtext COMMENT 'cached serialized value',
456         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
457         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
458          PRIMARY KEY(`k`),
459          INDEX `k_expires` (`k`,`expires`)
460 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
461
462 --
463 -- TABLE config
464 --
465 CREATE TABLE IF NOT EXISTS `config` (
466         `id` int unsigned NOT NULL auto_increment COMMENT '',
467         `cat` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
468         `k` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
469         `v` mediumtext COMMENT '',
470          PRIMARY KEY(`id`),
471          UNIQUE INDEX `cat_k` (`cat`,`k`)
472 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='main configuration storage';
473
474 --
475 -- TABLE contact-relation
476 --
477 CREATE TABLE IF NOT EXISTS `contact-relation` (
478         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact the related contact had interacted with',
479         `relation-cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'related contact who had interacted with the contact',
480         `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction',
481         `follow-updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last update of the contact relationship',
482         `follows` boolean NOT NULL DEFAULT '0' COMMENT '',
483          PRIMARY KEY(`cid`,`relation-cid`),
484          INDEX `relation-cid` (`relation-cid`),
485         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
486         FOREIGN KEY (`relation-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
487 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Contact relations';
488
489 --
490 -- TABLE conv
491 --
492 CREATE TABLE IF NOT EXISTS `conv` (
493         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
494         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this conversation',
495         `recips` text COMMENT 'sender_handle;recipient_handle',
496         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
497         `creator` varchar(255) NOT NULL DEFAULT '' COMMENT 'handle of creator',
498         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation timestamp',
499         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'edited timestamp',
500         `subject` text COMMENT 'subject of initial message',
501          PRIMARY KEY(`id`),
502          INDEX `uid` (`uid`),
503         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
504 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
505
506 --
507 -- TABLE conversation
508 --
509 CREATE TABLE IF NOT EXISTS `conversation` (
510         `item-uri` varbinary(255) NOT NULL COMMENT 'Original URI of the item - unrelated to the table with the same name',
511         `reply-to-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'URI to which this item is a reply',
512         `conversation-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation URI',
513         `conversation-href` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation link',
514         `protocol` tinyint unsigned NOT NULL DEFAULT 255 COMMENT 'The protocol of the item',
515         `direction` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'How the message arrived here: 1=push, 2=pull',
516         `source` mediumtext COMMENT 'Original source',
517         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Receiving date',
518          PRIMARY KEY(`item-uri`),
519          INDEX `conversation-uri` (`conversation-uri`),
520          INDEX `received` (`received`)
521 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Raw data and structure information for messages';
522
523 --
524 -- TABLE workerqueue
525 --
526 CREATE TABLE IF NOT EXISTS `workerqueue` (
527         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
528         `command` varchar(100) COMMENT 'Task command',
529         `parameter` mediumtext COMMENT 'Task parameter',
530         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
531         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
532         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
533         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
534         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
535         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
536         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
537          PRIMARY KEY(`id`),
538          INDEX `command` (`command`),
539          INDEX `done_command_parameter` (`done`,`command`,`parameter`(64)),
540          INDEX `done_executed` (`done`,`executed`),
541          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
542          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
543          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
544          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
545          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
546 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
547
548 --
549 -- TABLE delayed-post
550 --
551 CREATE TABLE IF NOT EXISTS `delayed-post` (
552         `id` int unsigned NOT NULL auto_increment,
553         `uri` varchar(255) COMMENT 'URI of the post that will be distributed later',
554         `uid` mediumint unsigned COMMENT 'Owner User id',
555         `delayed` datetime COMMENT 'delay time',
556         `wid` int unsigned COMMENT 'Workerqueue id',
557          PRIMARY KEY(`id`),
558          UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
559          INDEX `wid` (`wid`),
560         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
561         FOREIGN KEY (`wid`) REFERENCES `workerqueue` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
562 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be distributed at a later time';
563
564 --
565 -- TABLE diaspora-interaction
566 --
567 CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
568         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
569         `interaction` mediumtext COMMENT 'The Diaspora interaction',
570          PRIMARY KEY(`uri-id`),
571         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
572 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
573
574 --
575 -- TABLE endpoint
576 --
577 CREATE TABLE IF NOT EXISTS `endpoint` (
578         `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
579         `type` varchar(20) NOT NULL COMMENT '',
580         `owner-uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the apcontact url',
581          PRIMARY KEY(`url`),
582          UNIQUE INDEX `owner-uri-id_type` (`owner-uri-id`,`type`),
583         FOREIGN KEY (`owner-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
584 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub endpoints - used in the ActivityPub implementation';
585
586 --
587 -- TABLE event
588 --
589 CREATE TABLE IF NOT EXISTS `event` (
590         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
591         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
592         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
593         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact_id (ID of the contact in contact table)',
594         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
595         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the event uri',
596         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
597         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
598         `start` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event start time',
599         `finish` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event end time',
600         `summary` text COMMENT 'short description or title of the event',
601         `desc` text COMMENT 'event description',
602         `location` text COMMENT 'event location',
603         `type` varchar(20) NOT NULL DEFAULT '' COMMENT 'event or birthday',
604         `nofinish` boolean NOT NULL DEFAULT '0' COMMENT 'if event does have no end this is 1',
605         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '0 or 1',
606         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
607         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
608         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
609         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
610          PRIMARY KEY(`id`),
611          INDEX `uid_start` (`uid`,`start`),
612          INDEX `cid` (`cid`),
613          INDEX `uri-id` (`uri-id`),
614         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
615         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
616         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
617 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events';
618
619 --
620 -- TABLE fcontact
621 --
622 CREATE TABLE IF NOT EXISTS `fcontact` (
623         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
624         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id',
625         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
626         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the fcontact url',
627         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
628         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
629         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
630         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
631         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
632         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
633         `notify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
634         `poll` varchar(255) NOT NULL DEFAULT '' COMMENT '',
635         `confirm` varchar(255) NOT NULL DEFAULT '' COMMENT '',
636         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
637         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
638         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
639         `pubkey` text COMMENT '',
640         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
641         `interacting_count` int unsigned DEFAULT 0 COMMENT 'Number of contacts this contact interactes with',
642         `interacted_count` int unsigned DEFAULT 0 COMMENT 'Number of contacts that interacted with this contact',
643         `post_count` int unsigned DEFAULT 0 COMMENT 'Number of posts and comments',
644          PRIMARY KEY(`id`),
645          INDEX `addr` (`addr`(32)),
646          UNIQUE INDEX `url` (`url`(190)),
647          UNIQUE INDEX `uri-id` (`uri-id`),
648         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
649 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
650
651 --
652 -- TABLE fsuggest
653 --
654 CREATE TABLE IF NOT EXISTS `fsuggest` (
655         `id` int unsigned NOT NULL auto_increment COMMENT '',
656         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
657         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
658         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
659         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
660         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
661         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
662         `note` text COMMENT '',
663         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
664          PRIMARY KEY(`id`),
665          INDEX `cid` (`cid`),
666          INDEX `uid` (`uid`),
667         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
668         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
669 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff';
670
671 --
672 -- TABLE group
673 --
674 CREATE TABLE IF NOT EXISTS `group` (
675         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
676         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
677         `visible` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the member list is not private',
678         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the group has been deleted',
679         `cid` int unsigned COMMENT 'Contact id of forum. When this field is filled then the members are synced automatically.',
680         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'human readable name of group',
681          PRIMARY KEY(`id`),
682          INDEX `uid` (`uid`),
683          INDEX `cid` (`cid`),
684         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
685         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
686 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, group info';
687
688 --
689 -- TABLE group_member
690 --
691 CREATE TABLE IF NOT EXISTS `group_member` (
692         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
693         `gid` int unsigned NOT NULL DEFAULT 0 COMMENT 'groups.id of the associated group',
694         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id of the member assigned to the associated group',
695          PRIMARY KEY(`id`),
696          INDEX `contactid` (`contact-id`),
697          UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`),
698         FOREIGN KEY (`gid`) REFERENCES `group` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
699         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
700 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, member info';
701
702 --
703 -- TABLE gserver-tag
704 --
705 CREATE TABLE IF NOT EXISTS `gserver-tag` (
706         `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
707         `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
708          PRIMARY KEY(`gserver-id`,`tag`),
709          INDEX `tag` (`tag`),
710         FOREIGN KEY (`gserver-id`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
711 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Tags that the server has subscribed';
712
713 --
714 -- TABLE hook
715 --
716 CREATE TABLE IF NOT EXISTS `hook` (
717         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
718         `hook` varbinary(100) NOT NULL DEFAULT '' COMMENT 'name of hook',
719         `file` varbinary(200) NOT NULL DEFAULT '' COMMENT 'relative filename of hook handler',
720         `function` varbinary(200) NOT NULL DEFAULT '' COMMENT 'function name of hook handler',
721         `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',
722          PRIMARY KEY(`id`),
723          INDEX `priority` (`priority`),
724          UNIQUE INDEX `hook_file_function` (`hook`,`file`,`function`)
725 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='addon hook registry';
726
727 --
728 -- TABLE inbox-entry
729 --
730 CREATE TABLE IF NOT EXISTS `inbox-entry` (
731         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
732         `activity-id` varbinary(255) COMMENT 'id of the incoming activity',
733         `object-id` varbinary(255) COMMENT '',
734         `in-reply-to-id` varbinary(255) COMMENT '',
735         `type` varchar(64) COMMENT 'Type of the activity',
736         `object-type` varchar(64) COMMENT 'Type of the object activity',
737         `object-object-type` varchar(64) COMMENT 'Type of the object\'s object activity',
738         `received` datetime COMMENT 'Receiving date',
739         `activity` mediumtext COMMENT 'The JSON activity',
740         `signer` varchar(255) COMMENT '',
741         `push` boolean NOT NULL DEFAULT '0' COMMENT '',
742          PRIMARY KEY(`id`),
743          UNIQUE INDEX `activity-id` (`activity-id`),
744          INDEX `object-id` (`object-id`),
745          INDEX `received` (`received`)
746 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Incoming activity';
747
748 --
749 -- TABLE inbox-entry-receiver
750 --
751 CREATE TABLE IF NOT EXISTS `inbox-entry-receiver` (
752         `queue-id` int unsigned NOT NULL COMMENT '',
753         `uid` mediumint unsigned NOT NULL COMMENT 'User id',
754          PRIMARY KEY(`queue-id`,`uid`),
755          INDEX `uid` (`uid`),
756         FOREIGN KEY (`queue-id`) REFERENCES `inbox-entry` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
757         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
758 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Receiver for the incoming activity';
759
760 --
761 -- TABLE inbox-status
762 --
763 CREATE TABLE IF NOT EXISTS `inbox-status` (
764         `url` varbinary(255) NOT NULL COMMENT 'URL of the inbox',
765         `uri-id` int unsigned COMMENT 'Item-uri id of inbox url',
766         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date of this entry',
767         `success` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful delivery',
768         `failure` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed delivery',
769         `previous` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Previous delivery date',
770         `archive` boolean NOT NULL DEFAULT '0' COMMENT 'Is the inbox archived?',
771         `shared` boolean NOT NULL DEFAULT '0' COMMENT 'Is it a shared inbox?',
772          PRIMARY KEY(`url`),
773          INDEX `uri-id` (`uri-id`),
774         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
775 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Status of ActivityPub inboxes';
776
777 --
778 -- TABLE intro
779 --
780 CREATE TABLE IF NOT EXISTS `intro` (
781         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
782         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
783         `fid` int unsigned COMMENT 'deprecated',
784         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
785         `suggest-cid` int unsigned COMMENT 'Suggested contact',
786         `knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
787         `duplex` boolean NOT NULL DEFAULT '0' COMMENT 'deprecated',
788         `note` text COMMENT '',
789         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
790         `datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
791         `blocked` boolean NOT NULL DEFAULT '0' COMMENT 'deprecated',
792         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '',
793          PRIMARY KEY(`id`),
794          INDEX `contact-id` (`contact-id`),
795          INDEX `suggest-cid` (`suggest-cid`),
796          INDEX `uid` (`uid`),
797         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
798         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
799         FOREIGN KEY (`suggest-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
800 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
801
802 --
803 -- TABLE locks
804 --
805 CREATE TABLE IF NOT EXISTS `locks` (
806         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
807         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
808         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
809         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
810         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
811          PRIMARY KEY(`id`),
812          INDEX `name_expires` (`name`,`expires`)
813 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
814
815 --
816 -- TABLE mail
817 --
818 CREATE TABLE IF NOT EXISTS `mail` (
819         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
820         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
821         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
822         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
823         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
824         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
825         `contact-id` varchar(255) COMMENT 'contact.id',
826         `author-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the author of the mail',
827         `convid` int unsigned COMMENT 'conv.id',
828         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
829         `body` mediumtext COMMENT '',
830         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
831         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
832         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
833         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
834         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
835         `uri-id` int unsigned COMMENT 'Item-uri id of the related mail',
836         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
837         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related mail',
838         `thr-parent` varchar(255) COMMENT '',
839         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
840         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
841          PRIMARY KEY(`id`),
842          INDEX `uid_seen` (`uid`,`seen`),
843          INDEX `convid` (`convid`),
844          INDEX `uri` (`uri`(64)),
845          INDEX `parent-uri` (`parent-uri`(64)),
846          INDEX `contactid` (`contact-id`(32)),
847          INDEX `author-id` (`author-id`),
848          INDEX `uri-id` (`uri-id`),
849          INDEX `parent-uri-id` (`parent-uri-id`),
850          INDEX `thr-parent-id` (`thr-parent-id`),
851         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
852         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
853         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
854         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
855         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
856 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
857
858 --
859 -- TABLE mailacct
860 --
861 CREATE TABLE IF NOT EXISTS `mailacct` (
862         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
863         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
864         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
865         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
866         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
867         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
868         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
869         `pass` text COMMENT '',
870         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
871         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
872         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
873         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
874         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
875          PRIMARY KEY(`id`),
876          INDEX `uid` (`uid`),
877         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
878 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
879
880 --
881 -- TABLE manage
882 --
883 CREATE TABLE IF NOT EXISTS `manage` (
884         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
885         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
886         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
887          PRIMARY KEY(`id`),
888          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
889          INDEX `mid` (`mid`),
890         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
891         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
892 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
893
894 --
895 -- TABLE notification
896 --
897 CREATE TABLE IF NOT EXISTS `notification` (
898         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
899         `uid` mediumint unsigned COMMENT 'Owner User id',
900         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
901         `type` smallint unsigned COMMENT '',
902         `actor-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the actor that caused the notification',
903         `target-uri-id` int unsigned COMMENT 'Item-uri id of the related post',
904         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
905         `created` datetime COMMENT '',
906         `seen` boolean DEFAULT '0' COMMENT 'Seen on the desktop',
907         `dismissed` boolean DEFAULT '0' COMMENT 'Dismissed via the API',
908          PRIMARY KEY(`id`),
909          UNIQUE INDEX `uid_vid_type_actor-id_target-uri-id` (`uid`,`vid`,`type`,`actor-id`,`target-uri-id`),
910          INDEX `vid` (`vid`),
911          INDEX `actor-id` (`actor-id`),
912          INDEX `target-uri-id` (`target-uri-id`),
913          INDEX `parent-uri-id` (`parent-uri-id`),
914          INDEX `seen_uid` (`seen`,`uid`),
915         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
916         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
917         FOREIGN KEY (`actor-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
918         FOREIGN KEY (`target-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
919         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
920 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
921
922 --
923 -- TABLE notify
924 --
925 CREATE TABLE IF NOT EXISTS `notify` (
926         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
927         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
928         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
929         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
930         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
931         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
932         `msg` mediumtext COMMENT '',
933         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
934         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
935         `iid` int unsigned COMMENT '',
936         `parent` int unsigned COMMENT '',
937         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
938         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
939         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
940         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
941         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
942         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
943         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
944          PRIMARY KEY(`id`),
945          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
946          INDEX `uid_date` (`uid`,`date`),
947          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
948          INDEX `uri-id` (`uri-id`),
949          INDEX `parent-uri-id` (`parent-uri-id`),
950         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
951         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
952         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
953 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='[Deprecated] User notifications';
954
955 --
956 -- TABLE notify-threads
957 --
958 CREATE TABLE IF NOT EXISTS `notify-threads` (
959         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
960         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
961         `master-parent-item` int unsigned COMMENT 'Deprecated',
962         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
963         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
964         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
965          PRIMARY KEY(`id`),
966          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
967          INDEX `receiver-uid` (`receiver-uid`),
968          INDEX `notify-id` (`notify-id`),
969         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
970         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
971         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
972 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
973
974 --
975 -- TABLE oembed
976 --
977 CREATE TABLE IF NOT EXISTS `oembed` (
978         `url` varbinary(255) NOT NULL COMMENT 'page url',
979         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
980         `content` mediumtext COMMENT 'OEmbed data of the page',
981         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
982          PRIMARY KEY(`url`,`maxwidth`),
983          INDEX `created` (`created`)
984 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
985
986 --
987 -- TABLE openwebauth-token
988 --
989 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
990         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
991         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
992         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
993         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
994         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
995         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
996          PRIMARY KEY(`id`),
997          INDEX `uid` (`uid`),
998         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
999 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
1000
1001 --
1002 -- TABLE parsed_url
1003 --
1004 CREATE TABLE IF NOT EXISTS `parsed_url` (
1005         `url_hash` binary(64) NOT NULL COMMENT 'page url hash',
1006         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
1007         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
1008         `url` text NOT NULL COMMENT 'page url',
1009         `content` mediumtext COMMENT 'page data',
1010         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
1011         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of expiration',
1012          PRIMARY KEY(`url_hash`,`guessing`,`oembed`),
1013          INDEX `created` (`created`),
1014          INDEX `expires` (`expires`)
1015 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
1016
1017 --
1018 -- TABLE pconfig
1019 --
1020 CREATE TABLE IF NOT EXISTS `pconfig` (
1021         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
1022         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1023         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
1024         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
1025         `v` mediumtext COMMENT 'Value',
1026          PRIMARY KEY(`id`),
1027          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
1028         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1029 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
1030
1031 --
1032 -- TABLE photo
1033 --
1034 CREATE TABLE IF NOT EXISTS `photo` (
1035         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1036         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1037         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1038         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
1039         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
1040         `hash` char(32) COMMENT 'hash value of the photo',
1041         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
1042         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
1043         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1044         `desc` text COMMENT '',
1045         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
1046         `photo-type` tinyint unsigned COMMENT 'User avatar, user banner, contact avatar, contact banner or default',
1047         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1048         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
1049         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1050         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1051         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1052         `data` mediumblob NOT NULL COMMENT '',
1053         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1054         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
1055         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
1056         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
1057         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
1058         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
1059         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
1060         `backend-class` tinytext COMMENT 'Storage backend class',
1061         `backend-ref` text COMMENT 'Storage backend data reference',
1062         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1063          PRIMARY KEY(`id`),
1064          INDEX `contactid` (`contact-id`),
1065          INDEX `uid_contactid` (`uid`,`contact-id`),
1066          INDEX `uid_profile` (`uid`,`profile`),
1067          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
1068          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
1069          INDEX `resource-id` (`resource-id`),
1070          INDEX `uid_photo-type` (`uid`,`photo-type`),
1071         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1072         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1073 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1074
1075 --
1076 -- TABLE post
1077 --
1078 CREATE TABLE IF NOT EXISTS `post` (
1079         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1080         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1081         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1082         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1083         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1084         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1085         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1086         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1087         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1088         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1089         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1090         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1091         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1092         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1093         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1094         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1095         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1096         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1097          PRIMARY KEY(`uri-id`),
1098          INDEX `parent-uri-id` (`parent-uri-id`),
1099          INDEX `thr-parent-id` (`thr-parent-id`),
1100          INDEX `external-id` (`external-id`),
1101          INDEX `owner-id` (`owner-id`),
1102          INDEX `author-id` (`author-id`),
1103          INDEX `causer-id` (`causer-id`),
1104          INDEX `vid` (`vid`),
1105         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1106         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1107         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1108         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1109         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1110         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1111         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1112         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1113 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
1114
1115 --
1116 -- TABLE post-category
1117 --
1118 CREATE TABLE IF NOT EXISTS `post-category` (
1119         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1120         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1121         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1122         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1123          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1124          INDEX `tid` (`tid`),
1125          INDEX `uid_uri-id` (`uid`,`uri-id`),
1126         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1127         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1128         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1129 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1130
1131 --
1132 -- TABLE post-collection
1133 --
1134 CREATE TABLE IF NOT EXISTS `post-collection` (
1135         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1136         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0 - Featured',
1137          PRIMARY KEY(`uri-id`,`type`),
1138          INDEX `type` (`type`),
1139         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1140 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Collection of posts';
1141
1142 --
1143 -- TABLE post-content
1144 --
1145 CREATE TABLE IF NOT EXISTS `post-content` (
1146         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1147         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1148         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1149         `body` mediumtext COMMENT 'item body content',
1150         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1151         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1152         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1153         `language` text COMMENT 'Language information about this post',
1154         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1155         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1156         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1157         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1158         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1159         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1160         `target` text COMMENT 'JSON encoded target structure if used',
1161         `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',
1162         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1163          PRIMARY KEY(`uri-id`),
1164          INDEX `plink` (`plink`(191)),
1165          INDEX `resource-id` (`resource-id`),
1166          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1167         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1168 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1169
1170 --
1171 -- TABLE post-delivery
1172 --
1173 CREATE TABLE IF NOT EXISTS `post-delivery` (
1174         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1175         `inbox-id` int unsigned NOT NULL COMMENT 'Item-uri id of inbox url',
1176         `uid` mediumint unsigned COMMENT 'Delivering user',
1177         `created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
1178         `command` varbinary(32) COMMENT '',
1179         `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
1180         `receivers` mediumtext COMMENT 'JSON encoded array with the receiving contacts',
1181          PRIMARY KEY(`uri-id`,`inbox-id`),
1182          INDEX `inbox-id_created` (`inbox-id`,`created`),
1183          INDEX `uid` (`uid`),
1184         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1185         FOREIGN KEY (`inbox-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1186         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1187 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for posts for the batch processing';
1188
1189 --
1190 -- TABLE post-delivery-data
1191 --
1192 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1193         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1194         `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',
1195         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1196         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1197         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1198         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1199         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1200         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1201         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1202         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1203         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1204          PRIMARY KEY(`uri-id`),
1205         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1206 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1207
1208 --
1209 -- TABLE post-history
1210 --
1211 CREATE TABLE IF NOT EXISTS `post-history` (
1212         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1213         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of edit',
1214         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1215         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1216         `body` mediumtext COMMENT 'item body content',
1217         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1218         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1219         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1220         `language` text COMMENT 'Language information about this post',
1221         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1222         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1223         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1224         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1225         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1226         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1227         `target` text COMMENT 'JSON encoded target structure if used',
1228         `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',
1229         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1230          PRIMARY KEY(`uri-id`,`edited`),
1231         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1232 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post history';
1233
1234 --
1235 -- TABLE post-link
1236 --
1237 CREATE TABLE IF NOT EXISTS `post-link` (
1238         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1239         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1240         `url` varbinary(511) NOT NULL COMMENT 'External URL',
1241         `mimetype` varchar(60) COMMENT '',
1242          PRIMARY KEY(`id`),
1243          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1244         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1245 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post related external links';
1246
1247 --
1248 -- TABLE post-media
1249 --
1250 CREATE TABLE IF NOT EXISTS `post-media` (
1251         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1252         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1253         `url` varbinary(1024) NOT NULL COMMENT 'Media URL',
1254         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1255         `mimetype` varchar(60) COMMENT '',
1256         `height` smallint unsigned COMMENT 'Height of the media',
1257         `width` smallint unsigned COMMENT 'Width of the media',
1258         `size` bigint unsigned COMMENT 'Media size',
1259         `preview` varbinary(512) COMMENT 'Preview URL',
1260         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1261         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1262         `description` text COMMENT '',
1263         `name` varchar(255) COMMENT 'Name of the media',
1264         `author-url` varbinary(255) COMMENT 'URL of the author of the media',
1265         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1266         `author-image` varbinary(255) COMMENT 'Image of the author of the media',
1267         `publisher-url` varbinary(255) COMMENT 'URL of the publisher of the media',
1268         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1269         `publisher-image` varbinary(255) COMMENT 'Image of the publisher of the media',
1270          PRIMARY KEY(`id`),
1271          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`(512)),
1272          INDEX `uri-id-id` (`uri-id`,`id`),
1273         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1274 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1275
1276 --
1277 -- TABLE post-question
1278 --
1279 CREATE TABLE IF NOT EXISTS `post-question` (
1280         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1281         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1282         `multiple` boolean NOT NULL DEFAULT '0' COMMENT 'Multiple choice',
1283         `voters` int unsigned COMMENT 'Number of voters for this question',
1284         `end-time` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Question end time',
1285          PRIMARY KEY(`id`),
1286          UNIQUE INDEX `uri-id` (`uri-id`),
1287         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1288 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question';
1289
1290 --
1291 -- TABLE post-question-option
1292 --
1293 CREATE TABLE IF NOT EXISTS `post-question-option` (
1294         `id` int unsigned NOT NULL COMMENT 'Id of the question',
1295         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1296         `name` varchar(255) COMMENT 'Name of the option',
1297         `replies` int unsigned COMMENT 'Number of replies for this question option',
1298          PRIMARY KEY(`uri-id`,`id`),
1299         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1300 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question option';
1301
1302 --
1303 -- TABLE post-tag
1304 --
1305 CREATE TABLE IF NOT EXISTS `post-tag` (
1306         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1307         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1308         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1309         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1310          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1311          INDEX `tid` (`tid`),
1312          INDEX `cid` (`cid`),
1313         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1314         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1315         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1316 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1317
1318 --
1319 -- TABLE post-thread
1320 --
1321 CREATE TABLE IF NOT EXISTS `post-thread` (
1322         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1323         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1324         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1325         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1326         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1327         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1328         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1329         `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',
1330         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1331          PRIMARY KEY(`uri-id`),
1332          INDEX `owner-id` (`owner-id`),
1333          INDEX `author-id` (`author-id`),
1334          INDEX `causer-id` (`causer-id`),
1335          INDEX `received` (`received`),
1336          INDEX `commented` (`commented`),
1337         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1338         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1339         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1340         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1341 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1342
1343 --
1344 -- TABLE post-user
1345 --
1346 CREATE TABLE IF NOT EXISTS `post-user` (
1347         `id` int unsigned NOT NULL auto_increment,
1348         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1349         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1350         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1351         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1352         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1353         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1354         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1355         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1356         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1357         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1358         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1359         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1360         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1361         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1362         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1363         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1364         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1365         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1366         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1367         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1368         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1369         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1370         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1371         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1372         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1373         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1374         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1375         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1376         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1377          PRIMARY KEY(`id`),
1378          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1379          INDEX `uri-id` (`uri-id`),
1380          INDEX `parent-uri-id` (`parent-uri-id`),
1381          INDEX `thr-parent-id` (`thr-parent-id`),
1382          INDEX `external-id` (`external-id`),
1383          INDEX `owner-id` (`owner-id`),
1384          INDEX `author-id` (`author-id`),
1385          INDEX `causer-id` (`causer-id`),
1386          INDEX `vid` (`vid`),
1387          INDEX `contact-id` (`contact-id`),
1388          INDEX `event-id` (`event-id`),
1389          INDEX `psid` (`psid`),
1390          INDEX `author-id_uid` (`author-id`,`uid`),
1391          INDEX `author-id_received` (`author-id`,`received`),
1392          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1393          INDEX `uid_contactid` (`uid`,`contact-id`),
1394          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1395          INDEX `uid_unseen` (`uid`,`unseen`),
1396          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1397         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1398         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1399         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1400         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1401         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1402         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1403         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1404         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1405         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1406         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1407         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1408         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1409 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1410
1411 --
1412 -- TABLE post-thread-user
1413 --
1414 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1415         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1416         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1417         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1418         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1419         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1420         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1421         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1422         `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',
1423         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1424         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1425         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'deprecated',
1426         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1427         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1428         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1429         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1430         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1431         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Deprecated',
1432         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1433         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1434         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1435         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1436         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1437         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1438          PRIMARY KEY(`uid`,`uri-id`),
1439          INDEX `uri-id` (`uri-id`),
1440          INDEX `owner-id` (`owner-id`),
1441          INDEX `author-id` (`author-id`),
1442          INDEX `causer-id` (`causer-id`),
1443          INDEX `uid` (`uid`),
1444          INDEX `contact-id` (`contact-id`),
1445          INDEX `psid` (`psid`),
1446          INDEX `post-user-id` (`post-user-id`),
1447          INDEX `commented` (`commented`),
1448          INDEX `uid_received` (`uid`,`received`),
1449          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1450          INDEX `uid_commented` (`uid`,`commented`),
1451          INDEX `uid_starred` (`uid`,`starred`),
1452          INDEX `uid_mention` (`uid`,`mention`),
1453         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1454         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1455         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1456         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1457         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1458         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1459         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1460         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1461 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1462
1463 --
1464 -- TABLE post-user-notification
1465 --
1466 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1467         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1468         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1469         `notification-type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1470          PRIMARY KEY(`uid`,`uri-id`),
1471          INDEX `uri-id` (`uri-id`),
1472         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1473         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1474 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1475
1476 --
1477 -- TABLE process
1478 --
1479 CREATE TABLE IF NOT EXISTS `process` (
1480         `pid` int unsigned NOT NULL COMMENT 'The ID of the process',
1481         `hostname` varchar(32) NOT NULL COMMENT 'The name of the host the process is ran on',
1482         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1483         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1484          PRIMARY KEY(`pid`,`hostname`),
1485          INDEX `command` (`command`)
1486 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1487
1488 --
1489 -- TABLE profile
1490 --
1491 CREATE TABLE IF NOT EXISTS `profile` (
1492         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1493         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1494         `profile-name` varchar(255) COMMENT 'Deprecated',
1495         `is-default` boolean COMMENT 'Deprecated',
1496         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1497         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1498         `pdesc` varchar(255) COMMENT 'Deprecated',
1499         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1500         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1501         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1502         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1503         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1504         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1505         `hometown` varchar(255) COMMENT 'Deprecated',
1506         `gender` varchar(32) COMMENT 'Deprecated',
1507         `marital` varchar(255) COMMENT 'Deprecated',
1508         `with` text COMMENT 'Deprecated',
1509         `howlong` datetime COMMENT 'Deprecated',
1510         `sexual` varchar(255) COMMENT 'Deprecated',
1511         `politic` varchar(255) COMMENT 'Deprecated',
1512         `religion` varchar(255) COMMENT 'Deprecated',
1513         `pub_keywords` text COMMENT '',
1514         `prv_keywords` text COMMENT '',
1515         `likes` text COMMENT 'Deprecated',
1516         `dislikes` text COMMENT 'Deprecated',
1517         `about` text COMMENT 'Profile description',
1518         `summary` varchar(255) COMMENT 'Deprecated',
1519         `music` text COMMENT 'Deprecated',
1520         `book` text COMMENT 'Deprecated',
1521         `tv` text COMMENT 'Deprecated',
1522         `film` text COMMENT 'Deprecated',
1523         `interest` text COMMENT 'Deprecated',
1524         `romance` text COMMENT 'Deprecated',
1525         `work` text COMMENT 'Deprecated',
1526         `education` text COMMENT 'Deprecated',
1527         `contact` text COMMENT 'Deprecated',
1528         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1529         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
1530         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
1531         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1532         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1533         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1534         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1535          PRIMARY KEY(`id`),
1536          INDEX `uid_is-default` (`uid`,`is-default`),
1537          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1538         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1539 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1540
1541 --
1542 -- TABLE profile_field
1543 --
1544 CREATE TABLE IF NOT EXISTS `profile_field` (
1545         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1546         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1547         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1548         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1549         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1550         `value` text COMMENT 'Value of the field',
1551         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1552         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1553          PRIMARY KEY(`id`),
1554          INDEX `uid` (`uid`),
1555          INDEX `order` (`order`),
1556          INDEX `psid` (`psid`),
1557         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1558         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1559 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1560
1561 --
1562 -- TABLE push_subscriber
1563 --
1564 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1565         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1566         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1567         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1568         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1569         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1570         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1571         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1572         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1573         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1574         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1575          PRIMARY KEY(`id`),
1576          INDEX `next_try` (`next_try`),
1577          INDEX `uid` (`uid`),
1578         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1579 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1580
1581 --
1582 -- TABLE register
1583 --
1584 CREATE TABLE IF NOT EXISTS `register` (
1585         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1586         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1587         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1588         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1589         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1590         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1591         `note` text COMMENT '',
1592          PRIMARY KEY(`id`),
1593          INDEX `uid` (`uid`),
1594         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1595 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1596
1597 --
1598 -- TABLE search
1599 --
1600 CREATE TABLE IF NOT EXISTS `search` (
1601         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1602         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1603         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1604          PRIMARY KEY(`id`),
1605          INDEX `uid_term` (`uid`,`term`(64)),
1606          INDEX `term` (`term`(64)),
1607         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1608 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1609
1610 --
1611 -- TABLE session
1612 --
1613 CREATE TABLE IF NOT EXISTS `session` (
1614         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1615         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1616         `data` text COMMENT '',
1617         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1618          PRIMARY KEY(`id`),
1619          INDEX `sid` (`sid`(64)),
1620          INDEX `expire` (`expire`)
1621 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1622
1623 --
1624 -- TABLE storage
1625 --
1626 CREATE TABLE IF NOT EXISTS `storage` (
1627         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1628         `data` longblob NOT NULL COMMENT 'file data',
1629          PRIMARY KEY(`id`)
1630 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1631
1632 --
1633 -- TABLE subscription
1634 --
1635 CREATE TABLE IF NOT EXISTS `subscription` (
1636         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1637         `application-id` int unsigned NOT NULL COMMENT '',
1638         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
1639         `endpoint` varchar(511) COMMENT 'Endpoint URL',
1640         `pubkey` varchar(127) COMMENT 'User agent public key',
1641         `secret` varchar(32) COMMENT 'Auth secret',
1642         `follow` boolean COMMENT '',
1643         `favourite` boolean COMMENT '',
1644         `reblog` boolean COMMENT '',
1645         `mention` boolean COMMENT '',
1646         `poll` boolean COMMENT '',
1647         `follow_request` boolean COMMENT '',
1648         `status` boolean COMMENT '',
1649          PRIMARY KEY(`id`),
1650          UNIQUE INDEX `application-id_uid` (`application-id`,`uid`),
1651          INDEX `uid_application-id` (`uid`,`application-id`),
1652         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1653         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1654 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Push Subscription for the API';
1655
1656 --
1657 -- TABLE userd
1658 --
1659 CREATE TABLE IF NOT EXISTS `userd` (
1660         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1661         `username` varchar(255) NOT NULL COMMENT '',
1662          PRIMARY KEY(`id`),
1663          INDEX `username` (`username`(32))
1664 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1665
1666 --
1667 -- TABLE user-contact
1668 --
1669 CREATE TABLE IF NOT EXISTS `user-contact` (
1670         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1671         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1672         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
1673         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1674         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1675         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1676         `hidden` boolean COMMENT 'This contact is hidden from the others',
1677         `is-blocked` boolean COMMENT 'User is blocked by this contact',
1678         `pending` boolean COMMENT '',
1679         `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
1680         `info` mediumtext COMMENT '',
1681         `notify_new_posts` boolean COMMENT '',
1682         `remote_self` boolean COMMENT '',
1683         `fetch_further_information` tinyint unsigned COMMENT '',
1684         `ffi_keyword_denylist` text COMMENT '',
1685         `subhub` boolean COMMENT '',
1686         `hub-verify` varchar(255) COMMENT '',
1687         `protocol` char(4) COMMENT 'Protocol of the contact',
1688         `rating` tinyint COMMENT 'Automatically detected feed poll frequency',
1689         `priority` tinyint unsigned COMMENT 'Feed poll priority',
1690          PRIMARY KEY(`uid`,`cid`),
1691          INDEX `cid` (`cid`),
1692          UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
1693         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1694         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1695         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1696 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1697
1698 --
1699 -- TABLE worker-ipc
1700 --
1701 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1702         `key` int NOT NULL COMMENT '',
1703         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1704          PRIMARY KEY(`key`)
1705 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1706
1707 --
1708 -- VIEW application-view
1709 --
1710 DROP VIEW IF EXISTS `application-view`;
1711 CREATE VIEW `application-view` AS SELECT 
1712         `application`.`id` AS `id`,
1713         `application-token`.`uid` AS `uid`,
1714         `application`.`name` AS `name`,
1715         `application`.`redirect_uri` AS `redirect_uri`,
1716         `application`.`website` AS `website`,
1717         `application`.`client_id` AS `client_id`,
1718         `application`.`client_secret` AS `client_secret`,
1719         `application-token`.`code` AS `code`,
1720         `application-token`.`access_token` AS `access_token`,
1721         `application-token`.`created_at` AS `created_at`,
1722         `application-token`.`scopes` AS `scopes`,
1723         `application-token`.`read` AS `read`,
1724         `application-token`.`write` AS `write`,
1725         `application-token`.`follow` AS `follow`,
1726         `application-token`.`push` AS `push`
1727         FROM `application-token`
1728                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1729
1730 --
1731 -- VIEW post-user-view
1732 --
1733 DROP VIEW IF EXISTS `post-user-view`;
1734 CREATE VIEW `post-user-view` AS SELECT 
1735         `post-user`.`id` AS `id`,
1736         `post-user`.`id` AS `post-user-id`,
1737         `post-user`.`uid` AS `uid`,
1738         `parent-post`.`id` AS `parent`,
1739         `item-uri`.`uri` AS `uri`,
1740         `post-user`.`uri-id` AS `uri-id`,
1741         `parent-item-uri`.`uri` AS `parent-uri`,
1742         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1743         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1744         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1745         `item-uri`.`guid` AS `guid`,
1746         `post-user`.`wall` AS `wall`,
1747         `post-user`.`gravity` AS `gravity`,
1748         `external-item-uri`.`uri` AS `extid`,
1749         `post-user`.`external-id` AS `external-id`,
1750         `post-user`.`created` AS `created`,
1751         `post-user`.`edited` AS `edited`,
1752         `post-thread-user`.`commented` AS `commented`,
1753         `post-user`.`received` AS `received`,
1754         `post-thread-user`.`changed` AS `changed`,
1755         `post-user`.`post-type` AS `post-type`,
1756         `post-user`.`post-reason` AS `post-reason`,
1757         `post-user`.`private` AS `private`,
1758         `post-thread-user`.`pubmail` AS `pubmail`,
1759         `post-user`.`visible` AS `visible`,
1760         `post-thread-user`.`starred` AS `starred`,
1761         `post-user`.`unseen` AS `unseen`,
1762         `post-user`.`deleted` AS `deleted`,
1763         `post-user`.`origin` AS `origin`,
1764         `post-thread-user`.`origin` AS `parent-origin`,
1765         `post-thread-user`.`mention` AS `mention`,
1766         `post-user`.`global` AS `global`,
1767         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
1768         `post-user`.`network` AS `network`,
1769         `post-user`.`vid` AS `vid`,
1770         `post-user`.`psid` AS `psid`,
1771         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1772         `post-content`.`title` AS `title`,
1773         `post-content`.`content-warning` AS `content-warning`,
1774         `post-content`.`raw-body` AS `raw-body`,
1775         IFNULL (`post-content`.`body`, '') AS `body`,
1776         `post-content`.`rendered-hash` AS `rendered-hash`,
1777         `post-content`.`rendered-html` AS `rendered-html`,
1778         `post-content`.`language` AS `language`,
1779         `post-content`.`plink` AS `plink`,
1780         `post-content`.`location` AS `location`,
1781         `post-content`.`coord` AS `coord`,
1782         `post-content`.`app` AS `app`,
1783         `post-content`.`object-type` AS `object-type`,
1784         `post-content`.`object` AS `object`,
1785         `post-content`.`target-type` AS `target-type`,
1786         `post-content`.`target` AS `target`,
1787         `post-content`.`resource-id` AS `resource-id`,
1788         `post-user`.`contact-id` AS `contact-id`,
1789         `contact`.`uri-id` AS `contact-uri-id`,
1790         `contact`.`url` AS `contact-link`,
1791         `contact`.`addr` AS `contact-addr`,
1792         `contact`.`name` AS `contact-name`,
1793         `contact`.`nick` AS `contact-nick`,
1794         `contact`.`thumb` AS `contact-avatar`,
1795         `contact`.`network` AS `contact-network`,
1796         `contact`.`blocked` AS `contact-blocked`,
1797         `contact`.`hidden` AS `contact-hidden`,
1798         `contact`.`readonly` AS `contact-readonly`,
1799         `contact`.`archive` AS `contact-archive`,
1800         `contact`.`pending` AS `contact-pending`,
1801         `contact`.`rel` AS `contact-rel`,
1802         `contact`.`uid` AS `contact-uid`,
1803         `contact`.`contact-type` AS `contact-contact-type`,
1804         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1805         `contact`.`self` AS `self`,
1806         `contact`.`id` AS `cid`,
1807         `contact`.`alias` AS `alias`,
1808         `contact`.`photo` AS `photo`,
1809         `contact`.`name-date` AS `name-date`,
1810         `contact`.`uri-date` AS `uri-date`,
1811         `contact`.`avatar-date` AS `avatar-date`,
1812         `contact`.`thumb` AS `thumb`,
1813         `post-user`.`author-id` AS `author-id`,
1814         `author`.`uri-id` AS `author-uri-id`,
1815         `author`.`url` AS `author-link`,
1816         `author`.`addr` AS `author-addr`,
1817         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1818         `author`.`nick` AS `author-nick`,
1819         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1820         `author`.`network` AS `author-network`,
1821         `author`.`blocked` AS `author-blocked`,
1822         `author`.`hidden` AS `author-hidden`,
1823         `author`.`updated` AS `author-updated`,
1824         `author`.`gsid` AS `author-gsid`,
1825         `post-user`.`owner-id` AS `owner-id`,
1826         `owner`.`uri-id` AS `owner-uri-id`,
1827         `owner`.`url` AS `owner-link`,
1828         `owner`.`addr` AS `owner-addr`,
1829         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1830         `owner`.`nick` AS `owner-nick`,
1831         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1832         `owner`.`network` AS `owner-network`,
1833         `owner`.`blocked` AS `owner-blocked`,
1834         `owner`.`hidden` AS `owner-hidden`,
1835         `owner`.`updated` AS `owner-updated`,
1836         `owner`.`contact-type` AS `owner-contact-type`,
1837         `post-user`.`causer-id` AS `causer-id`,
1838         `causer`.`uri-id` AS `causer-uri-id`,
1839         `causer`.`url` AS `causer-link`,
1840         `causer`.`addr` AS `causer-addr`,
1841         `causer`.`name` AS `causer-name`,
1842         `causer`.`nick` AS `causer-nick`,
1843         `causer`.`thumb` AS `causer-avatar`,
1844         `causer`.`network` AS `causer-network`,
1845         `causer`.`blocked` AS `causer-blocked`,
1846         `causer`.`hidden` AS `causer-hidden`,
1847         `causer`.`contact-type` AS `causer-contact-type`,
1848         `post-delivery-data`.`postopts` AS `postopts`,
1849         `post-delivery-data`.`inform` AS `inform`,
1850         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1851         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1852         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1853         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1854         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1855         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1856         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1857         `post-user`.`event-id` AS `event-id`,
1858         `event`.`created` AS `event-created`,
1859         `event`.`edited` AS `event-edited`,
1860         `event`.`start` AS `event-start`,
1861         `event`.`finish` AS `event-finish`,
1862         `event`.`summary` AS `event-summary`,
1863         `event`.`desc` AS `event-desc`,
1864         `event`.`location` AS `event-location`,
1865         `event`.`type` AS `event-type`,
1866         `event`.`nofinish` AS `event-nofinish`,
1867         `event`.`ignore` AS `event-ignore`,
1868         `post-question`.`id` AS `question-id`,
1869         `post-question`.`multiple` AS `question-multiple`,
1870         `post-question`.`voters` AS `question-voters`,
1871         `post-question`.`end-time` AS `question-end-time`,
1872         EXISTS(SELECT `uri-id` FROM `post-category` WHERE `post-category`.`uri-id` = `post-user`.`uri-id` AND `post-category`.`uid` = `post-user`.`uid`) AS `has-categories`,
1873         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-user`.`uri-id`) AS `has-media`,
1874         `diaspora-interaction`.`interaction` AS `signed_text`,
1875         `parent-item-uri`.`guid` AS `parent-guid`,
1876         `parent-post`.`network` AS `parent-network`,
1877         `parent-post`.`author-id` AS `parent-author-id`,
1878         `parent-post-author`.`url` AS `parent-author-link`,
1879         `parent-post-author`.`name` AS `parent-author-name`,
1880         `parent-post-author`.`nick` AS `parent-author-nick`,
1881         `parent-post-author`.`network` AS `parent-author-network`,
1882         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1883         `parent-post-author`.`hidden` AS `parent-author-hidden`
1884         FROM `post-user`
1885                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1886                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1887                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1888                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1889                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1890                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1891                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1892                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1893                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1894                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1895                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1896                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1897                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1898                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1899                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
1900                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1901                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1902                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1903
1904 --
1905 -- VIEW post-thread-user-view
1906 --
1907 DROP VIEW IF EXISTS `post-thread-user-view`;
1908 CREATE VIEW `post-thread-user-view` AS SELECT 
1909         `post-user`.`id` AS `id`,
1910         `post-user`.`id` AS `post-user-id`,
1911         `post-thread-user`.`uid` AS `uid`,
1912         `parent-post`.`id` AS `parent`,
1913         `item-uri`.`uri` AS `uri`,
1914         `post-thread-user`.`uri-id` AS `uri-id`,
1915         `parent-item-uri`.`uri` AS `parent-uri`,
1916         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1917         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1918         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1919         `item-uri`.`guid` AS `guid`,
1920         `post-thread-user`.`wall` AS `wall`,
1921         `post-user`.`gravity` AS `gravity`,
1922         `external-item-uri`.`uri` AS `extid`,
1923         `post-user`.`external-id` AS `external-id`,
1924         `post-thread-user`.`created` AS `created`,
1925         `post-user`.`edited` AS `edited`,
1926         `post-thread-user`.`commented` AS `commented`,
1927         `post-thread-user`.`received` AS `received`,
1928         `post-thread-user`.`changed` AS `changed`,
1929         `post-user`.`post-type` AS `post-type`,
1930         `post-user`.`post-reason` AS `post-reason`,
1931         `post-user`.`private` AS `private`,
1932         `post-thread-user`.`pubmail` AS `pubmail`,
1933         `post-thread-user`.`ignored` AS `ignored`,
1934         `post-user`.`visible` AS `visible`,
1935         `post-thread-user`.`starred` AS `starred`,
1936         `post-thread-user`.`unseen` AS `unseen`,
1937         `post-user`.`deleted` AS `deleted`,
1938         `post-thread-user`.`origin` AS `origin`,
1939         `post-thread-user`.`mention` AS `mention`,
1940         `post-user`.`global` AS `global`,
1941         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
1942         `post-thread-user`.`network` AS `network`,
1943         `post-user`.`vid` AS `vid`,
1944         `post-thread-user`.`psid` AS `psid`,
1945         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1946         `post-content`.`title` AS `title`,
1947         `post-content`.`content-warning` AS `content-warning`,
1948         `post-content`.`raw-body` AS `raw-body`,
1949         `post-content`.`body` AS `body`,
1950         `post-content`.`rendered-hash` AS `rendered-hash`,
1951         `post-content`.`rendered-html` AS `rendered-html`,
1952         `post-content`.`language` AS `language`,
1953         `post-content`.`plink` AS `plink`,
1954         `post-content`.`location` AS `location`,
1955         `post-content`.`coord` AS `coord`,
1956         `post-content`.`app` AS `app`,
1957         `post-content`.`object-type` AS `object-type`,
1958         `post-content`.`object` AS `object`,
1959         `post-content`.`target-type` AS `target-type`,
1960         `post-content`.`target` AS `target`,
1961         `post-content`.`resource-id` AS `resource-id`,
1962         `post-thread-user`.`contact-id` AS `contact-id`,
1963         `contact`.`uri-id` AS `contact-uri-id`,
1964         `contact`.`url` AS `contact-link`,
1965         `contact`.`addr` AS `contact-addr`,
1966         `contact`.`name` AS `contact-name`,
1967         `contact`.`nick` AS `contact-nick`,
1968         `contact`.`thumb` AS `contact-avatar`,
1969         `contact`.`network` AS `contact-network`,
1970         `contact`.`blocked` AS `contact-blocked`,
1971         `contact`.`hidden` AS `contact-hidden`,
1972         `contact`.`readonly` AS `contact-readonly`,
1973         `contact`.`archive` AS `contact-archive`,
1974         `contact`.`pending` AS `contact-pending`,
1975         `contact`.`rel` AS `contact-rel`,
1976         `contact`.`uid` AS `contact-uid`,
1977         `contact`.`contact-type` AS `contact-contact-type`,
1978         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1979         `contact`.`self` AS `self`,
1980         `contact`.`id` AS `cid`,
1981         `contact`.`alias` AS `alias`,
1982         `contact`.`photo` AS `photo`,
1983         `contact`.`name-date` AS `name-date`,
1984         `contact`.`uri-date` AS `uri-date`,
1985         `contact`.`avatar-date` AS `avatar-date`,
1986         `contact`.`thumb` AS `thumb`,
1987         `post-thread-user`.`author-id` AS `author-id`,
1988         `author`.`uri-id` AS `author-uri-id`,
1989         `author`.`url` AS `author-link`,
1990         `author`.`addr` AS `author-addr`,
1991         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1992         `author`.`nick` AS `author-nick`,
1993         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1994         `author`.`network` AS `author-network`,
1995         `author`.`blocked` AS `author-blocked`,
1996         `author`.`hidden` AS `author-hidden`,
1997         `author`.`updated` AS `author-updated`,
1998         `author`.`gsid` AS `author-gsid`,
1999         `post-thread-user`.`owner-id` AS `owner-id`,
2000         `owner`.`uri-id` AS `owner-uri-id`,
2001         `owner`.`url` AS `owner-link`,
2002         `owner`.`addr` AS `owner-addr`,
2003         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
2004         `owner`.`nick` AS `owner-nick`,
2005         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
2006         `owner`.`network` AS `owner-network`,
2007         `owner`.`blocked` AS `owner-blocked`,
2008         `owner`.`hidden` AS `owner-hidden`,
2009         `owner`.`updated` AS `owner-updated`,
2010         `owner`.`contact-type` AS `owner-contact-type`,
2011         `post-thread-user`.`causer-id` AS `causer-id`,
2012         `causer`.`uri-id` AS `causer-uri-id`,
2013         `causer`.`url` AS `causer-link`,
2014         `causer`.`addr` AS `causer-addr`,
2015         `causer`.`name` AS `causer-name`,
2016         `causer`.`nick` AS `causer-nick`,
2017         `causer`.`thumb` AS `causer-avatar`,
2018         `causer`.`network` AS `causer-network`,
2019         `causer`.`blocked` AS `causer-blocked`,
2020         `causer`.`hidden` AS `causer-hidden`,
2021         `causer`.`contact-type` AS `causer-contact-type`,
2022         `post-delivery-data`.`postopts` AS `postopts`,
2023         `post-delivery-data`.`inform` AS `inform`,
2024         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
2025         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
2026         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
2027         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
2028         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
2029         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
2030         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
2031         `post-user`.`event-id` AS `event-id`,
2032         `event`.`created` AS `event-created`,
2033         `event`.`edited` AS `event-edited`,
2034         `event`.`start` AS `event-start`,
2035         `event`.`finish` AS `event-finish`,
2036         `event`.`summary` AS `event-summary`,
2037         `event`.`desc` AS `event-desc`,
2038         `event`.`location` AS `event-location`,
2039         `event`.`type` AS `event-type`,
2040         `event`.`nofinish` AS `event-nofinish`,
2041         `event`.`ignore` AS `event-ignore`,
2042         `post-question`.`id` AS `question-id`,
2043         `post-question`.`multiple` AS `question-multiple`,
2044         `post-question`.`voters` AS `question-voters`,
2045         `post-question`.`end-time` AS `question-end-time`,
2046         EXISTS(SELECT `uri-id` FROM `post-category` WHERE `post-category`.`uri-id` = `post-thread-user`.`uri-id` AND `post-category`.`uid` = `post-thread-user`.`uid`) AS `has-categories`,
2047         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-user`.`uri-id`) AS `has-media`,
2048         `diaspora-interaction`.`interaction` AS `signed_text`,
2049         `parent-item-uri`.`guid` AS `parent-guid`,
2050         `parent-post`.`network` AS `parent-network`,
2051         `parent-post`.`author-id` AS `parent-author-id`,
2052         `parent-post-author`.`url` AS `parent-author-link`,
2053         `parent-post-author`.`name` AS `parent-author-name`,
2054         `parent-post-author`.`network` AS `parent-author-network`,
2055         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2056         `parent-post-author`.`hidden` AS `parent-author-hidden`
2057         FROM `post-thread-user`
2058                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2059                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2060                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
2061                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
2062                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
2063                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
2064                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
2065                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
2066                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
2067                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
2068                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
2069                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
2070                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
2071                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
2072                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
2073                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
2074                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-thread-user`.`uid`
2075                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2076
2077 --
2078 -- VIEW post-view
2079 --
2080 DROP VIEW IF EXISTS `post-view`;
2081 CREATE VIEW `post-view` AS SELECT 
2082         `item-uri`.`uri` AS `uri`,
2083         `post`.`uri-id` AS `uri-id`,
2084         `parent-item-uri`.`uri` AS `parent-uri`,
2085         `post`.`parent-uri-id` AS `parent-uri-id`,
2086         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2087         `post`.`thr-parent-id` AS `thr-parent-id`,
2088         `item-uri`.`guid` AS `guid`,
2089         `post`.`gravity` AS `gravity`,
2090         `external-item-uri`.`uri` AS `extid`,
2091         `post`.`external-id` AS `external-id`,
2092         `post`.`created` AS `created`,
2093         `post`.`edited` AS `edited`,
2094         `post-thread`.`commented` AS `commented`,
2095         `post`.`received` AS `received`,
2096         `post-thread`.`changed` AS `changed`,
2097         `post`.`post-type` AS `post-type`,
2098         `post`.`private` AS `private`,
2099         `post`.`visible` AS `visible`,
2100         `post`.`deleted` AS `deleted`,
2101         `post`.`global` AS `global`,
2102         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
2103         `post`.`network` AS `network`,
2104         `post`.`vid` AS `vid`,
2105         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2106         `post-content`.`title` AS `title`,
2107         `post-content`.`content-warning` AS `content-warning`,
2108         `post-content`.`raw-body` AS `raw-body`,
2109         `post-content`.`body` AS `body`,
2110         `post-content`.`rendered-hash` AS `rendered-hash`,
2111         `post-content`.`rendered-html` AS `rendered-html`,
2112         `post-content`.`language` AS `language`,
2113         `post-content`.`plink` AS `plink`,
2114         `post-content`.`location` AS `location`,
2115         `post-content`.`coord` AS `coord`,
2116         `post-content`.`app` AS `app`,
2117         `post-content`.`object-type` AS `object-type`,
2118         `post-content`.`object` AS `object`,
2119         `post-content`.`target-type` AS `target-type`,
2120         `post-content`.`target` AS `target`,
2121         `post-content`.`resource-id` AS `resource-id`,
2122         `post`.`author-id` AS `contact-id`,
2123         `author`.`uri-id` AS `contact-uri-id`,
2124         `author`.`url` AS `contact-link`,
2125         `author`.`addr` AS `contact-addr`,
2126         `author`.`name` AS `contact-name`,
2127         `author`.`nick` AS `contact-nick`,
2128         `author`.`thumb` AS `contact-avatar`,
2129         `author`.`network` AS `contact-network`,
2130         `author`.`blocked` AS `contact-blocked`,
2131         `author`.`hidden` AS `contact-hidden`,
2132         `author`.`readonly` AS `contact-readonly`,
2133         `author`.`archive` AS `contact-archive`,
2134         `author`.`pending` AS `contact-pending`,
2135         `author`.`rel` AS `contact-rel`,
2136         `author`.`uid` AS `contact-uid`,
2137         `author`.`contact-type` AS `contact-contact-type`,
2138         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2139         false AS `self`,
2140         `author`.`id` AS `cid`,
2141         `author`.`alias` AS `alias`,
2142         `author`.`photo` AS `photo`,
2143         `author`.`name-date` AS `name-date`,
2144         `author`.`uri-date` AS `uri-date`,
2145         `author`.`avatar-date` AS `avatar-date`,
2146         `author`.`thumb` AS `thumb`,
2147         `post`.`author-id` AS `author-id`,
2148         `author`.`uri-id` AS `author-uri-id`,
2149         `author`.`url` AS `author-link`,
2150         `author`.`addr` AS `author-addr`,
2151         `author`.`name` AS `author-name`,
2152         `author`.`nick` AS `author-nick`,
2153         `author`.`thumb` AS `author-avatar`,
2154         `author`.`network` AS `author-network`,
2155         `author`.`blocked` AS `author-blocked`,
2156         `author`.`hidden` AS `author-hidden`,
2157         `author`.`updated` AS `author-updated`,
2158         `author`.`gsid` AS `author-gsid`,
2159         `post`.`owner-id` AS `owner-id`,
2160         `owner`.`uri-id` AS `owner-uri-id`,
2161         `owner`.`url` AS `owner-link`,
2162         `owner`.`addr` AS `owner-addr`,
2163         `owner`.`name` AS `owner-name`,
2164         `owner`.`nick` AS `owner-nick`,
2165         `owner`.`thumb` AS `owner-avatar`,
2166         `owner`.`network` AS `owner-network`,
2167         `owner`.`blocked` AS `owner-blocked`,
2168         `owner`.`hidden` AS `owner-hidden`,
2169         `owner`.`updated` AS `owner-updated`,
2170         `owner`.`contact-type` AS `owner-contact-type`,
2171         `post`.`causer-id` AS `causer-id`,
2172         `causer`.`uri-id` AS `causer-uri-id`,
2173         `causer`.`url` AS `causer-link`,
2174         `causer`.`addr` AS `causer-addr`,
2175         `causer`.`name` AS `causer-name`,
2176         `causer`.`nick` AS `causer-nick`,
2177         `causer`.`thumb` AS `causer-avatar`,
2178         `causer`.`network` AS `causer-network`,
2179         `causer`.`blocked` AS `causer-blocked`,
2180         `causer`.`hidden` AS `causer-hidden`,
2181         `causer`.`contact-type` AS `causer-contact-type`,
2182         `post-question`.`id` AS `question-id`,
2183         `post-question`.`multiple` AS `question-multiple`,
2184         `post-question`.`voters` AS `question-voters`,
2185         `post-question`.`end-time` AS `question-end-time`,
2186         0 AS `has-categories`,
2187         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post`.`uri-id`) AS `has-media`,
2188         `diaspora-interaction`.`interaction` AS `signed_text`,
2189         `parent-item-uri`.`guid` AS `parent-guid`,
2190         `parent-post`.`network` AS `parent-network`,
2191         `parent-post`.`author-id` AS `parent-author-id`,
2192         `parent-post-author`.`url` AS `parent-author-link`,
2193         `parent-post-author`.`name` AS `parent-author-name`,
2194         `parent-post-author`.`network` AS `parent-author-network`,
2195         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2196         `parent-post-author`.`hidden` AS `parent-author-hidden`
2197         FROM `post`
2198                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2199                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2200                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2201                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2202                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2203                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2204                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2205                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2206                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2207                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2208                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2209                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
2210                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2211                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2212
2213 --
2214 -- VIEW post-thread-view
2215 --
2216 DROP VIEW IF EXISTS `post-thread-view`;
2217 CREATE VIEW `post-thread-view` AS SELECT 
2218         `item-uri`.`uri` AS `uri`,
2219         `post-thread`.`uri-id` AS `uri-id`,
2220         `parent-item-uri`.`uri` AS `parent-uri`,
2221         `post`.`parent-uri-id` AS `parent-uri-id`,
2222         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2223         `post`.`thr-parent-id` AS `thr-parent-id`,
2224         `item-uri`.`guid` AS `guid`,
2225         `post`.`gravity` AS `gravity`,
2226         `external-item-uri`.`uri` AS `extid`,
2227         `post`.`external-id` AS `external-id`,
2228         `post-thread`.`created` AS `created`,
2229         `post`.`edited` AS `edited`,
2230         `post-thread`.`commented` AS `commented`,
2231         `post-thread`.`received` AS `received`,
2232         `post-thread`.`changed` AS `changed`,
2233         `post`.`post-type` AS `post-type`,
2234         `post`.`private` AS `private`,
2235         `post`.`visible` AS `visible`,
2236         `post`.`deleted` AS `deleted`,
2237         `post`.`global` AS `global`,
2238         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
2239         `post-thread`.`network` AS `network`,
2240         `post`.`vid` AS `vid`,
2241         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2242         `post-content`.`title` AS `title`,
2243         `post-content`.`content-warning` AS `content-warning`,
2244         `post-content`.`raw-body` AS `raw-body`,
2245         `post-content`.`body` AS `body`,
2246         `post-content`.`rendered-hash` AS `rendered-hash`,
2247         `post-content`.`rendered-html` AS `rendered-html`,
2248         `post-content`.`language` AS `language`,
2249         `post-content`.`plink` AS `plink`,
2250         `post-content`.`location` AS `location`,
2251         `post-content`.`coord` AS `coord`,
2252         `post-content`.`app` AS `app`,
2253         `post-content`.`object-type` AS `object-type`,
2254         `post-content`.`object` AS `object`,
2255         `post-content`.`target-type` AS `target-type`,
2256         `post-content`.`target` AS `target`,
2257         `post-content`.`resource-id` AS `resource-id`,
2258         `post-thread`.`author-id` AS `contact-id`,
2259         `author`.`uri-id` AS `contact-uri-id`,
2260         `author`.`url` AS `contact-link`,
2261         `author`.`addr` AS `contact-addr`,
2262         `author`.`name` AS `contact-name`,
2263         `author`.`nick` AS `contact-nick`,
2264         `author`.`thumb` AS `contact-avatar`,
2265         `author`.`network` AS `contact-network`,
2266         `author`.`blocked` AS `contact-blocked`,
2267         `author`.`hidden` AS `contact-hidden`,
2268         `author`.`readonly` AS `contact-readonly`,
2269         `author`.`archive` AS `contact-archive`,
2270         `author`.`pending` AS `contact-pending`,
2271         `author`.`rel` AS `contact-rel`,
2272         `author`.`uid` AS `contact-uid`,
2273         `author`.`contact-type` AS `contact-contact-type`,
2274         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2275         false AS `self`,
2276         `author`.`id` AS `cid`,
2277         `author`.`alias` AS `alias`,
2278         `author`.`photo` AS `photo`,
2279         `author`.`name-date` AS `name-date`,
2280         `author`.`uri-date` AS `uri-date`,
2281         `author`.`avatar-date` AS `avatar-date`,
2282         `author`.`thumb` AS `thumb`,
2283         `post-thread`.`author-id` AS `author-id`,
2284         `author`.`uri-id` AS `author-uri-id`,
2285         `author`.`url` AS `author-link`,
2286         `author`.`addr` AS `author-addr`,
2287         `author`.`name` AS `author-name`,
2288         `author`.`nick` AS `author-nick`,
2289         `author`.`thumb` AS `author-avatar`,
2290         `author`.`network` AS `author-network`,
2291         `author`.`blocked` AS `author-blocked`,
2292         `author`.`hidden` AS `author-hidden`,
2293         `author`.`updated` AS `author-updated`,
2294         `author`.`gsid` AS `author-gsid`,
2295         `post-thread`.`owner-id` AS `owner-id`,
2296         `owner`.`uri-id` AS `owner-uri-id`,
2297         `owner`.`url` AS `owner-link`,
2298         `owner`.`addr` AS `owner-addr`,
2299         `owner`.`name` AS `owner-name`,
2300         `owner`.`nick` AS `owner-nick`,
2301         `owner`.`thumb` AS `owner-avatar`,
2302         `owner`.`network` AS `owner-network`,
2303         `owner`.`blocked` AS `owner-blocked`,
2304         `owner`.`hidden` AS `owner-hidden`,
2305         `owner`.`updated` AS `owner-updated`,
2306         `owner`.`contact-type` AS `owner-contact-type`,
2307         `post-thread`.`causer-id` AS `causer-id`,
2308         `causer`.`uri-id` AS `causer-uri-id`,
2309         `causer`.`url` AS `causer-link`,
2310         `causer`.`addr` AS `causer-addr`,
2311         `causer`.`name` AS `causer-name`,
2312         `causer`.`nick` AS `causer-nick`,
2313         `causer`.`thumb` AS `causer-avatar`,
2314         `causer`.`network` AS `causer-network`,
2315         `causer`.`blocked` AS `causer-blocked`,
2316         `causer`.`hidden` AS `causer-hidden`,
2317         `causer`.`contact-type` AS `causer-contact-type`,
2318         `post-question`.`id` AS `question-id`,
2319         `post-question`.`multiple` AS `question-multiple`,
2320         `post-question`.`voters` AS `question-voters`,
2321         `post-question`.`end-time` AS `question-end-time`,
2322         0 AS `has-categories`,
2323         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`) AS `has-media`,
2324         `diaspora-interaction`.`interaction` AS `signed_text`,
2325         `parent-item-uri`.`guid` AS `parent-guid`,
2326         `parent-post`.`network` AS `parent-network`,
2327         `parent-post`.`author-id` AS `parent-author-id`,
2328         `parent-post-author`.`url` AS `parent-author-link`,
2329         `parent-post-author`.`name` AS `parent-author-name`,
2330         `parent-post-author`.`network` AS `parent-author-network`,
2331         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2332         `parent-post-author`.`hidden` AS `parent-author-hidden`
2333         FROM `post-thread`
2334                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2335                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2336                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2337                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2338                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2339                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2340                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2341                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2342                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2343                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2344                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2345                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`
2346                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2347                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2348
2349 --
2350 -- VIEW category-view
2351 --
2352 DROP VIEW IF EXISTS `category-view`;
2353 CREATE VIEW `category-view` AS SELECT 
2354         `post-category`.`uri-id` AS `uri-id`,
2355         `post-category`.`uid` AS `uid`,
2356         `post-category`.`type` AS `type`,
2357         `post-category`.`tid` AS `tid`,
2358         `tag`.`name` AS `name`,
2359         `tag`.`url` AS `url`
2360         FROM `post-category`
2361                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2362
2363 --
2364 -- VIEW collection-view
2365 --
2366 DROP VIEW IF EXISTS `collection-view`;
2367 CREATE VIEW `collection-view` AS SELECT 
2368         `post-collection`.`uri-id` AS `uri-id`,
2369         `post-collection`.`type` AS `type`,
2370         `post`.`author-id` AS `cid`,
2371         `post`.`received` AS `received`,
2372         `post`.`created` AS `created`,
2373         `post-thread`.`commented` AS `commented`,
2374         `post`.`private` AS `private`,
2375         `post`.`visible` AS `visible`,
2376         `post`.`deleted` AS `deleted`,
2377         `post`.`thr-parent-id` AS `thr-parent-id`,
2378         `post`.`author-id` AS `author-id`,
2379         `post`.`gravity` AS `gravity`
2380         FROM `post-collection`
2381                         INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
2382                         INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`;
2383
2384 --
2385 -- VIEW tag-view
2386 --
2387 DROP VIEW IF EXISTS `tag-view`;
2388 CREATE VIEW `tag-view` AS SELECT 
2389         `post-tag`.`uri-id` AS `uri-id`,
2390         `post-tag`.`type` AS `type`,
2391         `post-tag`.`tid` AS `tid`,
2392         `post-tag`.`cid` AS `cid`,
2393         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2394         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`,
2395         CASE `cid` WHEN 0 THEN `tag`.`type` ELSE 1 END AS `tag-type`
2396         FROM `post-tag`
2397                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2398                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2399
2400 --
2401 -- VIEW network-item-view
2402 --
2403 DROP VIEW IF EXISTS `network-item-view`;
2404 CREATE VIEW `network-item-view` AS SELECT 
2405         `post-user`.`uri-id` AS `uri-id`,
2406         `parent-post`.`id` AS `parent`,
2407         `post-user`.`received` AS `received`,
2408         `post-thread-user`.`commented` AS `commented`,
2409         `post-user`.`created` AS `created`,
2410         `post-user`.`uid` AS `uid`,
2411         `post-thread-user`.`starred` AS `starred`,
2412         `post-thread-user`.`mention` AS `mention`,
2413         `post-user`.`network` AS `network`,
2414         `post-user`.`unseen` AS `unseen`,
2415         `post-user`.`gravity` AS `gravity`,
2416         `post-user`.`contact-id` AS `contact-id`,
2417         `ownercontact`.`contact-type` AS `contact-type`
2418         FROM `post-user`
2419                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2420                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2421                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2422                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2423                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2424                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2425                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2426                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2427                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2428                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2429                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2430
2431 --
2432 -- VIEW network-thread-view
2433 --
2434 DROP VIEW IF EXISTS `network-thread-view`;
2435 CREATE VIEW `network-thread-view` AS SELECT 
2436         `post-thread-user`.`uri-id` AS `uri-id`,
2437         `parent-post`.`id` AS `parent`,
2438         `post-thread-user`.`received` AS `received`,
2439         `post-thread-user`.`commented` AS `commented`,
2440         `post-thread-user`.`created` AS `created`,
2441         `post-thread-user`.`uid` AS `uid`,
2442         `post-thread-user`.`starred` AS `starred`,
2443         `post-thread-user`.`mention` AS `mention`,
2444         `post-thread-user`.`network` AS `network`,
2445         `post-thread-user`.`contact-id` AS `contact-id`,
2446         `ownercontact`.`contact-type` AS `contact-type`
2447         FROM `post-thread-user`
2448                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2449                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2450                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2451                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2452                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2453                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2454                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2455                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2456                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2457                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2458                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2459
2460 --
2461 -- VIEW owner-view
2462 --
2463 DROP VIEW IF EXISTS `owner-view`;
2464 CREATE VIEW `owner-view` AS SELECT 
2465         `contact`.`id` AS `id`,
2466         `contact`.`uid` AS `uid`,
2467         `contact`.`created` AS `created`,
2468         `contact`.`updated` AS `updated`,
2469         `contact`.`self` AS `self`,
2470         `contact`.`remote_self` AS `remote_self`,
2471         `contact`.`rel` AS `rel`,
2472         `contact`.`network` AS `network`,
2473         `contact`.`protocol` AS `protocol`,
2474         `contact`.`name` AS `name`,
2475         `contact`.`nick` AS `nick`,
2476         `contact`.`location` AS `location`,
2477         `contact`.`about` AS `about`,
2478         `contact`.`keywords` AS `keywords`,
2479         `contact`.`xmpp` AS `xmpp`,
2480         `contact`.`matrix` AS `matrix`,
2481         `contact`.`attag` AS `attag`,
2482         `contact`.`avatar` AS `avatar`,
2483         `contact`.`photo` AS `photo`,
2484         `contact`.`thumb` AS `thumb`,
2485         `contact`.`micro` AS `micro`,
2486         `contact`.`header` AS `header`,
2487         `contact`.`url` AS `url`,
2488         `contact`.`nurl` AS `nurl`,
2489         `contact`.`uri-id` AS `uri-id`,
2490         `contact`.`addr` AS `addr`,
2491         `contact`.`alias` AS `alias`,
2492         `contact`.`pubkey` AS `pubkey`,
2493         `contact`.`prvkey` AS `prvkey`,
2494         `contact`.`batch` AS `batch`,
2495         `contact`.`request` AS `request`,
2496         `contact`.`notify` AS `notify`,
2497         `contact`.`poll` AS `poll`,
2498         `contact`.`confirm` AS `confirm`,
2499         `contact`.`poco` AS `poco`,
2500         `contact`.`subhub` AS `subhub`,
2501         `contact`.`hub-verify` AS `hub-verify`,
2502         `contact`.`last-update` AS `last-update`,
2503         `contact`.`success_update` AS `success_update`,
2504         `contact`.`failure_update` AS `failure_update`,
2505         `contact`.`name-date` AS `name-date`,
2506         `contact`.`uri-date` AS `uri-date`,
2507         `contact`.`avatar-date` AS `avatar-date`,
2508         `contact`.`avatar-date` AS `picdate`,
2509         `contact`.`term-date` AS `term-date`,
2510         `contact`.`last-item` AS `last-item`,
2511         `contact`.`priority` AS `priority`,
2512         `user`.`blocked` AS `blocked`,
2513         `contact`.`block_reason` AS `block_reason`,
2514         `contact`.`readonly` AS `readonly`,
2515         `contact`.`writable` AS `writable`,
2516         `contact`.`forum` AS `forum`,
2517         `contact`.`prv` AS `prv`,
2518         `contact`.`contact-type` AS `contact-type`,
2519         `contact`.`manually-approve` AS `manually-approve`,
2520         `contact`.`hidden` AS `hidden`,
2521         `contact`.`archive` AS `archive`,
2522         `contact`.`pending` AS `pending`,
2523         `contact`.`deleted` AS `deleted`,
2524         `contact`.`unsearchable` AS `unsearchable`,
2525         `contact`.`sensitive` AS `sensitive`,
2526         `contact`.`baseurl` AS `baseurl`,
2527         `contact`.`reason` AS `reason`,
2528         `contact`.`info` AS `info`,
2529         `contact`.`bdyear` AS `bdyear`,
2530         `contact`.`bd` AS `bd`,
2531         `contact`.`notify_new_posts` AS `notify_new_posts`,
2532         `contact`.`fetch_further_information` AS `fetch_further_information`,
2533         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2534         `user`.`parent-uid` AS `parent-uid`,
2535         `user`.`guid` AS `guid`,
2536         `user`.`nickname` AS `nickname`,
2537         `user`.`email` AS `email`,
2538         `user`.`openid` AS `openid`,
2539         `user`.`timezone` AS `timezone`,
2540         `user`.`language` AS `language`,
2541         `user`.`register_date` AS `register_date`,
2542         `user`.`login_date` AS `login_date`,
2543         `user`.`default-location` AS `default-location`,
2544         `user`.`allow_location` AS `allow_location`,
2545         `user`.`theme` AS `theme`,
2546         `user`.`pubkey` AS `upubkey`,
2547         `user`.`prvkey` AS `uprvkey`,
2548         `user`.`sprvkey` AS `sprvkey`,
2549         `user`.`spubkey` AS `spubkey`,
2550         `user`.`verified` AS `verified`,
2551         `user`.`blockwall` AS `blockwall`,
2552         `user`.`hidewall` AS `hidewall`,
2553         `user`.`blocktags` AS `blocktags`,
2554         `user`.`unkmail` AS `unkmail`,
2555         `user`.`cntunkmail` AS `cntunkmail`,
2556         `user`.`notify-flags` AS `notify-flags`,
2557         `user`.`page-flags` AS `page-flags`,
2558         `user`.`account-type` AS `account-type`,
2559         `user`.`prvnets` AS `prvnets`,
2560         `user`.`maxreq` AS `maxreq`,
2561         `user`.`expire` AS `expire`,
2562         `user`.`account_removed` AS `account_removed`,
2563         `user`.`account_expired` AS `account_expired`,
2564         `user`.`account_expires_on` AS `account_expires_on`,
2565         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2566         `user`.`def_gid` AS `def_gid`,
2567         `user`.`allow_cid` AS `allow_cid`,
2568         `user`.`allow_gid` AS `allow_gid`,
2569         `user`.`deny_cid` AS `deny_cid`,
2570         `user`.`deny_gid` AS `deny_gid`,
2571         `user`.`openidserver` AS `openidserver`,
2572         `profile`.`publish` AS `publish`,
2573         `profile`.`net-publish` AS `net-publish`,
2574         `profile`.`hide-friends` AS `hide-friends`,
2575         `profile`.`prv_keywords` AS `prv_keywords`,
2576         `profile`.`pub_keywords` AS `pub_keywords`,
2577         `profile`.`address` AS `address`,
2578         `profile`.`locality` AS `locality`,
2579         `profile`.`region` AS `region`,
2580         `profile`.`postal-code` AS `postal-code`,
2581         `profile`.`country-name` AS `country-name`,
2582         `profile`.`homepage` AS `homepage`,
2583         `profile`.`dob` AS `dob`
2584         FROM `user`
2585                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2586                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2587
2588 --
2589 -- VIEW account-view
2590 --
2591 DROP VIEW IF EXISTS `account-view`;
2592 CREATE VIEW `account-view` AS SELECT 
2593         `contact`.`id` AS `id`,
2594         `contact`.`url` AS `url`,
2595         `contact`.`nurl` AS `nurl`,
2596         `contact`.`uri-id` AS `uri-id`,
2597         `item-uri`.`guid` AS `guid`,
2598         `contact`.`addr` AS `addr`,
2599         `contact`.`alias` AS `alias`,
2600         `contact`.`name` AS `name`,
2601         `contact`.`nick` AS `nick`,
2602         `contact`.`about` AS `about`,
2603         `contact`.`keywords` AS `keywords`,
2604         `contact`.`xmpp` AS `xmpp`,
2605         `contact`.`matrix` AS `matrix`,
2606         `contact`.`avatar` AS `avatar`,
2607         `contact`.`photo` AS `photo`,
2608         `contact`.`thumb` AS `thumb`,
2609         `contact`.`micro` AS `micro`,
2610         `contact`.`header` AS `header`,
2611         `contact`.`created` AS `created`,
2612         `contact`.`updated` AS `updated`,
2613         `contact`.`network` AS `network`,
2614         `contact`.`protocol` AS `protocol`,
2615         `contact`.`location` AS `location`,
2616         `contact`.`attag` AS `attag`,
2617         `contact`.`pubkey` AS `pubkey`,
2618         `contact`.`prvkey` AS `prvkey`,
2619         `contact`.`subscribe` AS `subscribe`,
2620         `contact`.`last-update` AS `last-update`,
2621         `contact`.`success_update` AS `success_update`,
2622         `contact`.`failure_update` AS `failure_update`,
2623         `contact`.`failed` AS `failed`,
2624         `contact`.`last-item` AS `last-item`,
2625         `contact`.`last-discovery` AS `last-discovery`,
2626         `contact`.`contact-type` AS `contact-type`,
2627         `contact`.`manually-approve` AS `manually-approve`,
2628         `contact`.`unsearchable` AS `unsearchable`,
2629         `contact`.`sensitive` AS `sensitive`,
2630         `contact`.`baseurl` AS `baseurl`,
2631         `contact`.`gsid` AS `gsid`,
2632         `contact`.`info` AS `info`,
2633         `contact`.`bdyear` AS `bdyear`,
2634         `contact`.`bd` AS `bd`,
2635         `contact`.`poco` AS `poco`,
2636         `contact`.`name-date` AS `name-date`,
2637         `contact`.`uri-date` AS `uri-date`,
2638         `contact`.`avatar-date` AS `avatar-date`,
2639         `contact`.`term-date` AS `term-date`,
2640         `contact`.`hidden` AS `global-ignored`,
2641         `contact`.`blocked` AS `global-blocked`,
2642         `contact`.`hidden` AS `hidden`,
2643         `contact`.`archive` AS `archive`,
2644         `contact`.`deleted` AS `deleted`,
2645         `contact`.`blocked` AS `blocked`,
2646         `contact`.`notify` AS `dfrn-notify`,
2647         `contact`.`poll` AS `dfrn-poll`,
2648         `fcontact`.`guid` AS `diaspora-guid`,
2649         `fcontact`.`batch` AS `diaspora-batch`,
2650         `fcontact`.`notify` AS `diaspora-notify`,
2651         `fcontact`.`poll` AS `diaspora-poll`,
2652         `fcontact`.`alias` AS `diaspora-alias`,
2653         `apcontact`.`uuid` AS `ap-uuid`,
2654         `apcontact`.`type` AS `ap-type`,
2655         `apcontact`.`following` AS `ap-following`,
2656         `apcontact`.`followers` AS `ap-followers`,
2657         `apcontact`.`inbox` AS `ap-inbox`,
2658         `apcontact`.`outbox` AS `ap-outbox`,
2659         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2660         `apcontact`.`generator` AS `ap-generator`,
2661         `apcontact`.`following_count` AS `ap-following_count`,
2662         `apcontact`.`followers_count` AS `ap-followers_count`,
2663         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2664         `gserver`.`site_name` AS `site_name`,
2665         `gserver`.`platform` AS `platform`,
2666         `gserver`.`version` AS `version`
2667         FROM `contact`
2668                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
2669                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
2670                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
2671                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`
2672                         WHERE `contact`.`uid` = 0;
2673
2674 --
2675 -- VIEW account-user-view
2676 --
2677 DROP VIEW IF EXISTS `account-user-view`;
2678 CREATE VIEW `account-user-view` AS SELECT 
2679         `ucontact`.`id` AS `id`,
2680         `contact`.`id` AS `pid`,
2681         `ucontact`.`uid` AS `uid`,
2682         `contact`.`url` AS `url`,
2683         `contact`.`nurl` AS `nurl`,
2684         `contact`.`uri-id` AS `uri-id`,
2685         `item-uri`.`guid` AS `guid`,
2686         `contact`.`addr` AS `addr`,
2687         `contact`.`alias` AS `alias`,
2688         `contact`.`name` AS `name`,
2689         `contact`.`nick` AS `nick`,
2690         `contact`.`about` AS `about`,
2691         `contact`.`keywords` AS `keywords`,
2692         `contact`.`xmpp` AS `xmpp`,
2693         `contact`.`matrix` AS `matrix`,
2694         `contact`.`avatar` AS `avatar`,
2695         `contact`.`photo` AS `photo`,
2696         `contact`.`thumb` AS `thumb`,
2697         `contact`.`micro` AS `micro`,
2698         `contact`.`header` AS `header`,
2699         `contact`.`created` AS `created`,
2700         `contact`.`updated` AS `updated`,
2701         `ucontact`.`self` AS `self`,
2702         `ucontact`.`remote_self` AS `remote_self`,
2703         `ucontact`.`rel` AS `rel`,
2704         `contact`.`network` AS `network`,
2705         `ucontact`.`protocol` AS `protocol`,
2706         `contact`.`location` AS `location`,
2707         `ucontact`.`attag` AS `attag`,
2708         `contact`.`pubkey` AS `pubkey`,
2709         `contact`.`prvkey` AS `prvkey`,
2710         `contact`.`subscribe` AS `subscribe`,
2711         `contact`.`last-update` AS `last-update`,
2712         `contact`.`success_update` AS `success_update`,
2713         `contact`.`failure_update` AS `failure_update`,
2714         `contact`.`failed` AS `failed`,
2715         `contact`.`last-item` AS `last-item`,
2716         `contact`.`last-discovery` AS `last-discovery`,
2717         `contact`.`contact-type` AS `contact-type`,
2718         `contact`.`manually-approve` AS `manually-approve`,
2719         `contact`.`unsearchable` AS `unsearchable`,
2720         `contact`.`sensitive` AS `sensitive`,
2721         `contact`.`baseurl` AS `baseurl`,
2722         `contact`.`gsid` AS `gsid`,
2723         `ucontact`.`info` AS `info`,
2724         `contact`.`bdyear` AS `bdyear`,
2725         `contact`.`bd` AS `bd`,
2726         `contact`.`poco` AS `poco`,
2727         `contact`.`name-date` AS `name-date`,
2728         `contact`.`uri-date` AS `uri-date`,
2729         `contact`.`avatar-date` AS `avatar-date`,
2730         `contact`.`term-date` AS `term-date`,
2731         `contact`.`hidden` AS `global-ignored`,
2732         `contact`.`blocked` AS `global-blocked`,
2733         `ucontact`.`hidden` AS `hidden`,
2734         `ucontact`.`archive` AS `archive`,
2735         `ucontact`.`pending` AS `pending`,
2736         `ucontact`.`deleted` AS `deleted`,
2737         `ucontact`.`notify_new_posts` AS `notify_new_posts`,
2738         `ucontact`.`fetch_further_information` AS `fetch_further_information`,
2739         `ucontact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2740         `ucontact`.`rating` AS `rating`,
2741         `ucontact`.`readonly` AS `readonly`,
2742         `ucontact`.`blocked` AS `blocked`,
2743         `ucontact`.`block_reason` AS `block_reason`,
2744         `ucontact`.`subhub` AS `subhub`,
2745         `ucontact`.`hub-verify` AS `hub-verify`,
2746         `ucontact`.`reason` AS `reason`,
2747         `contact`.`notify` AS `dfrn-notify`,
2748         `contact`.`poll` AS `dfrn-poll`,
2749         `fcontact`.`guid` AS `diaspora-guid`,
2750         `fcontact`.`batch` AS `diaspora-batch`,
2751         `fcontact`.`notify` AS `diaspora-notify`,
2752         `fcontact`.`poll` AS `diaspora-poll`,
2753         `fcontact`.`alias` AS `diaspora-alias`,
2754         `fcontact`.`interacting_count` AS `diaspora-interacting_count`,
2755         `fcontact`.`interacted_count` AS `diaspora-interacted_count`,
2756         `fcontact`.`post_count` AS `diaspora-post_count`,
2757         `apcontact`.`uuid` AS `ap-uuid`,
2758         `apcontact`.`type` AS `ap-type`,
2759         `apcontact`.`following` AS `ap-following`,
2760         `apcontact`.`followers` AS `ap-followers`,
2761         `apcontact`.`inbox` AS `ap-inbox`,
2762         `apcontact`.`outbox` AS `ap-outbox`,
2763         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2764         `apcontact`.`generator` AS `ap-generator`,
2765         `apcontact`.`following_count` AS `ap-following_count`,
2766         `apcontact`.`followers_count` AS `ap-followers_count`,
2767         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2768         `gserver`.`site_name` AS `site_name`,
2769         `gserver`.`platform` AS `platform`,
2770         `gserver`.`version` AS `version`
2771         FROM `contact` AS `ucontact`
2772                         INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
2773                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
2774                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
2775                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr'
2776                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`;
2777
2778 --
2779 -- VIEW pending-view
2780 --
2781 DROP VIEW IF EXISTS `pending-view`;
2782 CREATE VIEW `pending-view` AS SELECT 
2783         `register`.`id` AS `id`,
2784         `register`.`hash` AS `hash`,
2785         `register`.`created` AS `created`,
2786         `register`.`uid` AS `uid`,
2787         `register`.`password` AS `password`,
2788         `register`.`language` AS `language`,
2789         `register`.`note` AS `note`,
2790         `contact`.`self` AS `self`,
2791         `contact`.`name` AS `name`,
2792         `contact`.`url` AS `url`,
2793         `contact`.`micro` AS `micro`,
2794         `user`.`email` AS `email`,
2795         `contact`.`nick` AS `nick`
2796         FROM `register`
2797                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2798                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2799
2800 --
2801 -- VIEW tag-search-view
2802 --
2803 DROP VIEW IF EXISTS `tag-search-view`;
2804 CREATE VIEW `tag-search-view` AS SELECT 
2805         `post-tag`.`uri-id` AS `uri-id`,
2806         `post-user`.`uid` AS `uid`,
2807         `post-user`.`id` AS `iid`,
2808         `post-user`.`private` AS `private`,
2809         `post-user`.`wall` AS `wall`,
2810         `post-user`.`origin` AS `origin`,
2811         `post-user`.`global` AS `global`,
2812         `post-user`.`gravity` AS `gravity`,
2813         `post-user`.`received` AS `received`,
2814         `post-user`.`network` AS `network`,
2815         `post-user`.`author-id` AS `author-id`,
2816         `tag`.`name` AS `name`
2817         FROM `post-tag`
2818                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2819                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2820                         WHERE `post-tag`.`type` = 1;
2821
2822 --
2823 -- VIEW workerqueue-view
2824 --
2825 DROP VIEW IF EXISTS `workerqueue-view`;
2826 CREATE VIEW `workerqueue-view` AS SELECT 
2827         `process`.`pid` AS `pid`,
2828         `workerqueue`.`priority` AS `priority`
2829         FROM `process`
2830                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2831                         WHERE NOT `workerqueue`.`done`;
2832
2833 --
2834 -- VIEW profile_field-view
2835 --
2836 DROP VIEW IF EXISTS `profile_field-view`;
2837 CREATE VIEW `profile_field-view` AS SELECT 
2838         `profile_field`.`id` AS `id`,
2839         `profile_field`.`uid` AS `uid`,
2840         `profile_field`.`label` AS `label`,
2841         `profile_field`.`value` AS `value`,
2842         `profile_field`.`order` AS `order`,
2843         `profile_field`.`psid` AS `psid`,
2844         `permissionset`.`allow_cid` AS `allow_cid`,
2845         `permissionset`.`allow_gid` AS `allow_gid`,
2846         `permissionset`.`deny_cid` AS `deny_cid`,
2847         `permissionset`.`deny_gid` AS `deny_gid`,
2848         `profile_field`.`created` AS `created`,
2849         `profile_field`.`edited` AS `edited`
2850         FROM `profile_field`
2851                         INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`;