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