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