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