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