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