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