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