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