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