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