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