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