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