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