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