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