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