]> git.mxchange.org Git - friendica.git/blob - database.sql
Compare with lowered tags
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2024.03-dev (Yellow Archangel)
3 -- DB_UPDATE_VERSION 1546
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         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
77         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
78         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
79         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
80         `pwdreset` varchar(255) COMMENT 'Password reset request token',
81         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
82         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
83         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT 'Delay in days before deleting user-related posts. Scope is controlled by pConfig.',
84         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
85         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
86         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
87         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
88         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
89         `allow_cid` mediumtext COMMENT 'default permission for this user',
90         `allow_gid` mediumtext COMMENT 'default permission for this user',
91         `deny_cid` mediumtext COMMENT 'default permission for this user',
92         `deny_gid` mediumtext COMMENT 'default permission for this user',
93         `openidserver` text COMMENT '',
94          PRIMARY KEY(`uid`),
95          INDEX `nickname` (`nickname`(32)),
96          INDEX `parent-uid` (`parent-uid`),
97          INDEX `guid` (`guid`),
98          INDEX `email` (`email`(64)),
99         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
100 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
101
102 --
103 -- TABLE user-gserver
104 --
105 CREATE TABLE IF NOT EXISTS `user-gserver` (
106         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
107         `gsid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Gserver id',
108         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'server accounts are ignored for the user',
109          PRIMARY KEY(`uid`,`gsid`),
110          INDEX `gsid` (`gsid`),
111         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
112         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
113 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User settings about remote servers';
114
115 --
116 -- TABLE item-uri
117 --
118 CREATE TABLE IF NOT EXISTS `item-uri` (
119         `id` int unsigned NOT NULL auto_increment,
120         `uri` varbinary(383) NOT NULL COMMENT 'URI of an item',
121         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
122          PRIMARY KEY(`id`),
123          UNIQUE INDEX `uri` (`uri`),
124          INDEX `guid` (`guid`)
125 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
126
127 --
128 -- TABLE contact
129 --
130 CREATE TABLE IF NOT EXISTS `contact` (
131         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
132         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
133         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
134         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
135         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
136         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
137         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
138         `location` varchar(255) DEFAULT '' COMMENT '',
139         `about` text COMMENT '',
140         `keywords` text COMMENT 'public keywords (interests) of the contact',
141         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
142         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
143         `avatar` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
144         `blurhash` varbinary(255) COMMENT 'BlurHash representation of the avatar',
145         `header` varbinary(383) COMMENT 'Header picture',
146         `url` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
147         `nurl` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
148         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
149         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
150         `alias` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
151         `pubkey` text COMMENT 'RSA public key 4096 bit',
152         `prvkey` text COMMENT 'RSA private key 4096 bit',
153         `batch` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
154         `notify` varbinary(383) COMMENT '',
155         `poll` varbinary(383) COMMENT '',
156         `subscribe` varbinary(383) COMMENT '',
157         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
158         `next-update` datetime COMMENT 'Next connection request',
159         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
160         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
161         `failed` boolean COMMENT 'Connection failed',
162         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
163         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
164         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
165         `local-data` boolean COMMENT 'Is true when there are posts with this contact on the system',
166         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
167         `block_reason` text COMMENT 'Node-wide block reason',
168         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
169         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay',
170         `manually-approve` boolean COMMENT 'Contact requests have to be approved manually',
171         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
172         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
173         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
174         `baseurl` varbinary(383) DEFAULT '' COMMENT 'baseurl of the contact from the gserver record, can be missing',
175         `gsid` int unsigned COMMENT 'Global Server ID, can be missing',
176         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
177         `reason` text COMMENT '',
178         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
179         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
180         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
181         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
182         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
183         `hub-verify` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
184         `rating` tinyint NOT NULL DEFAULT 0 COMMENT 'Automatically detected feed poll frequency',
185         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Feed poll priority',
186         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
187         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
188         `pending` boolean NOT NULL DEFAULT '1' COMMENT 'Contact request is pending',
189         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
190         `info` mediumtext COMMENT '',
191         `notify_new_posts` boolean NOT NULL DEFAULT '0' COMMENT '',
192         `fetch_further_information` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
193         `ffi_keyword_blacklist` text COMMENT '',
194         `photo` varbinary(383) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
195         `thumb` varbinary(383) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
196         `micro` varbinary(383) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
197         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
198         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
199         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
200         `request` varbinary(383) COMMENT '',
201         `confirm` varbinary(383) COMMENT '',
202         `poco` varbinary(383) COMMENT '',
203         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
204         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a group. Deprecated, use \'contact-type\' = \'community\' and \'manually-approve\' = false instead',
205         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group. Deprecated, use \'contact-type\' = \'community\' and \'manually-approve\' = true instead',
206         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
207         `site-pubkey` text COMMENT 'Deprecated',
208         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
209         `duplex` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
210         `issued-id` varbinary(383) NOT NULL DEFAULT '' COMMENT 'Deprecated',
211         `dfrn-id` varbinary(383) NOT NULL DEFAULT '' COMMENT 'Deprecated',
212         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
213         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
214         `usehub` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
215         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT 'Deprecated',
216         `profile-id` int unsigned COMMENT 'Deprecated',
217          PRIMARY KEY(`id`),
218          INDEX `uid_name` (`uid`,`name`(190)),
219          INDEX `self_uid` (`self`,`uid`),
220          INDEX `alias_uid` (`alias`(128),`uid`),
221          INDEX `pending_uid` (`pending`,`uid`),
222          INDEX `blocked_uid` (`blocked`,`uid`),
223          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
224          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
225          INDEX `batch_contact-type` (`batch`(64),`contact-type`),
226          INDEX `addr_uid` (`addr`(128),`uid`),
227          INDEX `nurl_uid` (`nurl`(128),`uid`),
228          INDEX `nick_uid` (`nick`(128),`uid`),
229          INDEX `attag_uid` (`attag`(96),`uid`),
230          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
231          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
232          INDEX `next-update` (`next-update`),
233          INDEX `local-data-next-update` (`local-data`,`next-update`),
234          INDEX `uid_lastitem` (`uid`,`last-item`),
235          INDEX `baseurl` (`baseurl`(64)),
236          INDEX `uid_contact-type` (`uid`,`contact-type`),
237          INDEX `uid_self_contact-type` (`uid`,`self`,`contact-type`),
238          INDEX `self_network_uid` (`self`,`network`,`uid`),
239          INDEX `gsid_uid_failed` (`gsid`,`uid`,`failed`),
240          INDEX `uri-id` (`uri-id`),
241         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
242         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
243         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
244 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
245
246 --
247 -- TABLE tag
248 --
249 CREATE TABLE IF NOT EXISTS `tag` (
250         `id` int unsigned NOT NULL auto_increment COMMENT '',
251         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
252         `url` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
253         `type` tinyint unsigned COMMENT 'Type of the tag (Unknown, General Collection, Follower Collection or Account)',
254          PRIMARY KEY(`id`),
255          UNIQUE INDEX `type_name_url` (`name`,`url`),
256          INDEX `url` (`url`)
257 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
258
259 --
260 -- TABLE permissionset
261 --
262 CREATE TABLE IF NOT EXISTS `permissionset` (
263         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
264         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
265         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
266         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed circles',
267         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
268         `deny_gid` mediumtext COMMENT 'Access Control - list of denied circles',
269          PRIMARY KEY(`id`),
270          INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`uid`,`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)),
271         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
272 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
273
274 --
275 -- TABLE verb
276 --
277 CREATE TABLE IF NOT EXISTS `verb` (
278         `id` smallint unsigned NOT NULL auto_increment,
279         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
280          PRIMARY KEY(`id`),
281          INDEX `name` (`name`)
282 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
283
284 --
285 -- TABLE 2fa_app_specific_password
286 --
287 CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
288         `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
289         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
290         `description` varchar(255) COMMENT 'Description of the usage of the password',
291         `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
292         `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
293         `last_used` datetime COMMENT 'Datetime the password was last used',
294          PRIMARY KEY(`id`),
295          INDEX `uid_description` (`uid`,`description`(190)),
296         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
297 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
298
299 --
300 -- TABLE 2fa_recovery_codes
301 --
302 CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` (
303         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
304         `code` varchar(50) NOT NULL COMMENT 'Recovery code string',
305         `generated` datetime NOT NULL COMMENT 'Datetime the code was generated',
306         `used` datetime COMMENT 'Datetime the code was used',
307          PRIMARY KEY(`uid`,`code`),
308         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
309 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes';
310
311 --
312 -- TABLE 2fa_trusted_browser
313 --
314 CREATE TABLE IF NOT EXISTS `2fa_trusted_browser` (
315         `cookie_hash` varchar(80) NOT NULL COMMENT 'Trusted cookie hash',
316         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
317         `user_agent` text COMMENT 'User agent string',
318         `trusted` boolean NOT NULL DEFAULT '1' COMMENT 'Whenever this browser should be trusted or not',
319         `created` datetime NOT NULL COMMENT 'Datetime the trusted browser was recorded',
320         `last_used` datetime COMMENT 'Datetime the trusted browser was last used',
321          PRIMARY KEY(`cookie_hash`),
322          INDEX `uid` (`uid`),
323         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
324 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication trusted browsers';
325
326 --
327 -- TABLE account-suggestion
328 --
329 CREATE TABLE IF NOT EXISTS `account-suggestion` (
330         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the account url',
331         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
332         `level` smallint unsigned COMMENT 'level of closeness',
333         `ignore` boolean NOT NULL DEFAULT '0' COMMENT 'If set, this account will not be suggested again',
334          PRIMARY KEY(`uid`,`uri-id`),
335          INDEX `uri-id_uid` (`uri-id`,`uid`),
336         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
337         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
338 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Account suggestion';
339
340 --
341 -- TABLE account-user
342 --
343 CREATE TABLE IF NOT EXISTS `account-user` (
344         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
345         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the account url',
346         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
347          PRIMARY KEY(`id`),
348          UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
349          INDEX `uid_uri-id` (`uid`,`uri-id`),
350         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
351         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
352 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Remote and local accounts';
353
354 --
355 -- TABLE apcontact
356 --
357 CREATE TABLE IF NOT EXISTS `apcontact` (
358         `url` varbinary(383) NOT NULL COMMENT 'URL of the contact',
359         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the apcontact url',
360         `uuid` varbinary(255) COMMENT '',
361         `type` varchar(20) NOT NULL COMMENT '',
362         `following` varbinary(383) COMMENT '',
363         `followers` varbinary(383) COMMENT '',
364         `inbox` varbinary(383) NOT NULL COMMENT '',
365         `outbox` varbinary(383) COMMENT '',
366         `sharedinbox` varbinary(383) COMMENT '',
367         `featured` varbinary(383) COMMENT 'Address for the collection of featured posts',
368         `featured-tags` varbinary(383) COMMENT 'Address for the collection of featured tags',
369         `manually-approve` boolean COMMENT '',
370         `discoverable` boolean COMMENT 'Mastodon extension: true if profile is published in their directory',
371         `suspended` boolean COMMENT 'Mastodon extension: true if profile is suspended',
372         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
373         `name` varchar(255) COMMENT '',
374         `about` text COMMENT '',
375         `xmpp` varchar(255) COMMENT 'XMPP address',
376         `matrix` varchar(255) COMMENT 'Matrix address',
377         `photo` varbinary(383) COMMENT '',
378         `header` varbinary(383) COMMENT 'Header picture',
379         `addr` varchar(255) COMMENT '',
380         `alias` varbinary(383) COMMENT '',
381         `pubkey` text COMMENT '',
382         `subscribe` varbinary(383) COMMENT '',
383         `baseurl` varbinary(383) COMMENT 'baseurl of the ap contact',
384         `gsid` int unsigned COMMENT 'Global Server ID',
385         `generator` varchar(255) COMMENT 'Name of the contact\'s system',
386         `following_count` int unsigned DEFAULT 0 COMMENT 'Number of following contacts',
387         `followers_count` int unsigned DEFAULT 0 COMMENT 'Number of followers',
388         `statuses_count` int unsigned DEFAULT 0 COMMENT 'Number of posts',
389         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
390          PRIMARY KEY(`url`),
391          INDEX `addr` (`addr`(32)),
392          INDEX `alias` (`alias`(190)),
393          INDEX `followers` (`followers`(190)),
394          INDEX `baseurl` (`baseurl`(190)),
395          INDEX `sharedinbox` (`sharedinbox`(190)),
396          INDEX `gsid` (`gsid`),
397          UNIQUE INDEX `uri-id` (`uri-id`),
398         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
399         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
400 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
401
402 --
403 -- TABLE application
404 --
405 CREATE TABLE IF NOT EXISTS `application` (
406         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
407         `client_id` varchar(64) NOT NULL COMMENT '',
408         `client_secret` varchar(64) NOT NULL COMMENT '',
409         `name` varchar(255) NOT NULL COMMENT '',
410         `redirect_uri` varbinary(383) NOT NULL COMMENT '',
411         `website` varbinary(383) COMMENT '',
412         `scopes` varchar(255) COMMENT '',
413         `read` boolean COMMENT 'Read scope',
414         `write` boolean COMMENT 'Write scope',
415         `follow` boolean COMMENT 'Follow scope',
416         `push` boolean COMMENT 'Push scope',
417          PRIMARY KEY(`id`),
418          UNIQUE INDEX `client_id` (`client_id`)
419 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application';
420
421 --
422 -- TABLE application-marker
423 --
424 CREATE TABLE IF NOT EXISTS `application-marker` (
425         `application-id` int unsigned NOT NULL COMMENT '',
426         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
427         `timeline` varchar(64) NOT NULL COMMENT 'Marker (home, notifications)',
428         `last_read_id` varbinary(383) COMMENT 'Marker id for the timeline',
429         `version` smallint unsigned COMMENT 'Version number',
430         `updated_at` datetime COMMENT 'creation time',
431          PRIMARY KEY(`application-id`,`uid`,`timeline`),
432          INDEX `uid_id` (`uid`),
433         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
434         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
435 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Timeline marker';
436
437 --
438 -- TABLE application-token
439 --
440 CREATE TABLE IF NOT EXISTS `application-token` (
441         `application-id` int unsigned NOT NULL COMMENT '',
442         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
443         `code` varchar(64) NOT NULL COMMENT '',
444         `access_token` varchar(64) NOT NULL COMMENT '',
445         `created_at` datetime NOT NULL COMMENT 'creation time',
446         `scopes` varchar(255) COMMENT '',
447         `read` boolean COMMENT 'Read scope',
448         `write` boolean COMMENT 'Write scope',
449         `follow` boolean COMMENT 'Follow scope',
450         `push` boolean COMMENT 'Push scope',
451          PRIMARY KEY(`application-id`,`uid`),
452          INDEX `uid_id` (`uid`,`application-id`),
453         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
454         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
455 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth user token';
456
457 --
458 -- TABLE attach
459 --
460 CREATE TABLE IF NOT EXISTS `attach` (
461         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
462         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
463         `hash` varchar(64) NOT NULL DEFAULT '' COMMENT 'hash',
464         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'filename of original',
465         `filetype` varchar(64) NOT NULL DEFAULT '' COMMENT 'mimetype',
466         `filesize` int unsigned NOT NULL DEFAULT 0 COMMENT 'size in bytes',
467         `data` longblob NOT NULL COMMENT 'file data',
468         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
469         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
470         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>',
471         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed circles',
472         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
473         `deny_gid` mediumtext COMMENT 'Access Control - list of denied circles',
474         `backend-class` tinytext COMMENT 'Storage backend class',
475         `backend-ref` text COMMENT 'Storage backend data reference',
476          PRIMARY KEY(`id`),
477          INDEX `uid` (`uid`),
478         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
479 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='file attachments';
480
481 --
482 -- TABLE cache
483 --
484 CREATE TABLE IF NOT EXISTS `cache` (
485         `k` varchar(255) NOT NULL COMMENT 'cache key',
486         `v` mediumtext COMMENT 'cached serialized value',
487         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
488         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
489          PRIMARY KEY(`k`),
490          INDEX `k_expires` (`k`,`expires`)
491 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
492
493 --
494 -- TABLE channel
495 --
496 CREATE TABLE IF NOT EXISTS `channel` (
497         `id` int unsigned NOT NULL auto_increment COMMENT '',
498         `uid` mediumint unsigned NOT NULL COMMENT 'User id',
499         `label` varchar(64) NOT NULL COMMENT 'Channel label',
500         `description` varchar(64) COMMENT 'Channel description',
501         `circle` int COMMENT 'Circle or channel that this channel is based on',
502         `access-key` varchar(1) COMMENT 'Access key',
503         `include-tags` varchar(1023) COMMENT 'Comma separated list of tags that will be included in the channel',
504         `exclude-tags` varchar(1023) COMMENT 'Comma separated list of tags that aren\'t allowed in the channel',
505         `full-text-search` varchar(1023) COMMENT 'Full text search pattern, see https://mariadb.com/kb/en/full-text-index-overview/#in-boolean-mode',
506         `media-type` smallint unsigned COMMENT 'Filtered media types',
507         `languages` mediumtext COMMENT 'Desired languages',
508         `publish` boolean COMMENT 'publish channel content',
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_blacklist` 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-counts-view
2030 --
2031 DROP VIEW IF EXISTS `post-counts-view`;
2032 CREATE VIEW `post-counts-view` AS SELECT 
2033         `post-counts`.`uri-id` AS `uri-id`,
2034         `post-counts`.`vid` AS `vid`,
2035         `verb`.`name` AS `verb`,
2036         `post-counts`.`reaction` AS `reaction`,
2037         `post-counts`.`parent-uri-id` AS `parent-uri-id`,
2038         `post-counts`.`count` AS `count`
2039         FROM `post-counts`
2040                         INNER JOIN `verb` ON `verb`.`id` = `post-counts`.`vid`;
2041
2042 --
2043 -- VIEW post-timeline-view
2044 --
2045 DROP VIEW IF EXISTS `post-timeline-view`;
2046 CREATE VIEW `post-timeline-view` AS SELECT 
2047         `post-user`.`uid` AS `uid`,
2048         `post-user`.`uri-id` AS `uri-id`,
2049         `post-user`.`gravity` AS `gravity`,
2050         `post-user`.`created` AS `created`,
2051         `post-user`.`edited` AS `edited`,
2052         `post-thread-user`.`commented` AS `commented`,
2053         `post-user`.`received` AS `received`,
2054         `post-thread-user`.`changed` AS `changed`,
2055         `post-user`.`private` AS `private`,
2056         `post-user`.`visible` AS `visible`,
2057         `post-user`.`deleted` AS `deleted`,
2058         `post-user`.`origin` AS `origin`,
2059         `post-user`.`global` AS `global`,
2060         `post-user`.`network` AS `network`,
2061         `post-user`.`protocol` AS `protocol`,
2062         `post-user`.`vid` AS `vid`,
2063         `post-user`.`contact-id` AS `contact-id`,
2064         `contact`.`blocked` AS `contact-blocked`,
2065         `contact`.`readonly` AS `contact-readonly`,
2066         `contact`.`pending` AS `contact-pending`,
2067         `contact`.`rel` AS `contact-rel`,
2068         `contact`.`uid` AS `contact-uid`,
2069         `contact`.`self` AS `self`,
2070         `post-user`.`author-id` AS `author-id`,
2071         `author`.`blocked` AS `author-blocked`,
2072         `author`.`hidden` AS `author-hidden`,
2073         `author`.`gsid` AS `author-gsid`,
2074         `post-user`.`owner-id` AS `owner-id`,
2075         `owner`.`blocked` AS `owner-blocked`,
2076         `owner`.`gsid` AS `owner-gsid`,
2077         `post-user`.`causer-id` AS `causer-id`,
2078         `causer`.`blocked` AS `causer-blocked`,
2079         `causer`.`gsid` AS `causer-gsid`
2080         FROM `post-user`
2081                         LEFT JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
2082                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
2083                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
2084                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
2085                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`;
2086
2087 --
2088 -- VIEW post-user-view
2089 --
2090 DROP VIEW IF EXISTS `post-user-view`;
2091 CREATE VIEW `post-user-view` AS SELECT 
2092         `post-user`.`id` AS `id`,
2093         `post-user`.`id` AS `post-user-id`,
2094         `post-user`.`uid` AS `uid`,
2095         `post-thread-user`.`post-user-id` AS `parent`,
2096         `item-uri`.`uri` AS `uri`,
2097         `post-user`.`uri-id` AS `uri-id`,
2098         `parent-item-uri`.`uri` AS `parent-uri`,
2099         `post-user`.`parent-uri-id` AS `parent-uri-id`,
2100         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2101         `post-user`.`thr-parent-id` AS `thr-parent-id`,
2102         `conversation-item-uri`.`uri` AS `conversation`,
2103         `post-thread-user`.`conversation-id` AS `conversation-id`,
2104         `quote-item-uri`.`uri` AS `quote-uri`,
2105         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2106         `item-uri`.`guid` AS `guid`,
2107         `post-user`.`wall` AS `wall`,
2108         `post-user`.`gravity` AS `gravity`,
2109         `external-item-uri`.`uri` AS `extid`,
2110         `post-user`.`external-id` AS `external-id`,
2111         `post-user`.`created` AS `created`,
2112         `post-user`.`edited` AS `edited`,
2113         `post-thread-user`.`commented` AS `commented`,
2114         `post-user`.`received` AS `received`,
2115         `post-thread-user`.`changed` AS `changed`,
2116         `post-user`.`post-type` AS `post-type`,
2117         `post-user`.`post-reason` AS `post-reason`,
2118         `post-user`.`private` AS `private`,
2119         `post-thread-user`.`pubmail` AS `pubmail`,
2120         `post-user`.`visible` AS `visible`,
2121         `post-thread-user`.`starred` AS `starred`,
2122         `post-user`.`unseen` AS `unseen`,
2123         `post-user`.`deleted` AS `deleted`,
2124         `post-user`.`origin` AS `origin`,
2125         `post-thread-user`.`origin` AS `parent-origin`,
2126         `post-thread-user`.`mention` AS `mention`,
2127         `post-user`.`global` AS `global`,
2128         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
2129         `post-user`.`network` AS `network`,
2130         `post-user`.`protocol` AS `protocol`,
2131         `post-user`.`vid` AS `vid`,
2132         `post-user`.`psid` AS `psid`,
2133         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2134         `post-content`.`title` AS `title`,
2135         `post-content`.`content-warning` AS `content-warning`,
2136         `post-content`.`raw-body` AS `raw-body`,
2137         IFNULL (`post-content`.`body`, '') AS `body`,
2138         `post-content`.`rendered-hash` AS `rendered-hash`,
2139         `post-content`.`rendered-html` AS `rendered-html`,
2140         `post-content`.`language` AS `language`,
2141         `post-content`.`plink` AS `plink`,
2142         `post-content`.`location` AS `location`,
2143         `post-content`.`coord` AS `coord`,
2144         `post-content`.`app` AS `app`,
2145         `post-content`.`object-type` AS `object-type`,
2146         `post-content`.`object` AS `object`,
2147         `post-content`.`target-type` AS `target-type`,
2148         `post-content`.`target` AS `target`,
2149         `post-content`.`resource-id` AS `resource-id`,
2150         `post-user`.`contact-id` AS `contact-id`,
2151         `contact`.`uri-id` AS `contact-uri-id`,
2152         `contact`.`url` AS `contact-link`,
2153         `contact`.`addr` AS `contact-addr`,
2154         `contact`.`name` AS `contact-name`,
2155         `contact`.`nick` AS `contact-nick`,
2156         `contact`.`thumb` AS `contact-avatar`,
2157         `contact`.`network` AS `contact-network`,
2158         `contact`.`blocked` AS `contact-blocked`,
2159         `contact`.`hidden` AS `contact-hidden`,
2160         `contact`.`readonly` AS `contact-readonly`,
2161         `contact`.`archive` AS `contact-archive`,
2162         `contact`.`pending` AS `contact-pending`,
2163         `contact`.`rel` AS `contact-rel`,
2164         `contact`.`uid` AS `contact-uid`,
2165         `contact`.`contact-type` AS `contact-contact-type`,
2166         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
2167         `contact`.`self` AS `self`,
2168         `contact`.`id` AS `cid`,
2169         `contact`.`alias` AS `alias`,
2170         `contact`.`photo` AS `photo`,
2171         `contact`.`name-date` AS `name-date`,
2172         `contact`.`uri-date` AS `uri-date`,
2173         `contact`.`avatar-date` AS `avatar-date`,
2174         `contact`.`thumb` AS `thumb`,
2175         `post-user`.`author-id` AS `author-id`,
2176         `author`.`uri-id` AS `author-uri-id`,
2177         `author`.`url` AS `author-link`,
2178         `author`.`addr` AS `author-addr`,
2179         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
2180         `author`.`nick` AS `author-nick`,
2181         `author`.`alias` AS `author-alias`,
2182         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
2183         `author`.`network` AS `author-network`,
2184         `author`.`blocked` AS `author-blocked`,
2185         `author`.`hidden` AS `author-hidden`,
2186         `author`.`updated` AS `author-updated`,
2187         `author`.`contact-type` AS `author-contact-type`,
2188         `author`.`gsid` AS `author-gsid`,
2189         `author`.`baseurl` AS `author-baseurl`,
2190         `post-user`.`owner-id` AS `owner-id`,
2191         `owner`.`uri-id` AS `owner-uri-id`,
2192         `owner`.`url` AS `owner-link`,
2193         `owner`.`addr` AS `owner-addr`,
2194         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
2195         `owner`.`nick` AS `owner-nick`,
2196         `owner`.`alias` AS `owner-alias`,
2197         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
2198         `owner`.`network` AS `owner-network`,
2199         `owner`.`blocked` AS `owner-blocked`,
2200         `owner`.`hidden` AS `owner-hidden`,
2201         `owner`.`updated` AS `owner-updated`,
2202         `owner`.`gsid` AS `owner-gsid`,
2203         `owner`.`contact-type` AS `owner-contact-type`,
2204         `post-user`.`causer-id` AS `causer-id`,
2205         `causer`.`uri-id` AS `causer-uri-id`,
2206         `causer`.`url` AS `causer-link`,
2207         `causer`.`addr` AS `causer-addr`,
2208         `causer`.`name` AS `causer-name`,
2209         `causer`.`nick` AS `causer-nick`,
2210         `causer`.`alias` AS `causer-alias`,
2211         `causer`.`thumb` AS `causer-avatar`,
2212         `causer`.`network` AS `causer-network`,
2213         `causer`.`blocked` AS `causer-blocked`,
2214         `causer`.`hidden` AS `causer-hidden`,
2215         `causer`.`gsid` AS `causer-gsid`,
2216         `causer`.`contact-type` AS `causer-contact-type`,
2217         `post-delivery-data`.`postopts` AS `postopts`,
2218         `post-delivery-data`.`inform` AS `inform`,
2219         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
2220         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
2221         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
2222         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
2223         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
2224         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
2225         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
2226         `post-user`.`event-id` AS `event-id`,
2227         `event`.`created` AS `event-created`,
2228         `event`.`edited` AS `event-edited`,
2229         `event`.`start` AS `event-start`,
2230         `event`.`finish` AS `event-finish`,
2231         `event`.`summary` AS `event-summary`,
2232         `event`.`desc` AS `event-desc`,
2233         `event`.`location` AS `event-location`,
2234         `event`.`type` AS `event-type`,
2235         `event`.`nofinish` AS `event-nofinish`,
2236         `event`.`ignore` AS `event-ignore`,
2237         `post-question`.`id` AS `question-id`,
2238         `post-question`.`multiple` AS `question-multiple`,
2239         `post-question`.`voters` AS `question-voters`,
2240         `post-question`.`end-time` AS `question-end-time`,
2241         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`,
2242         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-user`.`uri-id`) AS `has-media`,
2243         `diaspora-interaction`.`interaction` AS `signed_text`,
2244         `parent-item-uri`.`guid` AS `parent-guid`,
2245         `post-thread-user`.`network` AS `parent-network`,
2246         `post-thread-user`.`author-id` AS `parent-author-id`,
2247         `parent-post-author`.`url` AS `parent-author-link`,
2248         `parent-post-author`.`name` AS `parent-author-name`,
2249         `parent-post-author`.`nick` AS `parent-author-nick`,
2250         `parent-post-author`.`network` AS `parent-author-network`
2251         FROM `post-user`
2252                         INNER JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
2253                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
2254                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
2255                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
2256                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
2257                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
2258                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
2259                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
2260                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
2261                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
2262                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
2263                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
2264                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
2265                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
2266                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2267                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
2268                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
2269                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
2270                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `post-thread-user`.`author-id`;
2271
2272 --
2273 -- VIEW post-thread-user-view
2274 --
2275 DROP VIEW IF EXISTS `post-thread-user-view`;
2276 CREATE VIEW `post-thread-user-view` AS SELECT 
2277         `post-user`.`id` AS `id`,
2278         `post-user`.`id` AS `post-user-id`,
2279         `post-thread-user`.`uid` AS `uid`,
2280         `post-thread-user`.`post-user-id` AS `parent`,
2281         `item-uri`.`uri` AS `uri`,
2282         `post-thread-user`.`uri-id` AS `uri-id`,
2283         `parent-item-uri`.`uri` AS `parent-uri`,
2284         `post-user`.`parent-uri-id` AS `parent-uri-id`,
2285         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2286         `post-user`.`thr-parent-id` AS `thr-parent-id`,
2287         `conversation-item-uri`.`uri` AS `conversation`,
2288         `post-thread-user`.`conversation-id` AS `conversation-id`,
2289         `quote-item-uri`.`uri` AS `quote-uri`,
2290         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2291         `item-uri`.`guid` AS `guid`,
2292         `post-thread-user`.`wall` AS `wall`,
2293         `post-user`.`gravity` AS `gravity`,
2294         `external-item-uri`.`uri` AS `extid`,
2295         `post-user`.`external-id` AS `external-id`,
2296         `post-thread-user`.`created` AS `created`,
2297         `post-user`.`edited` AS `edited`,
2298         `post-thread-user`.`commented` AS `commented`,
2299         `post-thread-user`.`received` AS `received`,
2300         `post-thread-user`.`changed` AS `changed`,
2301         `post-user`.`post-type` AS `post-type`,
2302         `post-user`.`post-reason` AS `post-reason`,
2303         `post-user`.`private` AS `private`,
2304         `post-thread-user`.`pubmail` AS `pubmail`,
2305         `post-thread-user`.`ignored` AS `ignored`,
2306         `post-user`.`visible` AS `visible`,
2307         `post-thread-user`.`starred` AS `starred`,
2308         `post-thread-user`.`unseen` AS `unseen`,
2309         `post-user`.`deleted` AS `deleted`,
2310         `post-thread-user`.`origin` AS `origin`,
2311         `post-thread-user`.`mention` AS `mention`,
2312         `post-user`.`global` AS `global`,
2313         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
2314         `post-thread-user`.`network` AS `network`,
2315         `post-user`.`vid` AS `vid`,
2316         `post-thread-user`.`psid` AS `psid`,
2317         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2318         `post-content`.`title` AS `title`,
2319         `post-content`.`content-warning` AS `content-warning`,
2320         `post-content`.`raw-body` AS `raw-body`,
2321         `post-content`.`body` AS `body`,
2322         `post-content`.`rendered-hash` AS `rendered-hash`,
2323         `post-content`.`rendered-html` AS `rendered-html`,
2324         `post-content`.`language` AS `language`,
2325         `post-content`.`plink` AS `plink`,
2326         `post-content`.`location` AS `location`,
2327         `post-content`.`coord` AS `coord`,
2328         `post-content`.`app` AS `app`,
2329         `post-content`.`object-type` AS `object-type`,
2330         `post-content`.`object` AS `object`,
2331         `post-content`.`target-type` AS `target-type`,
2332         `post-content`.`target` AS `target`,
2333         `post-content`.`resource-id` AS `resource-id`,
2334         `post-thread-user`.`contact-id` AS `contact-id`,
2335         `contact`.`uri-id` AS `contact-uri-id`,
2336         `contact`.`url` AS `contact-link`,
2337         `contact`.`addr` AS `contact-addr`,
2338         `contact`.`name` AS `contact-name`,
2339         `contact`.`nick` AS `contact-nick`,
2340         `contact`.`thumb` AS `contact-avatar`,
2341         `contact`.`network` AS `contact-network`,
2342         `contact`.`blocked` AS `contact-blocked`,
2343         `contact`.`hidden` AS `contact-hidden`,
2344         `contact`.`readonly` AS `contact-readonly`,
2345         `contact`.`archive` AS `contact-archive`,
2346         `contact`.`pending` AS `contact-pending`,
2347         `contact`.`rel` AS `contact-rel`,
2348         `contact`.`uid` AS `contact-uid`,
2349         `contact`.`gsid` AS `contact-gsid`,
2350         `contact`.`contact-type` AS `contact-contact-type`,
2351         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
2352         `contact`.`self` AS `self`,
2353         `contact`.`id` AS `cid`,
2354         `contact`.`alias` AS `alias`,
2355         `contact`.`photo` AS `photo`,
2356         `contact`.`name-date` AS `name-date`,
2357         `contact`.`uri-date` AS `uri-date`,
2358         `contact`.`avatar-date` AS `avatar-date`,
2359         `contact`.`thumb` AS `thumb`,
2360         `post-thread-user`.`author-id` AS `author-id`,
2361         `author`.`uri-id` AS `author-uri-id`,
2362         `author`.`url` AS `author-link`,
2363         `author`.`addr` AS `author-addr`,
2364         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
2365         `author`.`nick` AS `author-nick`,
2366         `author`.`alias` AS `author-alias`,
2367         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
2368         `author`.`network` AS `author-network`,
2369         `author`.`blocked` AS `author-blocked`,
2370         `author`.`hidden` AS `author-hidden`,
2371         `author`.`updated` AS `author-updated`,
2372         `author`.`contact-type` AS `author-contact-type`,
2373         `author`.`gsid` AS `author-gsid`,
2374         `post-thread-user`.`owner-id` AS `owner-id`,
2375         `owner`.`uri-id` AS `owner-uri-id`,
2376         `owner`.`url` AS `owner-link`,
2377         `owner`.`addr` AS `owner-addr`,
2378         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
2379         `owner`.`nick` AS `owner-nick`,
2380         `owner`.`alias` AS `owner-alias`,
2381         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
2382         `owner`.`network` AS `owner-network`,
2383         `owner`.`blocked` AS `owner-blocked`,
2384         `owner`.`hidden` AS `owner-hidden`,
2385         `owner`.`updated` AS `owner-updated`,
2386         `owner`.`gsid` AS `owner-gsid`,
2387         `owner`.`contact-type` AS `owner-contact-type`,
2388         `post-thread-user`.`causer-id` AS `causer-id`,
2389         `causer`.`uri-id` AS `causer-uri-id`,
2390         `causer`.`url` AS `causer-link`,
2391         `causer`.`addr` AS `causer-addr`,
2392         `causer`.`name` AS `causer-name`,
2393         `causer`.`nick` AS `causer-nick`,
2394         `causer`.`alias` AS `causer-alias`,
2395         `causer`.`thumb` AS `causer-avatar`,
2396         `causer`.`network` AS `causer-network`,
2397         `causer`.`blocked` AS `causer-blocked`,
2398         `causer`.`hidden` AS `causer-hidden`,
2399         `causer`.`gsid` AS `causer-gsid`,
2400         `causer`.`contact-type` AS `causer-contact-type`,
2401         `post-delivery-data`.`postopts` AS `postopts`,
2402         `post-delivery-data`.`inform` AS `inform`,
2403         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
2404         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
2405         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
2406         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
2407         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
2408         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
2409         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
2410         `post-user`.`event-id` AS `event-id`,
2411         `event`.`created` AS `event-created`,
2412         `event`.`edited` AS `event-edited`,
2413         `event`.`start` AS `event-start`,
2414         `event`.`finish` AS `event-finish`,
2415         `event`.`summary` AS `event-summary`,
2416         `event`.`desc` AS `event-desc`,
2417         `event`.`location` AS `event-location`,
2418         `event`.`type` AS `event-type`,
2419         `event`.`nofinish` AS `event-nofinish`,
2420         `event`.`ignore` AS `event-ignore`,
2421         `post-question`.`id` AS `question-id`,
2422         `post-question`.`multiple` AS `question-multiple`,
2423         `post-question`.`voters` AS `question-voters`,
2424         `post-question`.`end-time` AS `question-end-time`,
2425         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`,
2426         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-user`.`uri-id`) AS `has-media`,
2427         `diaspora-interaction`.`interaction` AS `signed_text`,
2428         `parent-item-uri`.`guid` AS `parent-guid`,
2429         `post-thread-user`.`network` AS `parent-network`,
2430         `post-thread-user`.`author-id` AS `parent-author-id`,
2431         `author`.`url` AS `parent-author-link`,
2432         `author`.`name` AS `parent-author-name`,
2433         `author`.`nick` AS `parent-author-nick`,
2434         `author`.`network` AS `parent-author-network`
2435         FROM `post-thread-user`
2436                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2437                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2438                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
2439                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
2440                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
2441                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
2442                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
2443                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
2444                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
2445                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
2446                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
2447                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
2448                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
2449                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
2450                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2451                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
2452                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
2453                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`;
2454
2455 --
2456 -- VIEW post-view
2457 --
2458 DROP VIEW IF EXISTS `post-view`;
2459 CREATE VIEW `post-view` AS SELECT 
2460         `item-uri`.`uri` AS `uri`,
2461         `post`.`uri-id` AS `uri-id`,
2462         `parent-item-uri`.`uri` AS `parent-uri`,
2463         `post`.`parent-uri-id` AS `parent-uri-id`,
2464         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2465         `post`.`thr-parent-id` AS `thr-parent-id`,
2466         `conversation-item-uri`.`uri` AS `conversation`,
2467         `post-thread`.`conversation-id` AS `conversation-id`,
2468         `quote-item-uri`.`uri` AS `quote-uri`,
2469         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2470         `item-uri`.`guid` AS `guid`,
2471         `post`.`gravity` AS `gravity`,
2472         `external-item-uri`.`uri` AS `extid`,
2473         `post`.`external-id` AS `external-id`,
2474         `post`.`created` AS `created`,
2475         `post`.`edited` AS `edited`,
2476         `post-thread`.`commented` AS `commented`,
2477         `post`.`received` AS `received`,
2478         `post-thread`.`changed` AS `changed`,
2479         `post`.`post-type` AS `post-type`,
2480         `post`.`private` AS `private`,
2481         `post`.`visible` AS `visible`,
2482         `post`.`deleted` AS `deleted`,
2483         `post`.`global` AS `global`,
2484         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
2485         `post`.`network` AS `network`,
2486         `post`.`vid` AS `vid`,
2487         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2488         `post-content`.`title` AS `title`,
2489         `post-content`.`content-warning` AS `content-warning`,
2490         `post-content`.`raw-body` AS `raw-body`,
2491         `post-content`.`body` AS `body`,
2492         `post-content`.`rendered-hash` AS `rendered-hash`,
2493         `post-content`.`rendered-html` AS `rendered-html`,
2494         `post-content`.`language` AS `language`,
2495         `post-content`.`plink` AS `plink`,
2496         `post-content`.`location` AS `location`,
2497         `post-content`.`coord` AS `coord`,
2498         `post-content`.`app` AS `app`,
2499         `post-content`.`object-type` AS `object-type`,
2500         `post-content`.`object` AS `object`,
2501         `post-content`.`target-type` AS `target-type`,
2502         `post-content`.`target` AS `target`,
2503         `post-content`.`resource-id` AS `resource-id`,
2504         `post`.`author-id` AS `contact-id`,
2505         `author`.`uri-id` AS `contact-uri-id`,
2506         `author`.`url` AS `contact-link`,
2507         `author`.`addr` AS `contact-addr`,
2508         `author`.`name` AS `contact-name`,
2509         `author`.`nick` AS `contact-nick`,
2510         `author`.`thumb` AS `contact-avatar`,
2511         `author`.`network` AS `contact-network`,
2512         `author`.`blocked` AS `contact-blocked`,
2513         `author`.`hidden` AS `contact-hidden`,
2514         `author`.`readonly` AS `contact-readonly`,
2515         `author`.`archive` AS `contact-archive`,
2516         `author`.`pending` AS `contact-pending`,
2517         `author`.`rel` AS `contact-rel`,
2518         `author`.`uid` AS `contact-uid`,
2519         `author`.`contact-type` AS `contact-contact-type`,
2520         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2521         false AS `self`,
2522         `author`.`id` AS `cid`,
2523         `author`.`alias` AS `alias`,
2524         `author`.`photo` AS `photo`,
2525         `author`.`name-date` AS `name-date`,
2526         `author`.`uri-date` AS `uri-date`,
2527         `author`.`avatar-date` AS `avatar-date`,
2528         `author`.`thumb` AS `thumb`,
2529         `post`.`author-id` AS `author-id`,
2530         `author`.`uri-id` AS `author-uri-id`,
2531         `author`.`url` AS `author-link`,
2532         `author`.`addr` AS `author-addr`,
2533         `author`.`name` AS `author-name`,
2534         `author`.`nick` AS `author-nick`,
2535         `author`.`alias` AS `author-alias`,
2536         `author`.`thumb` AS `author-avatar`,
2537         `author`.`network` AS `author-network`,
2538         `author`.`blocked` AS `author-blocked`,
2539         `author`.`hidden` AS `author-hidden`,
2540         `author`.`updated` AS `author-updated`,
2541         `author`.`contact-type` AS `author-contact-type`,
2542         `author`.`gsid` AS `author-gsid`,
2543         `post`.`owner-id` AS `owner-id`,
2544         `owner`.`uri-id` AS `owner-uri-id`,
2545         `owner`.`url` AS `owner-link`,
2546         `owner`.`addr` AS `owner-addr`,
2547         `owner`.`name` AS `owner-name`,
2548         `owner`.`nick` AS `owner-nick`,
2549         `owner`.`alias` AS `owner-alias`,
2550         `owner`.`thumb` AS `owner-avatar`,
2551         `owner`.`network` AS `owner-network`,
2552         `owner`.`blocked` AS `owner-blocked`,
2553         `owner`.`hidden` AS `owner-hidden`,
2554         `owner`.`updated` AS `owner-updated`,
2555         `owner`.`contact-type` AS `owner-contact-type`,
2556         `owner`.`gsid` AS `owner-gsid`,
2557         `post`.`causer-id` AS `causer-id`,
2558         `causer`.`uri-id` AS `causer-uri-id`,
2559         `causer`.`url` AS `causer-link`,
2560         `causer`.`addr` AS `causer-addr`,
2561         `causer`.`name` AS `causer-name`,
2562         `causer`.`nick` AS `causer-nick`,
2563         `causer`.`alias` AS `causer-alias`,
2564         `causer`.`thumb` AS `causer-avatar`,
2565         `causer`.`network` AS `causer-network`,
2566         `causer`.`blocked` AS `causer-blocked`,
2567         `causer`.`hidden` AS `causer-hidden`,
2568         `causer`.`contact-type` AS `causer-contact-type`,
2569         `causer`.`gsid` AS `causer-gsid`,
2570         `post-question`.`id` AS `question-id`,
2571         `post-question`.`multiple` AS `question-multiple`,
2572         `post-question`.`voters` AS `question-voters`,
2573         `post-question`.`end-time` AS `question-end-time`,
2574         0 AS `has-categories`,
2575         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post`.`uri-id`) AS `has-media`,
2576         `diaspora-interaction`.`interaction` AS `signed_text`,
2577         `parent-item-uri`.`guid` AS `parent-guid`,
2578         `post-thread`.`network` AS `parent-network`,
2579         `post-thread`.`author-id` AS `parent-author-id`,
2580         `parent-post-author`.`url` AS `parent-author-link`,
2581         `parent-post-author`.`name` AS `parent-author-name`,
2582         `parent-post-author`.`nick` AS `parent-author-nick`,
2583         `parent-post-author`.`network` AS `parent-author-network`
2584         FROM `post`
2585                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2586                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2587                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2588                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2589                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2590                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2591                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2592                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2593                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2594                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2595                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2596                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2597                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2598                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
2599                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `post-thread`.`author-id`;
2600
2601 --
2602 -- VIEW post-thread-view
2603 --
2604 DROP VIEW IF EXISTS `post-thread-view`;
2605 CREATE VIEW `post-thread-view` AS SELECT 
2606         `item-uri`.`uri` AS `uri`,
2607         `post-thread`.`uri-id` AS `uri-id`,
2608         `parent-item-uri`.`uri` AS `parent-uri`,
2609         `post`.`parent-uri-id` AS `parent-uri-id`,
2610         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2611         `post`.`thr-parent-id` AS `thr-parent-id`,
2612         `conversation-item-uri`.`uri` AS `conversation`,
2613         `post-thread`.`conversation-id` AS `conversation-id`,
2614         `quote-item-uri`.`uri` AS `quote-uri`,
2615         `post-content`.`quote-uri-id` AS `quote-uri-id`,
2616         `item-uri`.`guid` AS `guid`,
2617         `post`.`gravity` AS `gravity`,
2618         `external-item-uri`.`uri` AS `extid`,
2619         `post`.`external-id` AS `external-id`,
2620         `post-thread`.`created` AS `created`,
2621         `post`.`edited` AS `edited`,
2622         `post-thread`.`commented` AS `commented`,
2623         `post-thread`.`received` AS `received`,
2624         `post-thread`.`changed` AS `changed`,
2625         `post`.`post-type` AS `post-type`,
2626         `post`.`private` AS `private`,
2627         `post`.`visible` AS `visible`,
2628         `post`.`deleted` AS `deleted`,
2629         `post`.`global` AS `global`,
2630         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
2631         `post-thread`.`network` AS `network`,
2632         `post`.`vid` AS `vid`,
2633         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2634         `post-content`.`title` AS `title`,
2635         `post-content`.`content-warning` AS `content-warning`,
2636         `post-content`.`raw-body` AS `raw-body`,
2637         `post-content`.`body` AS `body`,
2638         `post-content`.`rendered-hash` AS `rendered-hash`,
2639         `post-content`.`rendered-html` AS `rendered-html`,
2640         `post-content`.`language` AS `language`,
2641         `post-content`.`plink` AS `plink`,
2642         `post-content`.`location` AS `location`,
2643         `post-content`.`coord` AS `coord`,
2644         `post-content`.`app` AS `app`,
2645         `post-content`.`object-type` AS `object-type`,
2646         `post-content`.`object` AS `object`,
2647         `post-content`.`target-type` AS `target-type`,
2648         `post-content`.`target` AS `target`,
2649         `post-content`.`resource-id` AS `resource-id`,
2650         `post-thread`.`author-id` AS `contact-id`,
2651         `author`.`uri-id` AS `contact-uri-id`,
2652         `author`.`url` AS `contact-link`,
2653         `author`.`addr` AS `contact-addr`,
2654         `author`.`name` AS `contact-name`,
2655         `author`.`nick` AS `contact-nick`,
2656         `author`.`thumb` AS `contact-avatar`,
2657         `author`.`network` AS `contact-network`,
2658         `author`.`blocked` AS `contact-blocked`,
2659         `author`.`hidden` AS `contact-hidden`,
2660         `author`.`readonly` AS `contact-readonly`,
2661         `author`.`archive` AS `contact-archive`,
2662         `author`.`pending` AS `contact-pending`,
2663         `author`.`rel` AS `contact-rel`,
2664         `author`.`uid` AS `contact-uid`,
2665         `author`.`contact-type` AS `contact-contact-type`,
2666         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2667         false AS `self`,
2668         `author`.`id` AS `cid`,
2669         `author`.`alias` AS `alias`,
2670         `author`.`photo` AS `photo`,
2671         `author`.`name-date` AS `name-date`,
2672         `author`.`uri-date` AS `uri-date`,
2673         `author`.`avatar-date` AS `avatar-date`,
2674         `author`.`thumb` AS `thumb`,
2675         `post-thread`.`author-id` AS `author-id`,
2676         `author`.`uri-id` AS `author-uri-id`,
2677         `author`.`url` AS `author-link`,
2678         `author`.`addr` AS `author-addr`,
2679         `author`.`name` AS `author-name`,
2680         `author`.`nick` AS `author-nick`,
2681         `author`.`alias` AS `author-alias`,
2682         `author`.`thumb` AS `author-avatar`,
2683         `author`.`network` AS `author-network`,
2684         `author`.`blocked` AS `author-blocked`,
2685         `author`.`hidden` AS `author-hidden`,
2686         `author`.`updated` AS `author-updated`,
2687         `author`.`contact-type` AS `author-contact-type`,
2688         `author`.`gsid` AS `author-gsid`,
2689         `post-thread`.`owner-id` AS `owner-id`,
2690         `owner`.`uri-id` AS `owner-uri-id`,
2691         `owner`.`url` AS `owner-link`,
2692         `owner`.`addr` AS `owner-addr`,
2693         `owner`.`name` AS `owner-name`,
2694         `owner`.`nick` AS `owner-nick`,
2695         `owner`.`alias` AS `owner-alias`,
2696         `owner`.`thumb` AS `owner-avatar`,
2697         `owner`.`network` AS `owner-network`,
2698         `owner`.`blocked` AS `owner-blocked`,
2699         `owner`.`hidden` AS `owner-hidden`,
2700         `owner`.`updated` AS `owner-updated`,
2701         `owner`.`gsid` AS `owner-gsid`,
2702         `owner`.`contact-type` AS `owner-contact-type`,
2703         `post-thread`.`causer-id` AS `causer-id`,
2704         `causer`.`uri-id` AS `causer-uri-id`,
2705         `causer`.`url` AS `causer-link`,
2706         `causer`.`addr` AS `causer-addr`,
2707         `causer`.`name` AS `causer-name`,
2708         `causer`.`nick` AS `causer-nick`,
2709         `causer`.`alias` AS `causer-alias`,
2710         `causer`.`thumb` AS `causer-avatar`,
2711         `causer`.`network` AS `causer-network`,
2712         `causer`.`blocked` AS `causer-blocked`,
2713         `causer`.`hidden` AS `causer-hidden`,
2714         `causer`.`gsid` AS `causer-gsid`,
2715         `causer`.`contact-type` AS `causer-contact-type`,
2716         `post-question`.`id` AS `question-id`,
2717         `post-question`.`multiple` AS `question-multiple`,
2718         `post-question`.`voters` AS `question-voters`,
2719         `post-question`.`end-time` AS `question-end-time`,
2720         0 AS `has-categories`,
2721         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`) AS `has-media`,
2722         (SELECT COUNT(*) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-comments`,
2723         (SELECT COUNT(DISTINCT(`author-id`)) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-actors`,
2724         `diaspora-interaction`.`interaction` AS `signed_text`,
2725         `parent-item-uri`.`guid` AS `parent-guid`,
2726         `post-thread`.`network` AS `parent-network`,
2727         `post-thread`.`author-id` AS `parent-author-id`,
2728         `author`.`url` AS `parent-author-link`,
2729         `author`.`name` AS `parent-author-name`,
2730         `author`.`nick` AS `parent-author-nick`,
2731         `author`.`network` AS `parent-author-network`
2732         FROM `post-thread`
2733                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2734                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2735                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2736                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2737                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2738                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2739                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2740                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2741                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2742                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2743                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2744                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2745                         LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
2746                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`;
2747
2748 --
2749 -- VIEW category-view
2750 --
2751 DROP VIEW IF EXISTS `category-view`;
2752 CREATE VIEW `category-view` AS SELECT 
2753         `post-category`.`uri-id` AS `uri-id`,
2754         `post-category`.`uid` AS `uid`,
2755         `post-category`.`type` AS `type`,
2756         `post-category`.`tid` AS `tid`,
2757         `tag`.`name` AS `name`,
2758         `tag`.`url` AS `url`
2759         FROM `post-category`
2760                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2761
2762 --
2763 -- VIEW collection-view
2764 --
2765 DROP VIEW IF EXISTS `collection-view`;
2766 CREATE VIEW `collection-view` AS SELECT 
2767         `post-collection`.`uri-id` AS `uri-id`,
2768         `post-collection`.`type` AS `type`,
2769         `post-collection`.`author-id` AS `cid`,
2770         `post`.`received` AS `received`,
2771         `post`.`created` AS `created`,
2772         `post-thread`.`commented` AS `commented`,
2773         `post`.`private` AS `private`,
2774         `post`.`visible` AS `visible`,
2775         `post`.`deleted` AS `deleted`,
2776         `post`.`thr-parent-id` AS `thr-parent-id`,
2777         `post-collection`.`author-id` AS `author-id`,
2778         `post`.`gravity` AS `gravity`
2779         FROM `post-collection`
2780                         INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
2781                         INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`;
2782
2783 --
2784 -- VIEW media-view
2785 --
2786 DROP VIEW IF EXISTS `media-view`;
2787 CREATE VIEW `media-view` AS SELECT 
2788         `post-media`.`uri-id` AS `uri-id`,
2789         `post-media`.`type` AS `type`,
2790         `post`.`received` AS `received`,
2791         `post`.`created` AS `created`,
2792         `post`.`private` AS `private`,
2793         `post`.`visible` AS `visible`,
2794         `post`.`deleted` AS `deleted`,
2795         `post`.`thr-parent-id` AS `thr-parent-id`,
2796         `post`.`author-id` AS `author-id`,
2797         `post`.`gravity` AS `gravity`
2798         FROM `post-media`
2799                         INNER JOIN `post` ON `post-media`.`uri-id` = `post`.`uri-id`;
2800
2801 --
2802 -- VIEW tag-view
2803 --
2804 DROP VIEW IF EXISTS `tag-view`;
2805 CREATE VIEW `tag-view` AS SELECT 
2806         `post-tag`.`uri-id` AS `uri-id`,
2807         `post-tag`.`type` AS `type`,
2808         `post-tag`.`tid` AS `tid`,
2809         `post-tag`.`cid` AS `cid`,
2810         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2811         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`,
2812         CASE `cid` WHEN 0 THEN `tag`.`type` ELSE 1 END AS `tag-type`
2813         FROM `post-tag`
2814                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2815                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2816
2817 --
2818 -- VIEW network-item-view
2819 --
2820 DROP VIEW IF EXISTS `network-item-view`;
2821 CREATE VIEW `network-item-view` AS SELECT 
2822         `post-user`.`uri-id` AS `uri-id`,
2823         `post-thread-user`.`post-user-id` AS `parent`,
2824         `post-user`.`received` AS `received`,
2825         `post-thread-user`.`commented` AS `commented`,
2826         `post-user`.`created` AS `created`,
2827         `post-user`.`uid` AS `uid`,
2828         `post-thread-user`.`starred` AS `starred`,
2829         `post-thread-user`.`mention` AS `mention`,
2830         `post-user`.`network` AS `network`,
2831         `post-user`.`unseen` AS `unseen`,
2832         `post-user`.`gravity` AS `gravity`,
2833         `post-user`.`contact-id` AS `contact-id`,
2834         `ownercontact`.`contact-type` AS `contact-type`
2835         FROM `post-user`
2836                         INNER JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
2837                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2838                         STRAIGHT_JOIN `contact` AS `authorcontact` ON `authorcontact`.`id` = `post-thread-user`.`author-id`
2839                         STRAIGHT_JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2840                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2841                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2842                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2843                         AND NOT `authorcontact`.`blocked` AND NOT `ownercontact`.`blocked`
2844                         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`))
2845                         AND NOT EXISTS(SELECT `gsid`   FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
2846
2847 --
2848 -- VIEW network-thread-view
2849 --
2850 DROP VIEW IF EXISTS `network-thread-view`;
2851 CREATE VIEW `network-thread-view` AS SELECT 
2852         `post-thread-user`.`uri-id` AS `uri-id`,
2853         `post-thread-user`.`post-user-id` AS `parent`,
2854         `post-thread-user`.`received` AS `received`,
2855         `post-thread-user`.`commented` AS `commented`,
2856         `post-thread-user`.`created` AS `created`,
2857         `post-thread-user`.`uid` AS `uid`,
2858         `post-thread-user`.`starred` AS `starred`,
2859         `post-thread-user`.`mention` AS `mention`,
2860         `post-thread-user`.`network` AS `network`,
2861         `post-thread-user`.`contact-id` AS `contact-id`,
2862         `ownercontact`.`contact-type` AS `contact-type`
2863         FROM `post-thread-user`
2864                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2865                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2866                         STRAIGHT_JOIN `contact` AS `authorcontact` ON `authorcontact`.`id` = `post-thread-user`.`author-id`
2867                         STRAIGHT_JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2868                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2869                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2870                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2871                         AND NOT `authorcontact`.`blocked` AND NOT `ownercontact`.`blocked`
2872                         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`))
2873                         AND NOT EXISTS(SELECT `gsid`   FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
2874
2875 --
2876 -- VIEW owner-view
2877 --
2878 DROP VIEW IF EXISTS `owner-view`;
2879 CREATE VIEW `owner-view` AS SELECT 
2880         `contact`.`id` AS `id`,
2881         `contact`.`uid` AS `uid`,
2882         `contact`.`created` AS `created`,
2883         `contact`.`updated` AS `updated`,
2884         `contact`.`self` AS `self`,
2885         `contact`.`remote_self` AS `remote_self`,
2886         `contact`.`rel` AS `rel`,
2887         `contact`.`network` AS `network`,
2888         `contact`.`protocol` AS `protocol`,
2889         `contact`.`name` AS `name`,
2890         `contact`.`nick` AS `nick`,
2891         `contact`.`location` AS `location`,
2892         `contact`.`about` AS `about`,
2893         `contact`.`keywords` AS `keywords`,
2894         `contact`.`xmpp` AS `xmpp`,
2895         `contact`.`matrix` AS `matrix`,
2896         `contact`.`attag` AS `attag`,
2897         `contact`.`avatar` AS `avatar`,
2898         `contact`.`photo` AS `photo`,
2899         `contact`.`thumb` AS `thumb`,
2900         `contact`.`micro` AS `micro`,
2901         `contact`.`header` AS `header`,
2902         `contact`.`url` AS `url`,
2903         `contact`.`nurl` AS `nurl`,
2904         `contact`.`uri-id` AS `uri-id`,
2905         `contact`.`addr` AS `addr`,
2906         `contact`.`alias` AS `alias`,
2907         `contact`.`pubkey` AS `pubkey`,
2908         `contact`.`prvkey` AS `prvkey`,
2909         `contact`.`batch` AS `batch`,
2910         `contact`.`request` AS `request`,
2911         `contact`.`notify` AS `notify`,
2912         `contact`.`poll` AS `poll`,
2913         `contact`.`confirm` AS `confirm`,
2914         `contact`.`poco` AS `poco`,
2915         `contact`.`subhub` AS `subhub`,
2916         `contact`.`hub-verify` AS `hub-verify`,
2917         `contact`.`last-update` AS `last-update`,
2918         `contact`.`success_update` AS `success_update`,
2919         `contact`.`failure_update` AS `failure_update`,
2920         `contact`.`name-date` AS `name-date`,
2921         `contact`.`uri-date` AS `uri-date`,
2922         `contact`.`avatar-date` AS `avatar-date`,
2923         `contact`.`avatar-date` AS `picdate`,
2924         `contact`.`term-date` AS `term-date`,
2925         `contact`.`last-item` AS `last-item`,
2926         `contact`.`priority` AS `priority`,
2927         `user`.`blocked` AS `blocked`,
2928         `contact`.`block_reason` AS `block_reason`,
2929         `contact`.`readonly` AS `readonly`,
2930         `contact`.`writable` AS `writable`,
2931         `contact`.`forum` AS `forum`,
2932         `contact`.`prv` AS `prv`,
2933         `contact`.`contact-type` AS `contact-type`,
2934         `contact`.`manually-approve` AS `manually-approve`,
2935         `contact`.`hidden` AS `hidden`,
2936         `contact`.`archive` AS `archive`,
2937         `contact`.`pending` AS `pending`,
2938         `contact`.`deleted` AS `deleted`,
2939         `contact`.`unsearchable` AS `unsearchable`,
2940         `contact`.`sensitive` AS `sensitive`,
2941         `contact`.`baseurl` AS `baseurl`,
2942         `contact`.`reason` AS `reason`,
2943         `contact`.`info` AS `info`,
2944         `contact`.`bdyear` AS `bdyear`,
2945         `contact`.`bd` AS `bd`,
2946         `contact`.`notify_new_posts` AS `notify_new_posts`,
2947         `contact`.`fetch_further_information` AS `fetch_further_information`,
2948         `contact`.`ffi_keyword_blacklist` AS `ffi_keyword_blacklist`,
2949         `user`.`parent-uid` AS `parent-uid`,
2950         `user`.`guid` AS `guid`,
2951         `user`.`nickname` AS `nickname`,
2952         `user`.`email` AS `email`,
2953         `user`.`openid` AS `openid`,
2954         `user`.`timezone` AS `timezone`,
2955         `user`.`language` AS `language`,
2956         `user`.`register_date` AS `register_date`,
2957         `user`.`login_date` AS `login_date`,
2958         `user`.`last-activity` AS `last-activity`,
2959         `user`.`default-location` AS `default-location`,
2960         `user`.`allow_location` AS `allow_location`,
2961         `user`.`theme` AS `theme`,
2962         `user`.`pubkey` AS `upubkey`,
2963         `user`.`prvkey` AS `uprvkey`,
2964         `user`.`sprvkey` AS `sprvkey`,
2965         `user`.`spubkey` AS `spubkey`,
2966         `user`.`verified` AS `verified`,
2967         `user`.`blockwall` AS `blockwall`,
2968         `user`.`hidewall` AS `hidewall`,
2969         `user`.`blocktags` AS `blocktags`,
2970         `user`.`notify-flags` AS `notify-flags`,
2971         `user`.`page-flags` AS `page-flags`,
2972         `user`.`account-type` AS `account-type`,
2973         `user`.`prvnets` AS `prvnets`,
2974         `user`.`maxreq` AS `maxreq`,
2975         `user`.`expire` AS `expire`,
2976         `user`.`account_removed` AS `account_removed`,
2977         `user`.`account_expired` AS `account_expired`,
2978         `user`.`account_expires_on` AS `account_expires_on`,
2979         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2980         `user`.`def_gid` AS `def_gid`,
2981         `user`.`allow_cid` AS `allow_cid`,
2982         `user`.`allow_gid` AS `allow_gid`,
2983         `user`.`deny_cid` AS `deny_cid`,
2984         `user`.`deny_gid` AS `deny_gid`,
2985         `user`.`openidserver` AS `openidserver`,
2986         `profile`.`publish` AS `publish`,
2987         `profile`.`net-publish` AS `net-publish`,
2988         `profile`.`hide-friends` AS `hide-friends`,
2989         `profile`.`prv_keywords` AS `prv_keywords`,
2990         `profile`.`pub_keywords` AS `pub_keywords`,
2991         `profile`.`address` AS `address`,
2992         `profile`.`locality` AS `locality`,
2993         `profile`.`region` AS `region`,
2994         `profile`.`postal-code` AS `postal-code`,
2995         `profile`.`country-name` AS `country-name`,
2996         `profile`.`homepage` AS `homepage`,
2997         `profile`.`homepage_verified` AS `homepage_verified`,
2998         `profile`.`dob` AS `dob`
2999         FROM `user`
3000                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
3001                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
3002
3003 --
3004 -- VIEW account-view
3005 --
3006 DROP VIEW IF EXISTS `account-view`;
3007 CREATE VIEW `account-view` AS SELECT 
3008         `contact`.`id` AS `id`,
3009         `contact`.`url` AS `url`,
3010         `contact`.`nurl` AS `nurl`,
3011         `contact`.`uri-id` AS `uri-id`,
3012         `item-uri`.`guid` AS `guid`,
3013         `contact`.`addr` AS `addr`,
3014         `contact`.`alias` AS `alias`,
3015         `contact`.`name` AS `name`,
3016         `contact`.`nick` AS `nick`,
3017         `contact`.`about` AS `about`,
3018         `contact`.`keywords` AS `keywords`,
3019         `contact`.`xmpp` AS `xmpp`,
3020         `contact`.`matrix` AS `matrix`,
3021         `contact`.`avatar` AS `avatar`,
3022         `contact`.`photo` AS `photo`,
3023         `contact`.`thumb` AS `thumb`,
3024         `contact`.`micro` AS `micro`,
3025         `contact`.`header` AS `header`,
3026         `contact`.`created` AS `created`,
3027         `contact`.`updated` AS `updated`,
3028         `contact`.`network` AS `network`,
3029         `contact`.`protocol` AS `protocol`,
3030         `contact`.`location` AS `location`,
3031         `contact`.`attag` AS `attag`,
3032         `contact`.`pubkey` AS `pubkey`,
3033         `contact`.`prvkey` AS `prvkey`,
3034         `contact`.`subscribe` AS `subscribe`,
3035         `contact`.`last-update` AS `last-update`,
3036         `contact`.`success_update` AS `success_update`,
3037         `contact`.`failure_update` AS `failure_update`,
3038         `contact`.`failed` AS `failed`,
3039         `contact`.`last-item` AS `last-item`,
3040         `contact`.`last-discovery` AS `last-discovery`,
3041         `contact`.`contact-type` AS `contact-type`,
3042         `contact`.`manually-approve` AS `manually-approve`,
3043         `contact`.`unsearchable` AS `unsearchable`,
3044         `contact`.`sensitive` AS `sensitive`,
3045         `contact`.`baseurl` AS `baseurl`,
3046         `contact`.`gsid` AS `gsid`,
3047         `contact`.`info` AS `info`,
3048         `contact`.`bdyear` AS `bdyear`,
3049         `contact`.`bd` AS `bd`,
3050         `contact`.`poco` AS `poco`,
3051         `contact`.`name-date` AS `name-date`,
3052         `contact`.`uri-date` AS `uri-date`,
3053         `contact`.`avatar-date` AS `avatar-date`,
3054         `contact`.`term-date` AS `term-date`,
3055         `contact`.`hidden` AS `global-ignored`,
3056         `contact`.`blocked` AS `global-blocked`,
3057         `contact`.`hidden` AS `hidden`,
3058         `contact`.`archive` AS `archive`,
3059         `contact`.`deleted` AS `deleted`,
3060         `contact`.`blocked` AS `blocked`,
3061         `contact`.`notify` AS `dfrn-notify`,
3062         `contact`.`poll` AS `dfrn-poll`,
3063         `item-uri`.`guid` AS `diaspora-guid`,
3064         `diaspora-contact`.`batch` AS `diaspora-batch`,
3065         `diaspora-contact`.`notify` AS `diaspora-notify`,
3066         `diaspora-contact`.`poll` AS `diaspora-poll`,
3067         `diaspora-contact`.`alias` AS `diaspora-alias`,
3068         `apcontact`.`uuid` AS `ap-uuid`,
3069         `apcontact`.`type` AS `ap-type`,
3070         `apcontact`.`following` AS `ap-following`,
3071         `apcontact`.`followers` AS `ap-followers`,
3072         `apcontact`.`inbox` AS `ap-inbox`,
3073         `apcontact`.`outbox` AS `ap-outbox`,
3074         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
3075         `apcontact`.`generator` AS `ap-generator`,
3076         `apcontact`.`following_count` AS `ap-following_count`,
3077         `apcontact`.`followers_count` AS `ap-followers_count`,
3078         `apcontact`.`statuses_count` AS `ap-statuses_count`,
3079         `gserver`.`site_name` AS `site_name`,
3080         `gserver`.`platform` AS `platform`,
3081         `gserver`.`version` AS `version`,
3082         `gserver`.`blocked` AS `server-blocked`,
3083         `gserver`.`failed` AS `server-failed`
3084         FROM `contact`
3085                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
3086                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
3087                         LEFT JOIN `diaspora-contact` ON `diaspora-contact`.`uri-id` = contact.`uri-id`
3088                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`
3089                         WHERE `contact`.`uid` = 0;
3090
3091 --
3092 -- VIEW account-user-view
3093 --
3094 DROP VIEW IF EXISTS `account-user-view`;
3095 CREATE VIEW `account-user-view` AS SELECT 
3096         `ucontact`.`id` AS `id`,
3097         `contact`.`id` AS `pid`,
3098         `ucontact`.`uid` AS `uid`,
3099         `contact`.`url` AS `url`,
3100         `contact`.`nurl` AS `nurl`,
3101         `contact`.`uri-id` AS `uri-id`,
3102         `item-uri`.`guid` AS `guid`,
3103         `contact`.`addr` AS `addr`,
3104         `contact`.`alias` AS `alias`,
3105         `contact`.`name` AS `name`,
3106         `contact`.`nick` AS `nick`,
3107         `contact`.`about` AS `about`,
3108         `contact`.`keywords` AS `keywords`,
3109         `contact`.`xmpp` AS `xmpp`,
3110         `contact`.`matrix` AS `matrix`,
3111         `contact`.`avatar` AS `avatar`,
3112         `contact`.`photo` AS `photo`,
3113         `contact`.`thumb` AS `thumb`,
3114         `contact`.`micro` AS `micro`,
3115         `contact`.`header` AS `header`,
3116         `contact`.`created` AS `created`,
3117         `contact`.`updated` AS `updated`,
3118         `ucontact`.`self` AS `self`,
3119         `ucontact`.`remote_self` AS `remote_self`,
3120         `ucontact`.`rel` AS `rel`,
3121         `contact`.`network` AS `network`,
3122         `ucontact`.`protocol` AS `protocol`,
3123         `contact`.`location` AS `location`,
3124         `ucontact`.`attag` AS `attag`,
3125         `contact`.`pubkey` AS `pubkey`,
3126         `contact`.`prvkey` AS `prvkey`,
3127         `contact`.`subscribe` AS `subscribe`,
3128         `contact`.`last-update` AS `last-update`,
3129         `contact`.`success_update` AS `success_update`,
3130         `contact`.`failure_update` AS `failure_update`,
3131         `contact`.`failed` AS `failed`,
3132         `contact`.`last-item` AS `last-item`,
3133         `contact`.`last-discovery` AS `last-discovery`,
3134         `contact`.`contact-type` AS `contact-type`,
3135         `contact`.`manually-approve` AS `manually-approve`,
3136         `contact`.`unsearchable` AS `unsearchable`,
3137         `contact`.`sensitive` AS `sensitive`,
3138         `contact`.`baseurl` AS `baseurl`,
3139         `contact`.`gsid` AS `gsid`,
3140         `ucontact`.`info` AS `info`,
3141         `contact`.`bdyear` AS `bdyear`,
3142         `contact`.`bd` AS `bd`,
3143         `contact`.`poco` AS `poco`,
3144         `contact`.`name-date` AS `name-date`,
3145         `contact`.`uri-date` AS `uri-date`,
3146         `contact`.`avatar-date` AS `avatar-date`,
3147         `contact`.`term-date` AS `term-date`,
3148         `contact`.`hidden` AS `global-ignored`,
3149         `contact`.`blocked` AS `global-blocked`,
3150         `ucontact`.`hidden` AS `hidden`,
3151         `ucontact`.`archive` AS `archive`,
3152         `ucontact`.`pending` AS `pending`,
3153         `ucontact`.`deleted` AS `deleted`,
3154         `ucontact`.`notify_new_posts` AS `notify_new_posts`,
3155         `ucontact`.`fetch_further_information` AS `fetch_further_information`,
3156         `ucontact`.`ffi_keyword_blacklist` AS `ffi_keyword_blacklist`,
3157         `ucontact`.`rating` AS `rating`,
3158         `ucontact`.`readonly` AS `readonly`,
3159         `ucontact`.`blocked` AS `blocked`,
3160         `ucontact`.`block_reason` AS `block_reason`,
3161         `ucontact`.`subhub` AS `subhub`,
3162         `ucontact`.`hub-verify` AS `hub-verify`,
3163         `ucontact`.`reason` AS `reason`,
3164         `contact`.`notify` AS `dfrn-notify`,
3165         `contact`.`poll` AS `dfrn-poll`,
3166         `item-uri`.`guid` AS `diaspora-guid`,
3167         `diaspora-contact`.`batch` AS `diaspora-batch`,
3168         `diaspora-contact`.`notify` AS `diaspora-notify`,
3169         `diaspora-contact`.`poll` AS `diaspora-poll`,
3170         `diaspora-contact`.`alias` AS `diaspora-alias`,
3171         `diaspora-contact`.`interacting_count` AS `diaspora-interacting_count`,
3172         `diaspora-contact`.`interacted_count` AS `diaspora-interacted_count`,
3173         `diaspora-contact`.`post_count` AS `diaspora-post_count`,
3174         `apcontact`.`uuid` AS `ap-uuid`,
3175         `apcontact`.`type` AS `ap-type`,
3176         `apcontact`.`following` AS `ap-following`,
3177         `apcontact`.`followers` AS `ap-followers`,
3178         `apcontact`.`inbox` AS `ap-inbox`,
3179         `apcontact`.`outbox` AS `ap-outbox`,
3180         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
3181         `apcontact`.`generator` AS `ap-generator`,
3182         `apcontact`.`following_count` AS `ap-following_count`,
3183         `apcontact`.`followers_count` AS `ap-followers_count`,
3184         `apcontact`.`statuses_count` AS `ap-statuses_count`,
3185         `gserver`.`site_name` AS `site_name`,
3186         `gserver`.`platform` AS `platform`,
3187         `gserver`.`version` AS `version`,
3188         `gserver`.`blocked` AS `server-blocked`,
3189         `gserver`.`failed` AS `server-failed`
3190         FROM `contact` AS `ucontact`
3191                         INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
3192                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
3193                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
3194                         LEFT JOIN `diaspora-contact` ON `diaspora-contact`.`uri-id` = `ucontact`.`uri-id`
3195                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`;
3196
3197 --
3198 -- VIEW pending-view
3199 --
3200 DROP VIEW IF EXISTS `pending-view`;
3201 CREATE VIEW `pending-view` AS SELECT 
3202         `register`.`id` AS `id`,
3203         `register`.`hash` AS `hash`,
3204         `register`.`created` AS `created`,
3205         `register`.`uid` AS `uid`,
3206         `register`.`password` AS `password`,
3207         `register`.`language` AS `language`,
3208         `register`.`note` AS `note`,
3209         `contact`.`self` AS `self`,
3210         `contact`.`name` AS `name`,
3211         `contact`.`url` AS `url`,
3212         `contact`.`micro` AS `micro`,
3213         `user`.`email` AS `email`,
3214         `contact`.`nick` AS `nick`
3215         FROM `register`
3216                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
3217                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
3218
3219 --
3220 -- VIEW tag-search-view
3221 --
3222 DROP VIEW IF EXISTS `tag-search-view`;
3223 CREATE VIEW `tag-search-view` AS SELECT 
3224         `post-tag`.`uri-id` AS `uri-id`,
3225         `post-user`.`uid` AS `uid`,
3226         `post-user`.`id` AS `iid`,
3227         `post-user`.`private` AS `private`,
3228         `post-user`.`wall` AS `wall`,
3229         `post-user`.`origin` AS `origin`,
3230         `post-user`.`global` AS `global`,
3231         `post-user`.`gravity` AS `gravity`,
3232         `post-user`.`received` AS `received`,
3233         `post-user`.`network` AS `network`,
3234         `post-user`.`author-id` AS `author-id`,
3235         `tag`.`name` AS `name`
3236         FROM `post-tag`
3237                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
3238                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
3239                         WHERE `post-tag`.`type` = 1;
3240
3241 --
3242 -- VIEW workerqueue-view
3243 --
3244 DROP VIEW IF EXISTS `workerqueue-view`;
3245 CREATE VIEW `workerqueue-view` AS SELECT 
3246         `process`.`pid` AS `pid`,
3247         `workerqueue`.`priority` AS `priority`
3248         FROM `process`
3249                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
3250                         WHERE NOT `workerqueue`.`done`;
3251
3252 --
3253 -- VIEW profile_field-view
3254 --
3255 DROP VIEW IF EXISTS `profile_field-view`;
3256 CREATE VIEW `profile_field-view` AS SELECT 
3257         `profile_field`.`id` AS `id`,
3258         `profile_field`.`uid` AS `uid`,
3259         `profile_field`.`label` AS `label`,
3260         `profile_field`.`value` AS `value`,
3261         `profile_field`.`order` AS `order`,
3262         `profile_field`.`psid` AS `psid`,
3263         `permissionset`.`allow_cid` AS `allow_cid`,
3264         `permissionset`.`allow_gid` AS `allow_gid`,
3265         `permissionset`.`deny_cid` AS `deny_cid`,
3266         `permissionset`.`deny_gid` AS `deny_gid`,
3267         `profile_field`.`created` AS `created`,
3268         `profile_field`.`edited` AS `edited`
3269         FROM `profile_field`
3270                         INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`;
3271
3272 --
3273 -- VIEW diaspora-contact-view
3274 --
3275 DROP VIEW IF EXISTS `diaspora-contact-view`;
3276 CREATE VIEW `diaspora-contact-view` AS SELECT 
3277         `diaspora-contact`.`uri-id` AS `uri-id`,
3278         `item-uri`.`uri` AS `url`,
3279         `item-uri`.`guid` AS `guid`,
3280         `diaspora-contact`.`addr` AS `addr`,
3281         `diaspora-contact`.`alias` AS `alias`,
3282         `diaspora-contact`.`nick` AS `nick`,
3283         `diaspora-contact`.`name` AS `name`,
3284         `diaspora-contact`.`given-name` AS `given-name`,
3285         `diaspora-contact`.`family-name` AS `family-name`,
3286         `diaspora-contact`.`photo` AS `photo`,
3287         `diaspora-contact`.`photo-medium` AS `photo-medium`,
3288         `diaspora-contact`.`photo-small` AS `photo-small`,
3289         `diaspora-contact`.`batch` AS `batch`,
3290         `diaspora-contact`.`notify` AS `notify`,
3291         `diaspora-contact`.`poll` AS `poll`,
3292         `diaspora-contact`.`subscribe` AS `subscribe`,
3293         `diaspora-contact`.`searchable` AS `searchable`,
3294         `diaspora-contact`.`pubkey` AS `pubkey`,
3295         `gserver`.`url` AS `baseurl`,
3296         `diaspora-contact`.`gsid` AS `gsid`,
3297         `diaspora-contact`.`created` AS `created`,
3298         `diaspora-contact`.`updated` AS `updated`,
3299         `diaspora-contact`.`interacting_count` AS `interacting_count`,
3300         `diaspora-contact`.`interacted_count` AS `interacted_count`,
3301         `diaspora-contact`.`post_count` AS `post_count`
3302         FROM `diaspora-contact`
3303                         INNER JOIN `item-uri` ON `item-uri`.`id` = `diaspora-contact`.`uri-id`
3304                         LEFT JOIN `gserver` ON `gserver`.`id` = `diaspora-contact`.`gsid`;