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