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