]> git.mxchange.org Git - friendica.git/blob - database.sql
API: Added trending links
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2022.12-dev (Giant Rhubarb)
3 -- DB_UPDATE_VERSION 1492
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 'Delay in days before deleting user-related posts. Scope is controlled by pConfig.',
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         `quote-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the quoted uri',
1190         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1191         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1192         `language` text COMMENT 'Language information about this post',
1193         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1194         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1195         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1196         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1197         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1198         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1199         `target` text COMMENT 'JSON encoded target structure if used',
1200         `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',
1201         `plink` varbinary(383) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1202          PRIMARY KEY(`uri-id`),
1203          INDEX `plink` (`plink`(191)),
1204          INDEX `resource-id` (`resource-id`),
1205          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1206          INDEX `quote-uri-id` (`quote-uri-id`),
1207         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1208         FOREIGN KEY (`quote-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1209 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1210
1211 --
1212 -- TABLE post-delivery
1213 --
1214 CREATE TABLE IF NOT EXISTS `post-delivery` (
1215         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1216         `inbox-id` int unsigned NOT NULL COMMENT 'Item-uri id of inbox url',
1217         `uid` mediumint unsigned COMMENT 'Delivering user',
1218         `created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
1219         `command` varbinary(32) COMMENT '',
1220         `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
1221         `receivers` mediumtext COMMENT 'JSON encoded array with the receiving contacts',
1222          PRIMARY KEY(`uri-id`,`inbox-id`),
1223          INDEX `inbox-id_created` (`inbox-id`,`created`),
1224          INDEX `uid` (`uid`),
1225         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1226         FOREIGN KEY (`inbox-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1227         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1228 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for posts for the batch processing';
1229
1230 --
1231 -- TABLE post-delivery-data
1232 --
1233 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1234         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1235         `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',
1236         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1237         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1238         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1239         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1240         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1241         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1242         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1243         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1244         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1245          PRIMARY KEY(`uri-id`),
1246         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1247 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1248
1249 --
1250 -- TABLE post-history
1251 --
1252 CREATE TABLE IF NOT EXISTS `post-history` (
1253         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1254         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of edit',
1255         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1256         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1257         `body` mediumtext COMMENT 'item body content',
1258         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1259         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1260         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1261         `language` text COMMENT 'Language information about this post',
1262         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1263         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1264         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1265         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1266         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1267         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1268         `target` text COMMENT 'JSON encoded target structure if used',
1269         `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',
1270         `plink` varbinary(383) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1271          PRIMARY KEY(`uri-id`,`edited`),
1272         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1273 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post history';
1274
1275 --
1276 -- TABLE post-link
1277 --
1278 CREATE TABLE IF NOT EXISTS `post-link` (
1279         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1280         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1281         `url` varbinary(511) NOT NULL COMMENT 'External URL',
1282         `mimetype` varchar(60) COMMENT '',
1283          PRIMARY KEY(`id`),
1284          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1285         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1286 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post related external links';
1287
1288 --
1289 -- TABLE post-media
1290 --
1291 CREATE TABLE IF NOT EXISTS `post-media` (
1292         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1293         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1294         `url` varbinary(1024) NOT NULL COMMENT 'Media URL',
1295         `media-uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the activities uri-id',
1296         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1297         `mimetype` varchar(60) COMMENT '',
1298         `height` smallint unsigned COMMENT 'Height of the media',
1299         `width` smallint unsigned COMMENT 'Width of the media',
1300         `size` bigint unsigned COMMENT 'Media size',
1301         `preview` varbinary(512) COMMENT 'Preview URL',
1302         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1303         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1304         `description` text COMMENT '',
1305         `name` varchar(255) COMMENT 'Name of the media',
1306         `author-url` varbinary(383) COMMENT 'URL of the author of the media',
1307         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1308         `author-image` varbinary(383) COMMENT 'Image of the author of the media',
1309         `publisher-url` varbinary(383) COMMENT 'URL of the publisher of the media',
1310         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1311         `publisher-image` varbinary(383) COMMENT 'Image of the publisher of the media',
1312          PRIMARY KEY(`id`),
1313          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`(512)),
1314          INDEX `uri-id-id` (`uri-id`,`id`),
1315          INDEX `media-uri-id` (`media-uri-id`),
1316         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1317         FOREIGN KEY (`media-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1318 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1319
1320 --
1321 -- TABLE post-question
1322 --
1323 CREATE TABLE IF NOT EXISTS `post-question` (
1324         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1325         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1326         `multiple` boolean NOT NULL DEFAULT '0' COMMENT 'Multiple choice',
1327         `voters` int unsigned COMMENT 'Number of voters for this question',
1328         `end-time` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Question end time',
1329          PRIMARY KEY(`id`),
1330          UNIQUE INDEX `uri-id` (`uri-id`),
1331         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1332 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question';
1333
1334 --
1335 -- TABLE post-question-option
1336 --
1337 CREATE TABLE IF NOT EXISTS `post-question-option` (
1338         `id` int unsigned NOT NULL COMMENT 'Id of the question',
1339         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1340         `name` varchar(255) COMMENT 'Name of the option',
1341         `replies` int unsigned COMMENT 'Number of replies for this question option',
1342          PRIMARY KEY(`uri-id`,`id`),
1343         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1344 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question option';
1345
1346 --
1347 -- TABLE post-tag
1348 --
1349 CREATE TABLE IF NOT EXISTS `post-tag` (
1350         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1351         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1352         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1353         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1354          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1355          INDEX `tid` (`tid`),
1356          INDEX `cid` (`cid`),
1357         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1358         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1359         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1360 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1361
1362 --
1363 -- TABLE post-thread
1364 --
1365 CREATE TABLE IF NOT EXISTS `post-thread` (
1366         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1367         `conversation-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the conversation uri',
1368         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1369         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1370         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1371         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1372         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1373         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1374         `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',
1375         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1376          PRIMARY KEY(`uri-id`),
1377          INDEX `conversation-id` (`conversation-id`),
1378          INDEX `owner-id` (`owner-id`),
1379          INDEX `author-id` (`author-id`),
1380          INDEX `causer-id` (`causer-id`),
1381          INDEX `received` (`received`),
1382          INDEX `commented` (`commented`),
1383         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1384         FOREIGN KEY (`conversation-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1385         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1386         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1387         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1388 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1389
1390 --
1391 -- TABLE post-user
1392 --
1393 CREATE TABLE IF NOT EXISTS `post-user` (
1394         `id` int unsigned NOT NULL auto_increment,
1395         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1396         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1397         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1398         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1399         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1400         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1401         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1402         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1403         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1404         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1405         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1406         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1407         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1408         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1409         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1410         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1411         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1412         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1413         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1414         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1415         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1416         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1417         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1418         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1419         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1420         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1421         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1422         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1423         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1424          PRIMARY KEY(`id`),
1425          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1426          INDEX `uri-id` (`uri-id`),
1427          INDEX `parent-uri-id` (`parent-uri-id`),
1428          INDEX `thr-parent-id` (`thr-parent-id`),
1429          INDEX `external-id` (`external-id`),
1430          INDEX `owner-id` (`owner-id`),
1431          INDEX `author-id` (`author-id`),
1432          INDEX `causer-id` (`causer-id`),
1433          INDEX `vid` (`vid`),
1434          INDEX `contact-id` (`contact-id`),
1435          INDEX `event-id` (`event-id`),
1436          INDEX `psid` (`psid`),
1437          INDEX `author-id_uid` (`author-id`,`uid`),
1438          INDEX `author-id_received` (`author-id`,`received`),
1439          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1440          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1441          INDEX `uid_contactid` (`uid`,`contact-id`),
1442          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1443          INDEX `uid_unseen` (`uid`,`unseen`),
1444          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1445         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1446         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1447         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1448         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1449         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1450         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1451         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1452         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1453         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1454         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1455         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1456         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1457 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1458
1459 --
1460 -- TABLE post-thread-user
1461 --
1462 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1463         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1464         `conversation-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the conversation uri',
1465         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1466         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1467         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1468         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1469         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1470         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1471         `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',
1472         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1473         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1474         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'deprecated',
1475         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1476         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1477         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1478         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1479         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1480         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Deprecated',
1481         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1482         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1483         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1484         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1485         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1486         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1487          PRIMARY KEY(`uid`,`uri-id`),
1488          INDEX `uri-id` (`uri-id`),
1489          INDEX `conversation-id` (`conversation-id`),
1490          INDEX `owner-id` (`owner-id`),
1491          INDEX `author-id` (`author-id`),
1492          INDEX `causer-id` (`causer-id`),
1493          INDEX `uid` (`uid`),
1494          INDEX `contact-id` (`contact-id`),
1495          INDEX `psid` (`psid`),
1496          INDEX `post-user-id` (`post-user-id`),
1497          INDEX `commented` (`commented`),
1498          INDEX `uid_received` (`uid`,`received`),
1499          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1500          INDEX `uid_commented` (`uid`,`commented`),
1501          INDEX `uid_starred` (`uid`,`starred`),
1502          INDEX `uid_mention` (`uid`,`mention`),
1503         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1504         FOREIGN KEY (`conversation-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1505         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1506         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1507         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1508         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1509         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1510         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1511         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1512 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1513
1514 --
1515 -- TABLE post-user-notification
1516 --
1517 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1518         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1519         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1520         `notification-type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1521          PRIMARY KEY(`uid`,`uri-id`),
1522          INDEX `uri-id` (`uri-id`),
1523         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1524         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1525 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1526
1527 --
1528 -- TABLE process
1529 --
1530 CREATE TABLE IF NOT EXISTS `process` (
1531         `pid` int unsigned NOT NULL COMMENT 'The ID of the process',
1532         `hostname` varchar(32) NOT NULL COMMENT 'The name of the host the process is ran on',
1533         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1534         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1535          PRIMARY KEY(`pid`,`hostname`),
1536          INDEX `command` (`command`)
1537 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1538
1539 --
1540 -- TABLE profile
1541 --
1542 CREATE TABLE IF NOT EXISTS `profile` (
1543         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1544         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1545         `profile-name` varchar(255) COMMENT 'Deprecated',
1546         `is-default` boolean COMMENT 'Deprecated',
1547         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1548         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1549         `pdesc` varchar(255) COMMENT 'Deprecated',
1550         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1551         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1552         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1553         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1554         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1555         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1556         `hometown` varchar(255) COMMENT 'Deprecated',
1557         `gender` varchar(32) COMMENT 'Deprecated',
1558         `marital` varchar(255) COMMENT 'Deprecated',
1559         `with` text COMMENT 'Deprecated',
1560         `howlong` datetime COMMENT 'Deprecated',
1561         `sexual` varchar(255) COMMENT 'Deprecated',
1562         `politic` varchar(255) COMMENT 'Deprecated',
1563         `religion` varchar(255) COMMENT 'Deprecated',
1564         `pub_keywords` text COMMENT '',
1565         `prv_keywords` text COMMENT '',
1566         `likes` text COMMENT 'Deprecated',
1567         `dislikes` text COMMENT 'Deprecated',
1568         `about` text COMMENT 'Profile description',
1569         `summary` varchar(255) COMMENT 'Deprecated',
1570         `music` text COMMENT 'Deprecated',
1571         `book` text COMMENT 'Deprecated',
1572         `tv` text COMMENT 'Deprecated',
1573         `film` text COMMENT 'Deprecated',
1574         `interest` text COMMENT 'Deprecated',
1575         `romance` text COMMENT 'Deprecated',
1576         `work` text COMMENT 'Deprecated',
1577         `education` text COMMENT 'Deprecated',
1578         `contact` text COMMENT 'Deprecated',
1579         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1580         `homepage_verified` boolean NOT NULL DEFAULT '0' COMMENT 'was the homepage verified by a rel-me link back to the profile',
1581         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
1582         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
1583         `photo` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1584         `thumb` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1585         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1586         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1587          PRIMARY KEY(`id`),
1588          INDEX `uid_is-default` (`uid`,`is-default`),
1589          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1590         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1591 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1592
1593 --
1594 -- TABLE profile_field
1595 --
1596 CREATE TABLE IF NOT EXISTS `profile_field` (
1597         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1598         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1599         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1600         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1601         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1602         `value` text COMMENT 'Value of the field',
1603         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1604         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1605          PRIMARY KEY(`id`),
1606          INDEX `uid` (`uid`),
1607          INDEX `order` (`order`),
1608          INDEX `psid` (`psid`),
1609         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1610         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1611 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1612
1613 --
1614 -- TABLE push_subscriber
1615 --
1616 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1617         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1618         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1619         `callback_url` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1620         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1621         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1622         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1623         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1624         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1625         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1626         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1627          PRIMARY KEY(`id`),
1628          INDEX `next_try` (`next_try`),
1629          INDEX `uid` (`uid`),
1630         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1631 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1632
1633 --
1634 -- TABLE register
1635 --
1636 CREATE TABLE IF NOT EXISTS `register` (
1637         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1638         `hash` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1639         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1640         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1641         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1642         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1643         `note` text COMMENT '',
1644          PRIMARY KEY(`id`),
1645          INDEX `uid` (`uid`),
1646         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1647 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1648
1649 --
1650 -- TABLE report
1651 --
1652 CREATE TABLE IF NOT EXISTS `report` (
1653         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1654         `uid` mediumint unsigned COMMENT 'Reporting user',
1655         `cid` int unsigned NOT NULL COMMENT 'Reported contact',
1656         `comment` text COMMENT 'Report',
1657         `forward` boolean COMMENT 'Forward the report to the remote server',
1658         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1659          PRIMARY KEY(`id`),
1660          INDEX `uid` (`uid`),
1661          INDEX `cid` (`cid`),
1662         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1663         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1664 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1665
1666 --
1667 -- TABLE report-post
1668 --
1669 CREATE TABLE IF NOT EXISTS `report-post` (
1670         `rid` int unsigned NOT NULL COMMENT 'Report id',
1671         `uri-id` int unsigned NOT NULL COMMENT 'Uri-id of the reported post',
1672          PRIMARY KEY(`rid`,`uri-id`),
1673          INDEX `uri-id` (`uri-id`),
1674         FOREIGN KEY (`rid`) REFERENCES `report` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1675         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1676 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1677
1678 --
1679 -- TABLE search
1680 --
1681 CREATE TABLE IF NOT EXISTS `search` (
1682         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1683         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1684         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1685          PRIMARY KEY(`id`),
1686          INDEX `uid_term` (`uid`,`term`(64)),
1687          INDEX `term` (`term`(64)),
1688         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1689 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1690
1691 --
1692 -- TABLE session
1693 --
1694 CREATE TABLE IF NOT EXISTS `session` (
1695         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1696         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1697         `data` text COMMENT '',
1698         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1699          PRIMARY KEY(`id`),
1700          INDEX `sid` (`sid`(64)),
1701          INDEX `expire` (`expire`)
1702 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1703
1704 --
1705 -- TABLE storage
1706 --
1707 CREATE TABLE IF NOT EXISTS `storage` (
1708         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1709         `data` longblob NOT NULL COMMENT 'file data',
1710          PRIMARY KEY(`id`)
1711 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1712
1713 --
1714 -- TABLE subscription
1715 --
1716 CREATE TABLE IF NOT EXISTS `subscription` (
1717         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1718         `application-id` int unsigned NOT NULL COMMENT '',
1719         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
1720         `endpoint` varchar(511) COMMENT 'Endpoint URL',
1721         `pubkey` varchar(127) COMMENT 'User agent public key',
1722         `secret` varchar(32) COMMENT 'Auth secret',
1723         `follow` boolean COMMENT '',
1724         `favourite` boolean COMMENT '',
1725         `reblog` boolean COMMENT '',
1726         `mention` boolean COMMENT '',
1727         `poll` boolean COMMENT '',
1728         `follow_request` boolean COMMENT '',
1729         `status` boolean COMMENT '',
1730          PRIMARY KEY(`id`),
1731          UNIQUE INDEX `application-id_uid` (`application-id`,`uid`),
1732          INDEX `uid_application-id` (`uid`,`application-id`),
1733         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1734         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1735 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Push Subscription for the API';
1736
1737 --
1738 -- TABLE userd
1739 --
1740 CREATE TABLE IF NOT EXISTS `userd` (
1741         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1742         `username` varchar(255) NOT NULL COMMENT '',
1743          PRIMARY KEY(`id`),
1744          INDEX `username` (`username`(32))
1745 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1746
1747 --
1748 -- TABLE user-contact
1749 --
1750 CREATE TABLE IF NOT EXISTS `user-contact` (
1751         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1752         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1753         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
1754         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1755         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1756         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1757         `hidden` boolean COMMENT 'This contact is hidden from the others',
1758         `is-blocked` boolean COMMENT 'User is blocked by this contact',
1759         `pending` boolean COMMENT '',
1760         `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
1761         `info` mediumtext COMMENT '',
1762         `notify_new_posts` boolean COMMENT '',
1763         `remote_self` boolean COMMENT '',
1764         `fetch_further_information` tinyint unsigned COMMENT '',
1765         `ffi_keyword_denylist` text COMMENT '',
1766         `subhub` boolean COMMENT '',
1767         `hub-verify` varbinary(383) COMMENT '',
1768         `protocol` char(4) COMMENT 'Protocol of the contact',
1769         `rating` tinyint COMMENT 'Automatically detected feed poll frequency',
1770         `priority` tinyint unsigned COMMENT 'Feed poll priority',
1771          PRIMARY KEY(`uid`,`cid`),
1772          INDEX `cid` (`cid`),
1773          UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
1774         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1775         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1776         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1777 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1778
1779 --
1780 -- TABLE arrived-activity
1781 --
1782 CREATE TABLE IF NOT EXISTS `arrived-activity` (
1783         `object-id` varbinary(383) NOT NULL COMMENT 'object id of the incoming activity',
1784         `received` datetime COMMENT 'Receiving date',
1785          PRIMARY KEY(`object-id`)
1786 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Id of arrived activities';
1787
1788 --
1789 -- TABLE fetched-activity
1790 --
1791 CREATE TABLE IF NOT EXISTS `fetched-activity` (
1792         `object-id` varbinary(383) NOT NULL COMMENT 'object id of fetched activity',
1793         `received` datetime COMMENT 'Receiving date',
1794          PRIMARY KEY(`object-id`)
1795 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Id of fetched activities';
1796
1797 --
1798 -- TABLE worker-ipc
1799 --
1800 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1801         `key` int NOT NULL COMMENT '',
1802         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1803          PRIMARY KEY(`key`)
1804 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1805
1806 --
1807 -- VIEW application-view
1808 --
1809 DROP VIEW IF EXISTS `application-view`;
1810 CREATE VIEW `application-view` AS SELECT 
1811         `application`.`id` AS `id`,
1812         `application-token`.`uid` AS `uid`,
1813         `application`.`name` AS `name`,
1814         `application`.`redirect_uri` AS `redirect_uri`,
1815         `application`.`website` AS `website`,
1816         `application`.`client_id` AS `client_id`,
1817         `application`.`client_secret` AS `client_secret`,
1818         `application-token`.`code` AS `code`,
1819         `application-token`.`access_token` AS `access_token`,
1820         `application-token`.`created_at` AS `created_at`,
1821         `application-token`.`scopes` AS `scopes`,
1822         `application-token`.`read` AS `read`,
1823         `application-token`.`write` AS `write`,
1824         `application-token`.`follow` AS `follow`,
1825         `application-token`.`push` AS `push`
1826         FROM `application-token`
1827                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1828
1829 --
1830 -- VIEW post-user-view
1831 --
1832 DROP VIEW IF EXISTS `post-user-view`;
1833 CREATE VIEW `post-user-view` AS SELECT 
1834         `post-user`.`id` AS `id`,
1835         `post-user`.`id` AS `post-user-id`,
1836         `post-user`.`uid` AS `uid`,
1837         `parent-post`.`id` AS `parent`,
1838         `item-uri`.`uri` AS `uri`,
1839         `post-user`.`uri-id` AS `uri-id`,
1840         `parent-item-uri`.`uri` AS `parent-uri`,
1841         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1842         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1843         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1844         `conversation-item-uri`.`uri` AS `conversation`,
1845         `post-thread-user`.`conversation-id` AS `conversation-id`,
1846         `quote-item-uri`.`uri` AS `quote-uri`,
1847         `post-content`.`quote-uri-id` AS `quote-uri-id`,
1848         `item-uri`.`guid` AS `guid`,
1849         `post-user`.`wall` AS `wall`,
1850         `post-user`.`gravity` AS `gravity`,
1851         `external-item-uri`.`uri` AS `extid`,
1852         `post-user`.`external-id` AS `external-id`,
1853         `post-user`.`created` AS `created`,
1854         `post-user`.`edited` AS `edited`,
1855         `post-thread-user`.`commented` AS `commented`,
1856         `post-user`.`received` AS `received`,
1857         `post-thread-user`.`changed` AS `changed`,
1858         `post-user`.`post-type` AS `post-type`,
1859         `post-user`.`post-reason` AS `post-reason`,
1860         `post-user`.`private` AS `private`,
1861         `post-thread-user`.`pubmail` AS `pubmail`,
1862         `post-user`.`visible` AS `visible`,
1863         `post-thread-user`.`starred` AS `starred`,
1864         `post-user`.`unseen` AS `unseen`,
1865         `post-user`.`deleted` AS `deleted`,
1866         `post-user`.`origin` AS `origin`,
1867         `post-thread-user`.`origin` AS `parent-origin`,
1868         `post-thread-user`.`mention` AS `mention`,
1869         `post-user`.`global` AS `global`,
1870         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
1871         `post-user`.`network` AS `network`,
1872         `post-user`.`protocol` AS `protocol`,
1873         `post-user`.`vid` AS `vid`,
1874         `post-user`.`psid` AS `psid`,
1875         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1876         `post-content`.`title` AS `title`,
1877         `post-content`.`content-warning` AS `content-warning`,
1878         `post-content`.`raw-body` AS `raw-body`,
1879         IFNULL (`post-content`.`body`, '') AS `body`,
1880         `post-content`.`rendered-hash` AS `rendered-hash`,
1881         `post-content`.`rendered-html` AS `rendered-html`,
1882         `post-content`.`language` AS `language`,
1883         `post-content`.`plink` AS `plink`,
1884         `post-content`.`location` AS `location`,
1885         `post-content`.`coord` AS `coord`,
1886         `post-content`.`app` AS `app`,
1887         `post-content`.`object-type` AS `object-type`,
1888         `post-content`.`object` AS `object`,
1889         `post-content`.`target-type` AS `target-type`,
1890         `post-content`.`target` AS `target`,
1891         `post-content`.`resource-id` AS `resource-id`,
1892         `post-user`.`contact-id` AS `contact-id`,
1893         `contact`.`uri-id` AS `contact-uri-id`,
1894         `contact`.`url` AS `contact-link`,
1895         `contact`.`addr` AS `contact-addr`,
1896         `contact`.`name` AS `contact-name`,
1897         `contact`.`nick` AS `contact-nick`,
1898         `contact`.`thumb` AS `contact-avatar`,
1899         `contact`.`network` AS `contact-network`,
1900         `contact`.`blocked` AS `contact-blocked`,
1901         `contact`.`hidden` AS `contact-hidden`,
1902         `contact`.`readonly` AS `contact-readonly`,
1903         `contact`.`archive` AS `contact-archive`,
1904         `contact`.`pending` AS `contact-pending`,
1905         `contact`.`rel` AS `contact-rel`,
1906         `contact`.`uid` AS `contact-uid`,
1907         `contact`.`contact-type` AS `contact-contact-type`,
1908         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1909         `contact`.`self` AS `self`,
1910         `contact`.`id` AS `cid`,
1911         `contact`.`alias` AS `alias`,
1912         `contact`.`photo` AS `photo`,
1913         `contact`.`name-date` AS `name-date`,
1914         `contact`.`uri-date` AS `uri-date`,
1915         `contact`.`avatar-date` AS `avatar-date`,
1916         `contact`.`thumb` AS `thumb`,
1917         `post-user`.`author-id` AS `author-id`,
1918         `author`.`uri-id` AS `author-uri-id`,
1919         `author`.`url` AS `author-link`,
1920         `author`.`addr` AS `author-addr`,
1921         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1922         `author`.`nick` AS `author-nick`,
1923         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1924         `author`.`network` AS `author-network`,
1925         `author`.`blocked` AS `author-blocked`,
1926         `author`.`hidden` AS `author-hidden`,
1927         `author`.`updated` AS `author-updated`,
1928         `author`.`gsid` AS `author-gsid`,
1929         `post-user`.`owner-id` AS `owner-id`,
1930         `owner`.`uri-id` AS `owner-uri-id`,
1931         `owner`.`url` AS `owner-link`,
1932         `owner`.`addr` AS `owner-addr`,
1933         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1934         `owner`.`nick` AS `owner-nick`,
1935         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1936         `owner`.`network` AS `owner-network`,
1937         `owner`.`blocked` AS `owner-blocked`,
1938         `owner`.`hidden` AS `owner-hidden`,
1939         `owner`.`updated` AS `owner-updated`,
1940         `owner`.`contact-type` AS `owner-contact-type`,
1941         `post-user`.`causer-id` AS `causer-id`,
1942         `causer`.`uri-id` AS `causer-uri-id`,
1943         `causer`.`url` AS `causer-link`,
1944         `causer`.`addr` AS `causer-addr`,
1945         `causer`.`name` AS `causer-name`,
1946         `causer`.`nick` AS `causer-nick`,
1947         `causer`.`thumb` AS `causer-avatar`,
1948         `causer`.`network` AS `causer-network`,
1949         `causer`.`blocked` AS `causer-blocked`,
1950         `causer`.`hidden` AS `causer-hidden`,
1951         `causer`.`contact-type` AS `causer-contact-type`,
1952         `post-delivery-data`.`postopts` AS `postopts`,
1953         `post-delivery-data`.`inform` AS `inform`,
1954         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1955         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1956         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1957         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1958         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1959         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1960         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1961         `post-user`.`event-id` AS `event-id`,
1962         `event`.`created` AS `event-created`,
1963         `event`.`edited` AS `event-edited`,
1964         `event`.`start` AS `event-start`,
1965         `event`.`finish` AS `event-finish`,
1966         `event`.`summary` AS `event-summary`,
1967         `event`.`desc` AS `event-desc`,
1968         `event`.`location` AS `event-location`,
1969         `event`.`type` AS `event-type`,
1970         `event`.`nofinish` AS `event-nofinish`,
1971         `event`.`ignore` AS `event-ignore`,
1972         `post-question`.`id` AS `question-id`,
1973         `post-question`.`multiple` AS `question-multiple`,
1974         `post-question`.`voters` AS `question-voters`,
1975         `post-question`.`end-time` AS `question-end-time`,
1976         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`,
1977         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-user`.`uri-id`) AS `has-media`,
1978         `diaspora-interaction`.`interaction` AS `signed_text`,
1979         `parent-item-uri`.`guid` AS `parent-guid`,
1980         `parent-post`.`network` AS `parent-network`,
1981         `parent-post`.`author-id` AS `parent-author-id`,
1982         `parent-post-author`.`url` AS `parent-author-link`,
1983         `parent-post-author`.`name` AS `parent-author-name`,
1984         `parent-post-author`.`nick` AS `parent-author-nick`,
1985         `parent-post-author`.`network` AS `parent-author-network`
1986         FROM `post-user`
1987                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1988                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1989                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1990                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1991                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1992                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1993                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1994                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1995                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
1996                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1997                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1998                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1999                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
2000                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
2001                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2002                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
2003                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
2004                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
2005                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2006                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2007
2008 --
2009 -- VIEW post-thread-user-view
2010 --
2011 DROP VIEW IF EXISTS `post-thread-user-view`;
2012 CREATE VIEW `post-thread-user-view` AS SELECT 
2013         `post-user`.`id` AS `id`,
2014         `post-user`.`id` AS `post-user-id`,
2015         `post-thread-user`.`uid` AS `uid`,
2016         `parent-post`.`id` AS `parent`,
2017         `item-uri`.`uri` AS `uri`,
2018         `post-thread-user`.`uri-id` AS `uri-id`,
2019         `parent-item-uri`.`uri` AS `parent-uri`,
2020         `post-user`.`parent-uri-id` AS `parent-uri-id`,
2021         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2022         `post-user`.`thr-parent-id` AS `thr-parent-id`,
2023         `conversation-item-uri`.`uri` AS `conversation`,
2024         `post-thread-user`.`conversation-id` AS `conversation-id`,
2025         `quote-item-uri`.`uri` AS `quote-uri`,
2026         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2027         `item-uri`.`guid` AS `guid`,
2028         `post-thread-user`.`wall` AS `wall`,
2029         `post-user`.`gravity` AS `gravity`,
2030         `external-item-uri`.`uri` AS `extid`,
2031         `post-user`.`external-id` AS `external-id`,
2032         `post-thread-user`.`created` AS `created`,
2033         `post-user`.`edited` AS `edited`,
2034         `post-thread-user`.`commented` AS `commented`,
2035         `post-thread-user`.`received` AS `received`,
2036         `post-thread-user`.`changed` AS `changed`,
2037         `post-user`.`post-type` AS `post-type`,
2038         `post-user`.`post-reason` AS `post-reason`,
2039         `post-user`.`private` AS `private`,
2040         `post-thread-user`.`pubmail` AS `pubmail`,
2041         `post-thread-user`.`ignored` AS `ignored`,
2042         `post-user`.`visible` AS `visible`,
2043         `post-thread-user`.`starred` AS `starred`,
2044         `post-thread-user`.`unseen` AS `unseen`,
2045         `post-user`.`deleted` AS `deleted`,
2046         `post-thread-user`.`origin` AS `origin`,
2047         `post-thread-user`.`mention` AS `mention`,
2048         `post-user`.`global` AS `global`,
2049         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
2050         `post-thread-user`.`network` AS `network`,
2051         `post-user`.`vid` AS `vid`,
2052         `post-thread-user`.`psid` AS `psid`,
2053         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2054         `post-content`.`title` AS `title`,
2055         `post-content`.`content-warning` AS `content-warning`,
2056         `post-content`.`raw-body` AS `raw-body`,
2057         `post-content`.`body` AS `body`,
2058         `post-content`.`rendered-hash` AS `rendered-hash`,
2059         `post-content`.`rendered-html` AS `rendered-html`,
2060         `post-content`.`language` AS `language`,
2061         `post-content`.`plink` AS `plink`,
2062         `post-content`.`location` AS `location`,
2063         `post-content`.`coord` AS `coord`,
2064         `post-content`.`app` AS `app`,
2065         `post-content`.`object-type` AS `object-type`,
2066         `post-content`.`object` AS `object`,
2067         `post-content`.`target-type` AS `target-type`,
2068         `post-content`.`target` AS `target`,
2069         `post-content`.`resource-id` AS `resource-id`,
2070         `post-thread-user`.`contact-id` AS `contact-id`,
2071         `contact`.`uri-id` AS `contact-uri-id`,
2072         `contact`.`url` AS `contact-link`,
2073         `contact`.`addr` AS `contact-addr`,
2074         `contact`.`name` AS `contact-name`,
2075         `contact`.`nick` AS `contact-nick`,
2076         `contact`.`thumb` AS `contact-avatar`,
2077         `contact`.`network` AS `contact-network`,
2078         `contact`.`blocked` AS `contact-blocked`,
2079         `contact`.`hidden` AS `contact-hidden`,
2080         `contact`.`readonly` AS `contact-readonly`,
2081         `contact`.`archive` AS `contact-archive`,
2082         `contact`.`pending` AS `contact-pending`,
2083         `contact`.`rel` AS `contact-rel`,
2084         `contact`.`uid` AS `contact-uid`,
2085         `contact`.`contact-type` AS `contact-contact-type`,
2086         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
2087         `contact`.`self` AS `self`,
2088         `contact`.`id` AS `cid`,
2089         `contact`.`alias` AS `alias`,
2090         `contact`.`photo` AS `photo`,
2091         `contact`.`name-date` AS `name-date`,
2092         `contact`.`uri-date` AS `uri-date`,
2093         `contact`.`avatar-date` AS `avatar-date`,
2094         `contact`.`thumb` AS `thumb`,
2095         `post-thread-user`.`author-id` AS `author-id`,
2096         `author`.`uri-id` AS `author-uri-id`,
2097         `author`.`url` AS `author-link`,
2098         `author`.`addr` AS `author-addr`,
2099         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
2100         `author`.`nick` AS `author-nick`,
2101         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
2102         `author`.`network` AS `author-network`,
2103         `author`.`blocked` AS `author-blocked`,
2104         `author`.`hidden` AS `author-hidden`,
2105         `author`.`updated` AS `author-updated`,
2106         `author`.`gsid` AS `author-gsid`,
2107         `post-thread-user`.`owner-id` AS `owner-id`,
2108         `owner`.`uri-id` AS `owner-uri-id`,
2109         `owner`.`url` AS `owner-link`,
2110         `owner`.`addr` AS `owner-addr`,
2111         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
2112         `owner`.`nick` AS `owner-nick`,
2113         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
2114         `owner`.`network` AS `owner-network`,
2115         `owner`.`blocked` AS `owner-blocked`,
2116         `owner`.`hidden` AS `owner-hidden`,
2117         `owner`.`updated` AS `owner-updated`,
2118         `owner`.`contact-type` AS `owner-contact-type`,
2119         `post-thread-user`.`causer-id` AS `causer-id`,
2120         `causer`.`uri-id` AS `causer-uri-id`,
2121         `causer`.`url` AS `causer-link`,
2122         `causer`.`addr` AS `causer-addr`,
2123         `causer`.`name` AS `causer-name`,
2124         `causer`.`nick` AS `causer-nick`,
2125         `causer`.`thumb` AS `causer-avatar`,
2126         `causer`.`network` AS `causer-network`,
2127         `causer`.`blocked` AS `causer-blocked`,
2128         `causer`.`hidden` AS `causer-hidden`,
2129         `causer`.`contact-type` AS `causer-contact-type`,
2130         `post-delivery-data`.`postopts` AS `postopts`,
2131         `post-delivery-data`.`inform` AS `inform`,
2132         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
2133         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
2134         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
2135         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
2136         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
2137         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
2138         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
2139         `post-user`.`event-id` AS `event-id`,
2140         `event`.`created` AS `event-created`,
2141         `event`.`edited` AS `event-edited`,
2142         `event`.`start` AS `event-start`,
2143         `event`.`finish` AS `event-finish`,
2144         `event`.`summary` AS `event-summary`,
2145         `event`.`desc` AS `event-desc`,
2146         `event`.`location` AS `event-location`,
2147         `event`.`type` AS `event-type`,
2148         `event`.`nofinish` AS `event-nofinish`,
2149         `event`.`ignore` AS `event-ignore`,
2150         `post-question`.`id` AS `question-id`,
2151         `post-question`.`multiple` AS `question-multiple`,
2152         `post-question`.`voters` AS `question-voters`,
2153         `post-question`.`end-time` AS `question-end-time`,
2154         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`,
2155         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-user`.`uri-id`) AS `has-media`,
2156         `diaspora-interaction`.`interaction` AS `signed_text`,
2157         `parent-item-uri`.`guid` AS `parent-guid`,
2158         `parent-post`.`network` AS `parent-network`,
2159         `parent-post`.`author-id` AS `parent-author-id`,
2160         `parent-post-author`.`url` AS `parent-author-link`,
2161         `parent-post-author`.`name` AS `parent-author-name`,
2162         `parent-post-author`.`network` AS `parent-author-network`
2163         FROM `post-thread-user`
2164                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2165                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2166                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
2167                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
2168                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
2169                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
2170                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
2171                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
2172                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
2173                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
2174                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
2175                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
2176                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
2177                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
2178                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2179                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
2180                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
2181                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
2182                         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`
2183                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2184
2185 --
2186 -- VIEW post-view
2187 --
2188 DROP VIEW IF EXISTS `post-view`;
2189 CREATE VIEW `post-view` AS SELECT 
2190         `item-uri`.`uri` AS `uri`,
2191         `post`.`uri-id` AS `uri-id`,
2192         `parent-item-uri`.`uri` AS `parent-uri`,
2193         `post`.`parent-uri-id` AS `parent-uri-id`,
2194         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2195         `post`.`thr-parent-id` AS `thr-parent-id`,
2196         `conversation-item-uri`.`uri` AS `conversation`,
2197         `post-thread`.`conversation-id` AS `conversation-id`,
2198         `quote-item-uri`.`uri` AS `quote-uri`,
2199         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2200         `item-uri`.`guid` AS `guid`,
2201         `post`.`gravity` AS `gravity`,
2202         `external-item-uri`.`uri` AS `extid`,
2203         `post`.`external-id` AS `external-id`,
2204         `post`.`created` AS `created`,
2205         `post`.`edited` AS `edited`,
2206         `post-thread`.`commented` AS `commented`,
2207         `post`.`received` AS `received`,
2208         `post-thread`.`changed` AS `changed`,
2209         `post`.`post-type` AS `post-type`,
2210         `post`.`private` AS `private`,
2211         `post`.`visible` AS `visible`,
2212         `post`.`deleted` AS `deleted`,
2213         `post`.`global` AS `global`,
2214         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
2215         `post`.`network` AS `network`,
2216         `post`.`vid` AS `vid`,
2217         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2218         `post-content`.`title` AS `title`,
2219         `post-content`.`content-warning` AS `content-warning`,
2220         `post-content`.`raw-body` AS `raw-body`,
2221         `post-content`.`body` AS `body`,
2222         `post-content`.`rendered-hash` AS `rendered-hash`,
2223         `post-content`.`rendered-html` AS `rendered-html`,
2224         `post-content`.`language` AS `language`,
2225         `post-content`.`plink` AS `plink`,
2226         `post-content`.`location` AS `location`,
2227         `post-content`.`coord` AS `coord`,
2228         `post-content`.`app` AS `app`,
2229         `post-content`.`object-type` AS `object-type`,
2230         `post-content`.`object` AS `object`,
2231         `post-content`.`target-type` AS `target-type`,
2232         `post-content`.`target` AS `target`,
2233         `post-content`.`resource-id` AS `resource-id`,
2234         `post`.`author-id` AS `contact-id`,
2235         `author`.`uri-id` AS `contact-uri-id`,
2236         `author`.`url` AS `contact-link`,
2237         `author`.`addr` AS `contact-addr`,
2238         `author`.`name` AS `contact-name`,
2239         `author`.`nick` AS `contact-nick`,
2240         `author`.`thumb` AS `contact-avatar`,
2241         `author`.`network` AS `contact-network`,
2242         `author`.`blocked` AS `contact-blocked`,
2243         `author`.`hidden` AS `contact-hidden`,
2244         `author`.`readonly` AS `contact-readonly`,
2245         `author`.`archive` AS `contact-archive`,
2246         `author`.`pending` AS `contact-pending`,
2247         `author`.`rel` AS `contact-rel`,
2248         `author`.`uid` AS `contact-uid`,
2249         `author`.`contact-type` AS `contact-contact-type`,
2250         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2251         false AS `self`,
2252         `author`.`id` AS `cid`,
2253         `author`.`alias` AS `alias`,
2254         `author`.`photo` AS `photo`,
2255         `author`.`name-date` AS `name-date`,
2256         `author`.`uri-date` AS `uri-date`,
2257         `author`.`avatar-date` AS `avatar-date`,
2258         `author`.`thumb` AS `thumb`,
2259         `post`.`author-id` AS `author-id`,
2260         `author`.`uri-id` AS `author-uri-id`,
2261         `author`.`url` AS `author-link`,
2262         `author`.`addr` AS `author-addr`,
2263         `author`.`name` AS `author-name`,
2264         `author`.`nick` AS `author-nick`,
2265         `author`.`thumb` AS `author-avatar`,
2266         `author`.`network` AS `author-network`,
2267         `author`.`blocked` AS `author-blocked`,
2268         `author`.`hidden` AS `author-hidden`,
2269         `author`.`updated` AS `author-updated`,
2270         `author`.`gsid` AS `author-gsid`,
2271         `post`.`owner-id` AS `owner-id`,
2272         `owner`.`uri-id` AS `owner-uri-id`,
2273         `owner`.`url` AS `owner-link`,
2274         `owner`.`addr` AS `owner-addr`,
2275         `owner`.`name` AS `owner-name`,
2276         `owner`.`nick` AS `owner-nick`,
2277         `owner`.`thumb` AS `owner-avatar`,
2278         `owner`.`network` AS `owner-network`,
2279         `owner`.`blocked` AS `owner-blocked`,
2280         `owner`.`hidden` AS `owner-hidden`,
2281         `owner`.`updated` AS `owner-updated`,
2282         `owner`.`contact-type` AS `owner-contact-type`,
2283         `post`.`causer-id` AS `causer-id`,
2284         `causer`.`uri-id` AS `causer-uri-id`,
2285         `causer`.`url` AS `causer-link`,
2286         `causer`.`addr` AS `causer-addr`,
2287         `causer`.`name` AS `causer-name`,
2288         `causer`.`nick` AS `causer-nick`,
2289         `causer`.`thumb` AS `causer-avatar`,
2290         `causer`.`network` AS `causer-network`,
2291         `causer`.`blocked` AS `causer-blocked`,
2292         `causer`.`hidden` AS `causer-hidden`,
2293         `causer`.`contact-type` AS `causer-contact-type`,
2294         `post-question`.`id` AS `question-id`,
2295         `post-question`.`multiple` AS `question-multiple`,
2296         `post-question`.`voters` AS `question-voters`,
2297         `post-question`.`end-time` AS `question-end-time`,
2298         0 AS `has-categories`,
2299         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post`.`uri-id`) AS `has-media`,
2300         `diaspora-interaction`.`interaction` AS `signed_text`,
2301         `parent-item-uri`.`guid` AS `parent-guid`,
2302         `parent-post`.`network` AS `parent-network`,
2303         `parent-post`.`author-id` AS `parent-author-id`,
2304         `parent-post-author`.`url` AS `parent-author-link`,
2305         `parent-post-author`.`name` AS `parent-author-name`,
2306         `parent-post-author`.`network` AS `parent-author-network`
2307         FROM `post`
2308                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2309                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2310                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2311                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2312                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2313                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2314                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2315                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2316                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2317                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2318                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2319                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2320                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2321                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
2322                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2323                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2324
2325 --
2326 -- VIEW post-thread-view
2327 --
2328 DROP VIEW IF EXISTS `post-thread-view`;
2329 CREATE VIEW `post-thread-view` AS SELECT 
2330         `item-uri`.`uri` AS `uri`,
2331         `post-thread`.`uri-id` AS `uri-id`,
2332         `parent-item-uri`.`uri` AS `parent-uri`,
2333         `post`.`parent-uri-id` AS `parent-uri-id`,
2334         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2335         `post`.`thr-parent-id` AS `thr-parent-id`,
2336         `conversation-item-uri`.`uri` AS `conversation`,
2337         `post-thread`.`conversation-id` AS `conversation-id`,
2338         `quote-item-uri`.`uri` AS `quote-uri`,
2339         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2340         `item-uri`.`guid` AS `guid`,
2341         `post`.`gravity` AS `gravity`,
2342         `external-item-uri`.`uri` AS `extid`,
2343         `post`.`external-id` AS `external-id`,
2344         `post-thread`.`created` AS `created`,
2345         `post`.`edited` AS `edited`,
2346         `post-thread`.`commented` AS `commented`,
2347         `post-thread`.`received` AS `received`,
2348         `post-thread`.`changed` AS `changed`,
2349         `post`.`post-type` AS `post-type`,
2350         `post`.`private` AS `private`,
2351         `post`.`visible` AS `visible`,
2352         `post`.`deleted` AS `deleted`,
2353         `post`.`global` AS `global`,
2354         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
2355         `post-thread`.`network` AS `network`,
2356         `post`.`vid` AS `vid`,
2357         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2358         `post-content`.`title` AS `title`,
2359         `post-content`.`content-warning` AS `content-warning`,
2360         `post-content`.`raw-body` AS `raw-body`,
2361         `post-content`.`body` AS `body`,
2362         `post-content`.`rendered-hash` AS `rendered-hash`,
2363         `post-content`.`rendered-html` AS `rendered-html`,
2364         `post-content`.`language` AS `language`,
2365         `post-content`.`plink` AS `plink`,
2366         `post-content`.`location` AS `location`,
2367         `post-content`.`coord` AS `coord`,
2368         `post-content`.`app` AS `app`,
2369         `post-content`.`object-type` AS `object-type`,
2370         `post-content`.`object` AS `object`,
2371         `post-content`.`target-type` AS `target-type`,
2372         `post-content`.`target` AS `target`,
2373         `post-content`.`resource-id` AS `resource-id`,
2374         `post-thread`.`author-id` AS `contact-id`,
2375         `author`.`uri-id` AS `contact-uri-id`,
2376         `author`.`url` AS `contact-link`,
2377         `author`.`addr` AS `contact-addr`,
2378         `author`.`name` AS `contact-name`,
2379         `author`.`nick` AS `contact-nick`,
2380         `author`.`thumb` AS `contact-avatar`,
2381         `author`.`network` AS `contact-network`,
2382         `author`.`blocked` AS `contact-blocked`,
2383         `author`.`hidden` AS `contact-hidden`,
2384         `author`.`readonly` AS `contact-readonly`,
2385         `author`.`archive` AS `contact-archive`,
2386         `author`.`pending` AS `contact-pending`,
2387         `author`.`rel` AS `contact-rel`,
2388         `author`.`uid` AS `contact-uid`,
2389         `author`.`contact-type` AS `contact-contact-type`,
2390         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2391         false AS `self`,
2392         `author`.`id` AS `cid`,
2393         `author`.`alias` AS `alias`,
2394         `author`.`photo` AS `photo`,
2395         `author`.`name-date` AS `name-date`,
2396         `author`.`uri-date` AS `uri-date`,
2397         `author`.`avatar-date` AS `avatar-date`,
2398         `author`.`thumb` AS `thumb`,
2399         `post-thread`.`author-id` AS `author-id`,
2400         `author`.`uri-id` AS `author-uri-id`,
2401         `author`.`url` AS `author-link`,
2402         `author`.`addr` AS `author-addr`,
2403         `author`.`name` AS `author-name`,
2404         `author`.`nick` AS `author-nick`,
2405         `author`.`thumb` AS `author-avatar`,
2406         `author`.`network` AS `author-network`,
2407         `author`.`blocked` AS `author-blocked`,
2408         `author`.`hidden` AS `author-hidden`,
2409         `author`.`updated` AS `author-updated`,
2410         `author`.`gsid` AS `author-gsid`,
2411         `post-thread`.`owner-id` AS `owner-id`,
2412         `owner`.`uri-id` AS `owner-uri-id`,
2413         `owner`.`url` AS `owner-link`,
2414         `owner`.`addr` AS `owner-addr`,
2415         `owner`.`name` AS `owner-name`,
2416         `owner`.`nick` AS `owner-nick`,
2417         `owner`.`thumb` AS `owner-avatar`,
2418         `owner`.`network` AS `owner-network`,
2419         `owner`.`blocked` AS `owner-blocked`,
2420         `owner`.`hidden` AS `owner-hidden`,
2421         `owner`.`updated` AS `owner-updated`,
2422         `owner`.`contact-type` AS `owner-contact-type`,
2423         `post-thread`.`causer-id` AS `causer-id`,
2424         `causer`.`uri-id` AS `causer-uri-id`,
2425         `causer`.`url` AS `causer-link`,
2426         `causer`.`addr` AS `causer-addr`,
2427         `causer`.`name` AS `causer-name`,
2428         `causer`.`nick` AS `causer-nick`,
2429         `causer`.`thumb` AS `causer-avatar`,
2430         `causer`.`network` AS `causer-network`,
2431         `causer`.`blocked` AS `causer-blocked`,
2432         `causer`.`hidden` AS `causer-hidden`,
2433         `causer`.`contact-type` AS `causer-contact-type`,
2434         `post-question`.`id` AS `question-id`,
2435         `post-question`.`multiple` AS `question-multiple`,
2436         `post-question`.`voters` AS `question-voters`,
2437         `post-question`.`end-time` AS `question-end-time`,
2438         0 AS `has-categories`,
2439         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`) AS `has-media`,
2440         (SELECT COUNT(*) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-comments`,
2441         (SELECT COUNT(DISTINCT(`author-id`)) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-actors`,
2442         `diaspora-interaction`.`interaction` AS `signed_text`,
2443         `parent-item-uri`.`guid` AS `parent-guid`,
2444         `parent-post`.`network` AS `parent-network`,
2445         `parent-post`.`author-id` AS `parent-author-id`,
2446         `parent-post-author`.`url` AS `parent-author-link`,
2447         `parent-post-author`.`name` AS `parent-author-name`,
2448         `parent-post-author`.`network` AS `parent-author-network`
2449         FROM `post-thread`
2450                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2451                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2452                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2453                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2454                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2455                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2456                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2457                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2458                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2459                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2460                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2461                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2462                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2463                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`
2464                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2465                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2466
2467 --
2468 -- VIEW category-view
2469 --
2470 DROP VIEW IF EXISTS `category-view`;
2471 CREATE VIEW `category-view` AS SELECT 
2472         `post-category`.`uri-id` AS `uri-id`,
2473         `post-category`.`uid` AS `uid`,
2474         `post-category`.`type` AS `type`,
2475         `post-category`.`tid` AS `tid`,
2476         `tag`.`name` AS `name`,
2477         `tag`.`url` AS `url`
2478         FROM `post-category`
2479                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2480
2481 --
2482 -- VIEW collection-view
2483 --
2484 DROP VIEW IF EXISTS `collection-view`;
2485 CREATE VIEW `collection-view` AS SELECT 
2486         `post-collection`.`uri-id` AS `uri-id`,
2487         `post-collection`.`type` AS `type`,
2488         `post-collection`.`author-id` AS `cid`,
2489         `post`.`received` AS `received`,
2490         `post`.`created` AS `created`,
2491         `post-thread`.`commented` AS `commented`,
2492         `post`.`private` AS `private`,
2493         `post`.`visible` AS `visible`,
2494         `post`.`deleted` AS `deleted`,
2495         `post`.`thr-parent-id` AS `thr-parent-id`,
2496         `post-collection`.`author-id` AS `author-id`,
2497         `post`.`gravity` AS `gravity`
2498         FROM `post-collection`
2499                         INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
2500                         INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`;
2501
2502 --
2503 -- VIEW tag-view
2504 --
2505 DROP VIEW IF EXISTS `tag-view`;
2506 CREATE VIEW `tag-view` AS SELECT 
2507         `post-tag`.`uri-id` AS `uri-id`,
2508         `post-tag`.`type` AS `type`,
2509         `post-tag`.`tid` AS `tid`,
2510         `post-tag`.`cid` AS `cid`,
2511         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2512         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`,
2513         CASE `cid` WHEN 0 THEN `tag`.`type` ELSE 1 END AS `tag-type`
2514         FROM `post-tag`
2515                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2516                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2517
2518 --
2519 -- VIEW network-item-view
2520 --
2521 DROP VIEW IF EXISTS `network-item-view`;
2522 CREATE VIEW `network-item-view` AS SELECT 
2523         `post-user`.`uri-id` AS `uri-id`,
2524         `parent-post`.`id` AS `parent`,
2525         `post-user`.`received` AS `received`,
2526         `post-thread-user`.`commented` AS `commented`,
2527         `post-user`.`created` AS `created`,
2528         `post-user`.`uid` AS `uid`,
2529         `post-thread-user`.`starred` AS `starred`,
2530         `post-thread-user`.`mention` AS `mention`,
2531         `post-user`.`network` AS `network`,
2532         `post-user`.`unseen` AS `unseen`,
2533         `post-user`.`gravity` AS `gravity`,
2534         `post-user`.`contact-id` AS `contact-id`,
2535         `ownercontact`.`contact-type` AS `contact-type`
2536         FROM `post-user`
2537                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2538                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2539                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2540                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2541                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2542                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2543                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2544                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2545                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2546                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2547                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2548
2549 --
2550 -- VIEW network-thread-view
2551 --
2552 DROP VIEW IF EXISTS `network-thread-view`;
2553 CREATE VIEW `network-thread-view` AS SELECT 
2554         `post-thread-user`.`uri-id` AS `uri-id`,
2555         `parent-post`.`id` AS `parent`,
2556         `post-thread-user`.`received` AS `received`,
2557         `post-thread-user`.`commented` AS `commented`,
2558         `post-thread-user`.`created` AS `created`,
2559         `post-thread-user`.`uid` AS `uid`,
2560         `post-thread-user`.`starred` AS `starred`,
2561         `post-thread-user`.`mention` AS `mention`,
2562         `post-thread-user`.`network` AS `network`,
2563         `post-thread-user`.`contact-id` AS `contact-id`,
2564         `ownercontact`.`contact-type` AS `contact-type`
2565         FROM `post-thread-user`
2566                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2567                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2568                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2569                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2570                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2571                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2572                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2573                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2574                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2575                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2576                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2577
2578 --
2579 -- VIEW owner-view
2580 --
2581 DROP VIEW IF EXISTS `owner-view`;
2582 CREATE VIEW `owner-view` AS SELECT 
2583         `contact`.`id` AS `id`,
2584         `contact`.`uid` AS `uid`,
2585         `contact`.`created` AS `created`,
2586         `contact`.`updated` AS `updated`,
2587         `contact`.`self` AS `self`,
2588         `contact`.`remote_self` AS `remote_self`,
2589         `contact`.`rel` AS `rel`,
2590         `contact`.`network` AS `network`,
2591         `contact`.`protocol` AS `protocol`,
2592         `contact`.`name` AS `name`,
2593         `contact`.`nick` AS `nick`,
2594         `contact`.`location` AS `location`,
2595         `contact`.`about` AS `about`,
2596         `contact`.`keywords` AS `keywords`,
2597         `contact`.`xmpp` AS `xmpp`,
2598         `contact`.`matrix` AS `matrix`,
2599         `contact`.`attag` AS `attag`,
2600         `contact`.`avatar` AS `avatar`,
2601         `contact`.`photo` AS `photo`,
2602         `contact`.`thumb` AS `thumb`,
2603         `contact`.`micro` AS `micro`,
2604         `contact`.`header` AS `header`,
2605         `contact`.`url` AS `url`,
2606         `contact`.`nurl` AS `nurl`,
2607         `contact`.`uri-id` AS `uri-id`,
2608         `contact`.`addr` AS `addr`,
2609         `contact`.`alias` AS `alias`,
2610         `contact`.`pubkey` AS `pubkey`,
2611         `contact`.`prvkey` AS `prvkey`,
2612         `contact`.`batch` AS `batch`,
2613         `contact`.`request` AS `request`,
2614         `contact`.`notify` AS `notify`,
2615         `contact`.`poll` AS `poll`,
2616         `contact`.`confirm` AS `confirm`,
2617         `contact`.`poco` AS `poco`,
2618         `contact`.`subhub` AS `subhub`,
2619         `contact`.`hub-verify` AS `hub-verify`,
2620         `contact`.`last-update` AS `last-update`,
2621         `contact`.`success_update` AS `success_update`,
2622         `contact`.`failure_update` AS `failure_update`,
2623         `contact`.`name-date` AS `name-date`,
2624         `contact`.`uri-date` AS `uri-date`,
2625         `contact`.`avatar-date` AS `avatar-date`,
2626         `contact`.`avatar-date` AS `picdate`,
2627         `contact`.`term-date` AS `term-date`,
2628         `contact`.`last-item` AS `last-item`,
2629         `contact`.`priority` AS `priority`,
2630         `user`.`blocked` AS `blocked`,
2631         `contact`.`block_reason` AS `block_reason`,
2632         `contact`.`readonly` AS `readonly`,
2633         `contact`.`writable` AS `writable`,
2634         `contact`.`forum` AS `forum`,
2635         `contact`.`prv` AS `prv`,
2636         `contact`.`contact-type` AS `contact-type`,
2637         `contact`.`manually-approve` AS `manually-approve`,
2638         `contact`.`hidden` AS `hidden`,
2639         `contact`.`archive` AS `archive`,
2640         `contact`.`pending` AS `pending`,
2641         `contact`.`deleted` AS `deleted`,
2642         `contact`.`unsearchable` AS `unsearchable`,
2643         `contact`.`sensitive` AS `sensitive`,
2644         `contact`.`baseurl` AS `baseurl`,
2645         `contact`.`reason` AS `reason`,
2646         `contact`.`info` AS `info`,
2647         `contact`.`bdyear` AS `bdyear`,
2648         `contact`.`bd` AS `bd`,
2649         `contact`.`notify_new_posts` AS `notify_new_posts`,
2650         `contact`.`fetch_further_information` AS `fetch_further_information`,
2651         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2652         `user`.`parent-uid` AS `parent-uid`,
2653         `user`.`guid` AS `guid`,
2654         `user`.`nickname` AS `nickname`,
2655         `user`.`email` AS `email`,
2656         `user`.`openid` AS `openid`,
2657         `user`.`timezone` AS `timezone`,
2658         `user`.`language` AS `language`,
2659         `user`.`register_date` AS `register_date`,
2660         `user`.`login_date` AS `login_date`,
2661         `user`.`default-location` AS `default-location`,
2662         `user`.`allow_location` AS `allow_location`,
2663         `user`.`theme` AS `theme`,
2664         `user`.`pubkey` AS `upubkey`,
2665         `user`.`prvkey` AS `uprvkey`,
2666         `user`.`sprvkey` AS `sprvkey`,
2667         `user`.`spubkey` AS `spubkey`,
2668         `user`.`verified` AS `verified`,
2669         `user`.`blockwall` AS `blockwall`,
2670         `user`.`hidewall` AS `hidewall`,
2671         `user`.`blocktags` AS `blocktags`,
2672         `user`.`unkmail` AS `unkmail`,
2673         `user`.`cntunkmail` AS `cntunkmail`,
2674         `user`.`notify-flags` AS `notify-flags`,
2675         `user`.`page-flags` AS `page-flags`,
2676         `user`.`account-type` AS `account-type`,
2677         `user`.`prvnets` AS `prvnets`,
2678         `user`.`maxreq` AS `maxreq`,
2679         `user`.`expire` AS `expire`,
2680         `user`.`account_removed` AS `account_removed`,
2681         `user`.`account_expired` AS `account_expired`,
2682         `user`.`account_expires_on` AS `account_expires_on`,
2683         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2684         `user`.`def_gid` AS `def_gid`,
2685         `user`.`allow_cid` AS `allow_cid`,
2686         `user`.`allow_gid` AS `allow_gid`,
2687         `user`.`deny_cid` AS `deny_cid`,
2688         `user`.`deny_gid` AS `deny_gid`,
2689         `user`.`openidserver` AS `openidserver`,
2690         `profile`.`publish` AS `publish`,
2691         `profile`.`net-publish` AS `net-publish`,
2692         `profile`.`hide-friends` AS `hide-friends`,
2693         `profile`.`prv_keywords` AS `prv_keywords`,
2694         `profile`.`pub_keywords` AS `pub_keywords`,
2695         `profile`.`address` AS `address`,
2696         `profile`.`locality` AS `locality`,
2697         `profile`.`region` AS `region`,
2698         `profile`.`postal-code` AS `postal-code`,
2699         `profile`.`country-name` AS `country-name`,
2700         `profile`.`homepage` AS `homepage`,
2701         `profile`.`homepage_verified` AS `homepage_verified`,
2702         `profile`.`dob` AS `dob`
2703         FROM `user`
2704                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2705                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2706
2707 --
2708 -- VIEW account-view
2709 --
2710 DROP VIEW IF EXISTS `account-view`;
2711 CREATE VIEW `account-view` AS SELECT 
2712         `contact`.`id` AS `id`,
2713         `contact`.`url` AS `url`,
2714         `contact`.`nurl` AS `nurl`,
2715         `contact`.`uri-id` AS `uri-id`,
2716         `item-uri`.`guid` AS `guid`,
2717         `contact`.`addr` AS `addr`,
2718         `contact`.`alias` AS `alias`,
2719         `contact`.`name` AS `name`,
2720         `contact`.`nick` AS `nick`,
2721         `contact`.`about` AS `about`,
2722         `contact`.`keywords` AS `keywords`,
2723         `contact`.`xmpp` AS `xmpp`,
2724         `contact`.`matrix` AS `matrix`,
2725         `contact`.`avatar` AS `avatar`,
2726         `contact`.`photo` AS `photo`,
2727         `contact`.`thumb` AS `thumb`,
2728         `contact`.`micro` AS `micro`,
2729         `contact`.`header` AS `header`,
2730         `contact`.`created` AS `created`,
2731         `contact`.`updated` AS `updated`,
2732         `contact`.`network` AS `network`,
2733         `contact`.`protocol` AS `protocol`,
2734         `contact`.`location` AS `location`,
2735         `contact`.`attag` AS `attag`,
2736         `contact`.`pubkey` AS `pubkey`,
2737         `contact`.`prvkey` AS `prvkey`,
2738         `contact`.`subscribe` AS `subscribe`,
2739         `contact`.`last-update` AS `last-update`,
2740         `contact`.`success_update` AS `success_update`,
2741         `contact`.`failure_update` AS `failure_update`,
2742         `contact`.`failed` AS `failed`,
2743         `contact`.`last-item` AS `last-item`,
2744         `contact`.`last-discovery` AS `last-discovery`,
2745         `contact`.`contact-type` AS `contact-type`,
2746         `contact`.`manually-approve` AS `manually-approve`,
2747         `contact`.`unsearchable` AS `unsearchable`,
2748         `contact`.`sensitive` AS `sensitive`,
2749         `contact`.`baseurl` AS `baseurl`,
2750         `contact`.`gsid` AS `gsid`,
2751         `contact`.`info` AS `info`,
2752         `contact`.`bdyear` AS `bdyear`,
2753         `contact`.`bd` AS `bd`,
2754         `contact`.`poco` AS `poco`,
2755         `contact`.`name-date` AS `name-date`,
2756         `contact`.`uri-date` AS `uri-date`,
2757         `contact`.`avatar-date` AS `avatar-date`,
2758         `contact`.`term-date` AS `term-date`,
2759         `contact`.`hidden` AS `global-ignored`,
2760         `contact`.`blocked` AS `global-blocked`,
2761         `contact`.`hidden` AS `hidden`,
2762         `contact`.`archive` AS `archive`,
2763         `contact`.`deleted` AS `deleted`,
2764         `contact`.`blocked` AS `blocked`,
2765         `contact`.`notify` AS `dfrn-notify`,
2766         `contact`.`poll` AS `dfrn-poll`,
2767         `fcontact`.`guid` AS `diaspora-guid`,
2768         `fcontact`.`batch` AS `diaspora-batch`,
2769         `fcontact`.`notify` AS `diaspora-notify`,
2770         `fcontact`.`poll` AS `diaspora-poll`,
2771         `fcontact`.`alias` AS `diaspora-alias`,
2772         `apcontact`.`uuid` AS `ap-uuid`,
2773         `apcontact`.`type` AS `ap-type`,
2774         `apcontact`.`following` AS `ap-following`,
2775         `apcontact`.`followers` AS `ap-followers`,
2776         `apcontact`.`inbox` AS `ap-inbox`,
2777         `apcontact`.`outbox` AS `ap-outbox`,
2778         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2779         `apcontact`.`generator` AS `ap-generator`,
2780         `apcontact`.`following_count` AS `ap-following_count`,
2781         `apcontact`.`followers_count` AS `ap-followers_count`,
2782         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2783         `gserver`.`site_name` AS `site_name`,
2784         `gserver`.`platform` AS `platform`,
2785         `gserver`.`version` AS `version`
2786         FROM `contact`
2787                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
2788                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
2789                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
2790                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`
2791                         WHERE `contact`.`uid` = 0;
2792
2793 --
2794 -- VIEW account-user-view
2795 --
2796 DROP VIEW IF EXISTS `account-user-view`;
2797 CREATE VIEW `account-user-view` AS SELECT 
2798         `ucontact`.`id` AS `id`,
2799         `contact`.`id` AS `pid`,
2800         `ucontact`.`uid` AS `uid`,
2801         `contact`.`url` AS `url`,
2802         `contact`.`nurl` AS `nurl`,
2803         `contact`.`uri-id` AS `uri-id`,
2804         `item-uri`.`guid` AS `guid`,
2805         `contact`.`addr` AS `addr`,
2806         `contact`.`alias` AS `alias`,
2807         `contact`.`name` AS `name`,
2808         `contact`.`nick` AS `nick`,
2809         `contact`.`about` AS `about`,
2810         `contact`.`keywords` AS `keywords`,
2811         `contact`.`xmpp` AS `xmpp`,
2812         `contact`.`matrix` AS `matrix`,
2813         `contact`.`avatar` AS `avatar`,
2814         `contact`.`photo` AS `photo`,
2815         `contact`.`thumb` AS `thumb`,
2816         `contact`.`micro` AS `micro`,
2817         `contact`.`header` AS `header`,
2818         `contact`.`created` AS `created`,
2819         `contact`.`updated` AS `updated`,
2820         `ucontact`.`self` AS `self`,
2821         `ucontact`.`remote_self` AS `remote_self`,
2822         `ucontact`.`rel` AS `rel`,
2823         `contact`.`network` AS `network`,
2824         `ucontact`.`protocol` AS `protocol`,
2825         `contact`.`location` AS `location`,
2826         `ucontact`.`attag` AS `attag`,
2827         `contact`.`pubkey` AS `pubkey`,
2828         `contact`.`prvkey` AS `prvkey`,
2829         `contact`.`subscribe` AS `subscribe`,
2830         `contact`.`last-update` AS `last-update`,
2831         `contact`.`success_update` AS `success_update`,
2832         `contact`.`failure_update` AS `failure_update`,
2833         `contact`.`failed` AS `failed`,
2834         `contact`.`last-item` AS `last-item`,
2835         `contact`.`last-discovery` AS `last-discovery`,
2836         `contact`.`contact-type` AS `contact-type`,
2837         `contact`.`manually-approve` AS `manually-approve`,
2838         `contact`.`unsearchable` AS `unsearchable`,
2839         `contact`.`sensitive` AS `sensitive`,
2840         `contact`.`baseurl` AS `baseurl`,
2841         `contact`.`gsid` AS `gsid`,
2842         `ucontact`.`info` AS `info`,
2843         `contact`.`bdyear` AS `bdyear`,
2844         `contact`.`bd` AS `bd`,
2845         `contact`.`poco` AS `poco`,
2846         `contact`.`name-date` AS `name-date`,
2847         `contact`.`uri-date` AS `uri-date`,
2848         `contact`.`avatar-date` AS `avatar-date`,
2849         `contact`.`term-date` AS `term-date`,
2850         `contact`.`hidden` AS `global-ignored`,
2851         `contact`.`blocked` AS `global-blocked`,
2852         `ucontact`.`hidden` AS `hidden`,
2853         `ucontact`.`archive` AS `archive`,
2854         `ucontact`.`pending` AS `pending`,
2855         `ucontact`.`deleted` AS `deleted`,
2856         `ucontact`.`notify_new_posts` AS `notify_new_posts`,
2857         `ucontact`.`fetch_further_information` AS `fetch_further_information`,
2858         `ucontact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2859         `ucontact`.`rating` AS `rating`,
2860         `ucontact`.`readonly` AS `readonly`,
2861         `ucontact`.`blocked` AS `blocked`,
2862         `ucontact`.`block_reason` AS `block_reason`,
2863         `ucontact`.`subhub` AS `subhub`,
2864         `ucontact`.`hub-verify` AS `hub-verify`,
2865         `ucontact`.`reason` AS `reason`,
2866         `contact`.`notify` AS `dfrn-notify`,
2867         `contact`.`poll` AS `dfrn-poll`,
2868         `fcontact`.`guid` AS `diaspora-guid`,
2869         `fcontact`.`batch` AS `diaspora-batch`,
2870         `fcontact`.`notify` AS `diaspora-notify`,
2871         `fcontact`.`poll` AS `diaspora-poll`,
2872         `fcontact`.`alias` AS `diaspora-alias`,
2873         `fcontact`.`interacting_count` AS `diaspora-interacting_count`,
2874         `fcontact`.`interacted_count` AS `diaspora-interacted_count`,
2875         `fcontact`.`post_count` AS `diaspora-post_count`,
2876         `apcontact`.`uuid` AS `ap-uuid`,
2877         `apcontact`.`type` AS `ap-type`,
2878         `apcontact`.`following` AS `ap-following`,
2879         `apcontact`.`followers` AS `ap-followers`,
2880         `apcontact`.`inbox` AS `ap-inbox`,
2881         `apcontact`.`outbox` AS `ap-outbox`,
2882         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2883         `apcontact`.`generator` AS `ap-generator`,
2884         `apcontact`.`following_count` AS `ap-following_count`,
2885         `apcontact`.`followers_count` AS `ap-followers_count`,
2886         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2887         `gserver`.`site_name` AS `site_name`,
2888         `gserver`.`platform` AS `platform`,
2889         `gserver`.`version` AS `version`
2890         FROM `contact` AS `ucontact`
2891                         INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
2892                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
2893                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
2894                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr'
2895                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`;
2896
2897 --
2898 -- VIEW pending-view
2899 --
2900 DROP VIEW IF EXISTS `pending-view`;
2901 CREATE VIEW `pending-view` AS SELECT 
2902         `register`.`id` AS `id`,
2903         `register`.`hash` AS `hash`,
2904         `register`.`created` AS `created`,
2905         `register`.`uid` AS `uid`,
2906         `register`.`password` AS `password`,
2907         `register`.`language` AS `language`,
2908         `register`.`note` AS `note`,
2909         `contact`.`self` AS `self`,
2910         `contact`.`name` AS `name`,
2911         `contact`.`url` AS `url`,
2912         `contact`.`micro` AS `micro`,
2913         `user`.`email` AS `email`,
2914         `contact`.`nick` AS `nick`
2915         FROM `register`
2916                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2917                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2918
2919 --
2920 -- VIEW tag-search-view
2921 --
2922 DROP VIEW IF EXISTS `tag-search-view`;
2923 CREATE VIEW `tag-search-view` AS SELECT 
2924         `post-tag`.`uri-id` AS `uri-id`,
2925         `post-user`.`uid` AS `uid`,
2926         `post-user`.`id` AS `iid`,
2927         `post-user`.`private` AS `private`,
2928         `post-user`.`wall` AS `wall`,
2929         `post-user`.`origin` AS `origin`,
2930         `post-user`.`global` AS `global`,
2931         `post-user`.`gravity` AS `gravity`,
2932         `post-user`.`received` AS `received`,
2933         `post-user`.`network` AS `network`,
2934         `post-user`.`author-id` AS `author-id`,
2935         `tag`.`name` AS `name`
2936         FROM `post-tag`
2937                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2938                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2939                         WHERE `post-tag`.`type` = 1;
2940
2941 --
2942 -- VIEW workerqueue-view
2943 --
2944 DROP VIEW IF EXISTS `workerqueue-view`;
2945 CREATE VIEW `workerqueue-view` AS SELECT 
2946         `process`.`pid` AS `pid`,
2947         `workerqueue`.`priority` AS `priority`
2948         FROM `process`
2949                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2950                         WHERE NOT `workerqueue`.`done`;
2951
2952 --
2953 -- VIEW profile_field-view
2954 --
2955 DROP VIEW IF EXISTS `profile_field-view`;
2956 CREATE VIEW `profile_field-view` AS SELECT 
2957         `profile_field`.`id` AS `id`,
2958         `profile_field`.`uid` AS `uid`,
2959         `profile_field`.`label` AS `label`,
2960         `profile_field`.`value` AS `value`,
2961         `profile_field`.`order` AS `order`,
2962         `profile_field`.`psid` AS `psid`,
2963         `permissionset`.`allow_cid` AS `allow_cid`,
2964         `permissionset`.`allow_gid` AS `allow_gid`,
2965         `permissionset`.`deny_cid` AS `deny_cid`,
2966         `permissionset`.`deny_gid` AS `deny_gid`,
2967         `profile_field`.`created` AS `created`,
2968         `profile_field`.`edited` AS `edited`
2969         FROM `profile_field`
2970                         INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`;