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