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