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