]> git.mxchange.org Git - friendica.git/blob - database.sql
Merge remote-tracking branch 'upstream/2022.09-rc' into pagecache
[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         `content` mediumtext COMMENT 'Page content',
1016         `fetched` datetime COMMENT 'date when the page had been fetched',
1017          PRIMARY KEY(`page`),
1018          INDEX `fetched` (`fetched`)
1019 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
1020
1021 --
1022 -- TABLE parsed_url
1023 --
1024 CREATE TABLE IF NOT EXISTS `parsed_url` (
1025         `url_hash` binary(64) NOT NULL COMMENT 'page url hash',
1026         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
1027         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
1028         `url` text NOT NULL COMMENT 'page url',
1029         `content` mediumtext COMMENT 'page data',
1030         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
1031         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of expiration',
1032          PRIMARY KEY(`url_hash`,`guessing`,`oembed`),
1033          INDEX `created` (`created`),
1034          INDEX `expires` (`expires`)
1035 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
1036
1037 --
1038 -- TABLE pconfig
1039 --
1040 CREATE TABLE IF NOT EXISTS `pconfig` (
1041         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
1042         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1043         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
1044         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
1045         `v` mediumtext COMMENT 'Value',
1046          PRIMARY KEY(`id`),
1047          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
1048         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1049 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
1050
1051 --
1052 -- TABLE photo
1053 --
1054 CREATE TABLE IF NOT EXISTS `photo` (
1055         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1056         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1057         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1058         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
1059         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
1060         `hash` char(32) COMMENT 'hash value of the photo',
1061         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
1062         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
1063         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1064         `desc` text COMMENT '',
1065         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
1066         `photo-type` tinyint unsigned COMMENT 'User avatar, user banner, contact avatar, contact banner or default',
1067         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1068         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
1069         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1070         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1071         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1072         `data` mediumblob NOT NULL COMMENT '',
1073         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1074         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
1075         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
1076         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
1077         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
1078         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
1079         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
1080         `backend-class` tinytext COMMENT 'Storage backend class',
1081         `backend-ref` text COMMENT 'Storage backend data reference',
1082         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1083          PRIMARY KEY(`id`),
1084          INDEX `contactid` (`contact-id`),
1085          INDEX `uid_contactid` (`uid`,`contact-id`),
1086          INDEX `uid_profile` (`uid`,`profile`),
1087          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
1088          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
1089          INDEX `resource-id` (`resource-id`),
1090          INDEX `uid_photo-type` (`uid`,`photo-type`),
1091         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1092         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1093 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1094
1095 --
1096 -- TABLE post
1097 --
1098 CREATE TABLE IF NOT EXISTS `post` (
1099         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1100         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1101         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1102         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1103         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1104         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1105         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1106         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1107         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1108         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1109         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1110         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1111         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1112         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1113         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1114         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1115         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1116         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1117          PRIMARY KEY(`uri-id`),
1118          INDEX `parent-uri-id` (`parent-uri-id`),
1119          INDEX `thr-parent-id` (`thr-parent-id`),
1120          INDEX `external-id` (`external-id`),
1121          INDEX `owner-id` (`owner-id`),
1122          INDEX `author-id` (`author-id`),
1123          INDEX `causer-id` (`causer-id`),
1124          INDEX `vid` (`vid`),
1125         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1126         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1127         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1128         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1129         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1130         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1131         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1132         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1133 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
1134
1135 --
1136 -- TABLE post-activity
1137 --
1138 CREATE TABLE IF NOT EXISTS `post-activity` (
1139         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1140         `activity` mediumtext COMMENT 'Original activity',
1141         `received` datetime COMMENT '',
1142          PRIMARY KEY(`uri-id`),
1143         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1144 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Original remote activity';
1145
1146 --
1147 -- TABLE post-category
1148 --
1149 CREATE TABLE IF NOT EXISTS `post-category` (
1150         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1151         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1152         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1153         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1154          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1155          INDEX `tid` (`tid`),
1156          INDEX `uid_uri-id` (`uid`,`uri-id`),
1157         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1158         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1159         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1160 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1161
1162 --
1163 -- TABLE post-collection
1164 --
1165 CREATE TABLE IF NOT EXISTS `post-collection` (
1166         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1167         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0 - Featured',
1168         `author-id` int unsigned COMMENT 'Author of the featured post',
1169          PRIMARY KEY(`uri-id`,`type`),
1170          INDEX `type` (`type`),
1171          INDEX `author-id` (`author-id`),
1172         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1173         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1174 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Collection of posts';
1175
1176 --
1177 -- TABLE post-content
1178 --
1179 CREATE TABLE IF NOT EXISTS `post-content` (
1180         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1181         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1182         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1183         `body` mediumtext COMMENT 'item body content',
1184         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1185         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1186         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1187         `language` text COMMENT 'Language information about this post',
1188         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1189         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1190         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1191         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1192         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1193         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1194         `target` text COMMENT 'JSON encoded target structure if used',
1195         `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',
1196         `plink` varbinary(383) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1197          PRIMARY KEY(`uri-id`),
1198          INDEX `plink` (`plink`(191)),
1199          INDEX `resource-id` (`resource-id`),
1200          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1201         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1202 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1203
1204 --
1205 -- TABLE post-delivery
1206 --
1207 CREATE TABLE IF NOT EXISTS `post-delivery` (
1208         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1209         `inbox-id` int unsigned NOT NULL COMMENT 'Item-uri id of inbox url',
1210         `uid` mediumint unsigned COMMENT 'Delivering user',
1211         `created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
1212         `command` varbinary(32) COMMENT '',
1213         `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
1214         `receivers` mediumtext COMMENT 'JSON encoded array with the receiving contacts',
1215          PRIMARY KEY(`uri-id`,`inbox-id`),
1216          INDEX `inbox-id_created` (`inbox-id`,`created`),
1217          INDEX `uid` (`uid`),
1218         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1219         FOREIGN KEY (`inbox-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1220         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1221 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for posts for the batch processing';
1222
1223 --
1224 -- TABLE post-delivery-data
1225 --
1226 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1227         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1228         `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',
1229         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1230         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1231         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1232         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1233         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1234         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1235         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1236         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1237         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1238          PRIMARY KEY(`uri-id`),
1239         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1240 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1241
1242 --
1243 -- TABLE post-history
1244 --
1245 CREATE TABLE IF NOT EXISTS `post-history` (
1246         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1247         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of edit',
1248         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1249         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1250         `body` mediumtext COMMENT 'item body content',
1251         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1252         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1253         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1254         `language` text COMMENT 'Language information about this post',
1255         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1256         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1257         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1258         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1259         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1260         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1261         `target` text COMMENT 'JSON encoded target structure if used',
1262         `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',
1263         `plink` varbinary(383) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1264          PRIMARY KEY(`uri-id`,`edited`),
1265         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1266 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post history';
1267
1268 --
1269 -- TABLE post-link
1270 --
1271 CREATE TABLE IF NOT EXISTS `post-link` (
1272         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1273         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1274         `url` varbinary(511) NOT NULL COMMENT 'External URL',
1275         `mimetype` varchar(60) COMMENT '',
1276          PRIMARY KEY(`id`),
1277          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1278         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1279 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post related external links';
1280
1281 --
1282 -- TABLE post-media
1283 --
1284 CREATE TABLE IF NOT EXISTS `post-media` (
1285         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1286         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1287         `url` varbinary(1024) NOT NULL COMMENT 'Media URL',
1288         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1289         `mimetype` varchar(60) COMMENT '',
1290         `height` smallint unsigned COMMENT 'Height of the media',
1291         `width` smallint unsigned COMMENT 'Width of the media',
1292         `size` bigint unsigned COMMENT 'Media size',
1293         `preview` varbinary(512) COMMENT 'Preview URL',
1294         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1295         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1296         `description` text COMMENT '',
1297         `name` varchar(255) COMMENT 'Name of the media',
1298         `author-url` varbinary(383) COMMENT 'URL of the author of the media',
1299         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1300         `author-image` varbinary(383) COMMENT 'Image of the author of the media',
1301         `publisher-url` varbinary(383) COMMENT 'URL of the publisher of the media',
1302         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1303         `publisher-image` varbinary(383) COMMENT 'Image of the publisher of the media',
1304          PRIMARY KEY(`id`),
1305          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`(512)),
1306          INDEX `uri-id-id` (`uri-id`,`id`),
1307         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1308 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1309
1310 --
1311 -- TABLE post-question
1312 --
1313 CREATE TABLE IF NOT EXISTS `post-question` (
1314         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1315         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1316         `multiple` boolean NOT NULL DEFAULT '0' COMMENT 'Multiple choice',
1317         `voters` int unsigned COMMENT 'Number of voters for this question',
1318         `end-time` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Question end time',
1319          PRIMARY KEY(`id`),
1320          UNIQUE INDEX `uri-id` (`uri-id`),
1321         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1322 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question';
1323
1324 --
1325 -- TABLE post-question-option
1326 --
1327 CREATE TABLE IF NOT EXISTS `post-question-option` (
1328         `id` int unsigned NOT NULL COMMENT 'Id of the question',
1329         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1330         `name` varchar(255) COMMENT 'Name of the option',
1331         `replies` int unsigned COMMENT 'Number of replies for this question option',
1332          PRIMARY KEY(`uri-id`,`id`),
1333         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1334 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Question option';
1335
1336 --
1337 -- TABLE post-tag
1338 --
1339 CREATE TABLE IF NOT EXISTS `post-tag` (
1340         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1341         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1342         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1343         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1344          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1345          INDEX `tid` (`tid`),
1346          INDEX `cid` (`cid`),
1347         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1348         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1349         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1350 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1351
1352 --
1353 -- TABLE post-thread
1354 --
1355 CREATE TABLE IF NOT EXISTS `post-thread` (
1356         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1357         `conversation-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the conversation uri',
1358         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1359         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1360         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1361         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1362         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1363         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1364         `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',
1365         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1366          PRIMARY KEY(`uri-id`),
1367          INDEX `conversation-id` (`conversation-id`),
1368          INDEX `owner-id` (`owner-id`),
1369          INDEX `author-id` (`author-id`),
1370          INDEX `causer-id` (`causer-id`),
1371          INDEX `received` (`received`),
1372          INDEX `commented` (`commented`),
1373         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1374         FOREIGN KEY (`conversation-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1375         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1376         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1377         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1378 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1379
1380 --
1381 -- TABLE post-user
1382 --
1383 CREATE TABLE IF NOT EXISTS `post-user` (
1384         `id` int unsigned NOT NULL auto_increment,
1385         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1386         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1387         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1388         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1389         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1390         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1391         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1392         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1393         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1394         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1395         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1396         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1397         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1398         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1399         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1400         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1401         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1402         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1403         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1404         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1405         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1406         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1407         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1408         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1409         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1410         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1411         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1412         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1413         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1414          PRIMARY KEY(`id`),
1415          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1416          INDEX `uri-id` (`uri-id`),
1417          INDEX `parent-uri-id` (`parent-uri-id`),
1418          INDEX `thr-parent-id` (`thr-parent-id`),
1419          INDEX `external-id` (`external-id`),
1420          INDEX `owner-id` (`owner-id`),
1421          INDEX `author-id` (`author-id`),
1422          INDEX `causer-id` (`causer-id`),
1423          INDEX `vid` (`vid`),
1424          INDEX `contact-id` (`contact-id`),
1425          INDEX `event-id` (`event-id`),
1426          INDEX `psid` (`psid`),
1427          INDEX `author-id_uid` (`author-id`,`uid`),
1428          INDEX `author-id_received` (`author-id`,`received`),
1429          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1430          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1431          INDEX `uid_contactid` (`uid`,`contact-id`),
1432          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1433          INDEX `uid_unseen` (`uid`,`unseen`),
1434          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1435         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1436         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1437         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1438         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1439         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1440         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1441         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1442         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1443         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1444         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1445         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1446         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1447 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1448
1449 --
1450 -- TABLE post-thread-user
1451 --
1452 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1453         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1454         `conversation-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the conversation uri',
1455         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1456         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1457         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1458         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1459         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1460         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1461         `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',
1462         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1463         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1464         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'deprecated',
1465         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1466         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1467         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1468         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1469         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1470         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Deprecated',
1471         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1472         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1473         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1474         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1475         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1476         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1477          PRIMARY KEY(`uid`,`uri-id`),
1478          INDEX `uri-id` (`uri-id`),
1479          INDEX `conversation-id` (`conversation-id`),
1480          INDEX `owner-id` (`owner-id`),
1481          INDEX `author-id` (`author-id`),
1482          INDEX `causer-id` (`causer-id`),
1483          INDEX `uid` (`uid`),
1484          INDEX `contact-id` (`contact-id`),
1485          INDEX `psid` (`psid`),
1486          INDEX `post-user-id` (`post-user-id`),
1487          INDEX `commented` (`commented`),
1488          INDEX `uid_received` (`uid`,`received`),
1489          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1490          INDEX `uid_commented` (`uid`,`commented`),
1491          INDEX `uid_starred` (`uid`,`starred`),
1492          INDEX `uid_mention` (`uid`,`mention`),
1493         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1494         FOREIGN KEY (`conversation-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1495         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1496         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1497         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1498         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1499         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1500         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1501         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1502 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1503
1504 --
1505 -- TABLE post-user-notification
1506 --
1507 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1508         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1509         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1510         `notification-type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1511          PRIMARY KEY(`uid`,`uri-id`),
1512          INDEX `uri-id` (`uri-id`),
1513         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1514         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1515 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1516
1517 --
1518 -- TABLE process
1519 --
1520 CREATE TABLE IF NOT EXISTS `process` (
1521         `pid` int unsigned NOT NULL COMMENT 'The ID of the process',
1522         `hostname` varchar(32) NOT NULL COMMENT 'The name of the host the process is ran on',
1523         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1524         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1525          PRIMARY KEY(`pid`,`hostname`),
1526          INDEX `command` (`command`)
1527 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1528
1529 --
1530 -- TABLE profile
1531 --
1532 CREATE TABLE IF NOT EXISTS `profile` (
1533         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1534         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1535         `profile-name` varchar(255) COMMENT 'Deprecated',
1536         `is-default` boolean COMMENT 'Deprecated',
1537         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1538         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1539         `pdesc` varchar(255) COMMENT 'Deprecated',
1540         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1541         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1542         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1543         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1544         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1545         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1546         `hometown` varchar(255) COMMENT 'Deprecated',
1547         `gender` varchar(32) COMMENT 'Deprecated',
1548         `marital` varchar(255) COMMENT 'Deprecated',
1549         `with` text COMMENT 'Deprecated',
1550         `howlong` datetime COMMENT 'Deprecated',
1551         `sexual` varchar(255) COMMENT 'Deprecated',
1552         `politic` varchar(255) COMMENT 'Deprecated',
1553         `religion` varchar(255) COMMENT 'Deprecated',
1554         `pub_keywords` text COMMENT '',
1555         `prv_keywords` text COMMENT '',
1556         `likes` text COMMENT 'Deprecated',
1557         `dislikes` text COMMENT 'Deprecated',
1558         `about` text COMMENT 'Profile description',
1559         `summary` varchar(255) COMMENT 'Deprecated',
1560         `music` text COMMENT 'Deprecated',
1561         `book` text COMMENT 'Deprecated',
1562         `tv` text COMMENT 'Deprecated',
1563         `film` text COMMENT 'Deprecated',
1564         `interest` text COMMENT 'Deprecated',
1565         `romance` text COMMENT 'Deprecated',
1566         `work` text COMMENT 'Deprecated',
1567         `education` text COMMENT 'Deprecated',
1568         `contact` text COMMENT 'Deprecated',
1569         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1570         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
1571         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
1572         `photo` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1573         `thumb` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1574         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1575         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1576          PRIMARY KEY(`id`),
1577          INDEX `uid_is-default` (`uid`,`is-default`),
1578          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1579         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1580 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1581
1582 --
1583 -- TABLE profile_field
1584 --
1585 CREATE TABLE IF NOT EXISTS `profile_field` (
1586         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1587         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1588         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1589         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1590         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1591         `value` text COMMENT 'Value of the field',
1592         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1593         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1594          PRIMARY KEY(`id`),
1595          INDEX `uid` (`uid`),
1596          INDEX `order` (`order`),
1597          INDEX `psid` (`psid`),
1598         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1599         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1600 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1601
1602 --
1603 -- TABLE push_subscriber
1604 --
1605 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1606         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1607         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1608         `callback_url` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
1609         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1610         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1611         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1612         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1613         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1614         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1615         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1616          PRIMARY KEY(`id`),
1617          INDEX `next_try` (`next_try`),
1618          INDEX `uid` (`uid`),
1619         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1620 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1621
1622 --
1623 -- TABLE register
1624 --
1625 CREATE TABLE IF NOT EXISTS `register` (
1626         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1627         `hash` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1628         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1629         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1630         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1631         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1632         `note` text COMMENT '',
1633          PRIMARY KEY(`id`),
1634          INDEX `uid` (`uid`),
1635         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1636 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1637
1638 --
1639 -- TABLE search
1640 --
1641 CREATE TABLE IF NOT EXISTS `search` (
1642         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1643         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1644         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1645          PRIMARY KEY(`id`),
1646          INDEX `uid_term` (`uid`,`term`(64)),
1647          INDEX `term` (`term`(64)),
1648         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1649 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1650
1651 --
1652 -- TABLE session
1653 --
1654 CREATE TABLE IF NOT EXISTS `session` (
1655         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1656         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1657         `data` text COMMENT '',
1658         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1659          PRIMARY KEY(`id`),
1660          INDEX `sid` (`sid`(64)),
1661          INDEX `expire` (`expire`)
1662 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1663
1664 --
1665 -- TABLE storage
1666 --
1667 CREATE TABLE IF NOT EXISTS `storage` (
1668         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1669         `data` longblob NOT NULL COMMENT 'file data',
1670          PRIMARY KEY(`id`)
1671 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1672
1673 --
1674 -- TABLE subscription
1675 --
1676 CREATE TABLE IF NOT EXISTS `subscription` (
1677         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1678         `application-id` int unsigned NOT NULL COMMENT '',
1679         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
1680         `endpoint` varchar(511) COMMENT 'Endpoint URL',
1681         `pubkey` varchar(127) COMMENT 'User agent public key',
1682         `secret` varchar(32) COMMENT 'Auth secret',
1683         `follow` boolean COMMENT '',
1684         `favourite` boolean COMMENT '',
1685         `reblog` boolean COMMENT '',
1686         `mention` boolean COMMENT '',
1687         `poll` boolean COMMENT '',
1688         `follow_request` boolean COMMENT '',
1689         `status` boolean COMMENT '',
1690          PRIMARY KEY(`id`),
1691          UNIQUE INDEX `application-id_uid` (`application-id`,`uid`),
1692          INDEX `uid_application-id` (`uid`,`application-id`),
1693         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1694         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1695 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Push Subscription for the API';
1696
1697 --
1698 -- TABLE userd
1699 --
1700 CREATE TABLE IF NOT EXISTS `userd` (
1701         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1702         `username` varchar(255) NOT NULL COMMENT '',
1703          PRIMARY KEY(`id`),
1704          INDEX `username` (`username`(32))
1705 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1706
1707 --
1708 -- TABLE user-contact
1709 --
1710 CREATE TABLE IF NOT EXISTS `user-contact` (
1711         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1712         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1713         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
1714         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1715         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1716         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1717         `hidden` boolean COMMENT 'This contact is hidden from the others',
1718         `is-blocked` boolean COMMENT 'User is blocked by this contact',
1719         `pending` boolean COMMENT '',
1720         `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
1721         `info` mediumtext COMMENT '',
1722         `notify_new_posts` boolean COMMENT '',
1723         `remote_self` boolean COMMENT '',
1724         `fetch_further_information` tinyint unsigned COMMENT '',
1725         `ffi_keyword_denylist` text COMMENT '',
1726         `subhub` boolean COMMENT '',
1727         `hub-verify` varbinary(383) COMMENT '',
1728         `protocol` char(4) COMMENT 'Protocol of the contact',
1729         `rating` tinyint COMMENT 'Automatically detected feed poll frequency',
1730         `priority` tinyint unsigned COMMENT 'Feed poll priority',
1731          PRIMARY KEY(`uid`,`cid`),
1732          INDEX `cid` (`cid`),
1733          UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
1734         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1735         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1736         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1737 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1738
1739 --
1740 -- TABLE arrived-activity
1741 --
1742 CREATE TABLE IF NOT EXISTS `arrived-activity` (
1743         `object-id` varbinary(383) NOT NULL COMMENT 'object id of the incoming activity',
1744         `received` datetime COMMENT 'Receiving date',
1745          PRIMARY KEY(`object-id`)
1746 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Id of arrived activities';
1747
1748 --
1749 -- TABLE fetched-activity
1750 --
1751 CREATE TABLE IF NOT EXISTS `fetched-activity` (
1752         `object-id` varbinary(383) NOT NULL COMMENT 'object id of fetched activity',
1753         `received` datetime COMMENT 'Receiving date',
1754          PRIMARY KEY(`object-id`)
1755 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Id of fetched activities';
1756
1757 --
1758 -- TABLE worker-ipc
1759 --
1760 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1761         `key` int NOT NULL COMMENT '',
1762         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1763          PRIMARY KEY(`key`)
1764 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1765
1766 --
1767 -- VIEW application-view
1768 --
1769 DROP VIEW IF EXISTS `application-view`;
1770 CREATE VIEW `application-view` AS SELECT 
1771         `application`.`id` AS `id`,
1772         `application-token`.`uid` AS `uid`,
1773         `application`.`name` AS `name`,
1774         `application`.`redirect_uri` AS `redirect_uri`,
1775         `application`.`website` AS `website`,
1776         `application`.`client_id` AS `client_id`,
1777         `application`.`client_secret` AS `client_secret`,
1778         `application-token`.`code` AS `code`,
1779         `application-token`.`access_token` AS `access_token`,
1780         `application-token`.`created_at` AS `created_at`,
1781         `application-token`.`scopes` AS `scopes`,
1782         `application-token`.`read` AS `read`,
1783         `application-token`.`write` AS `write`,
1784         `application-token`.`follow` AS `follow`,
1785         `application-token`.`push` AS `push`
1786         FROM `application-token`
1787                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1788
1789 --
1790 -- VIEW post-user-view
1791 --
1792 DROP VIEW IF EXISTS `post-user-view`;
1793 CREATE VIEW `post-user-view` AS SELECT 
1794         `post-user`.`id` AS `id`,
1795         `post-user`.`id` AS `post-user-id`,
1796         `post-user`.`uid` AS `uid`,
1797         `parent-post`.`id` AS `parent`,
1798         `item-uri`.`uri` AS `uri`,
1799         `post-user`.`uri-id` AS `uri-id`,
1800         `parent-item-uri`.`uri` AS `parent-uri`,
1801         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1802         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1803         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1804         `conversation-item-uri`.`uri` AS `conversation`,
1805         `post-thread-user`.`conversation-id` AS `conversation-id`,
1806         `item-uri`.`guid` AS `guid`,
1807         `post-user`.`wall` AS `wall`,
1808         `post-user`.`gravity` AS `gravity`,
1809         `external-item-uri`.`uri` AS `extid`,
1810         `post-user`.`external-id` AS `external-id`,
1811         `post-user`.`created` AS `created`,
1812         `post-user`.`edited` AS `edited`,
1813         `post-thread-user`.`commented` AS `commented`,
1814         `post-user`.`received` AS `received`,
1815         `post-thread-user`.`changed` AS `changed`,
1816         `post-user`.`post-type` AS `post-type`,
1817         `post-user`.`post-reason` AS `post-reason`,
1818         `post-user`.`private` AS `private`,
1819         `post-thread-user`.`pubmail` AS `pubmail`,
1820         `post-user`.`visible` AS `visible`,
1821         `post-thread-user`.`starred` AS `starred`,
1822         `post-user`.`unseen` AS `unseen`,
1823         `post-user`.`deleted` AS `deleted`,
1824         `post-user`.`origin` AS `origin`,
1825         `post-thread-user`.`origin` AS `parent-origin`,
1826         `post-thread-user`.`mention` AS `mention`,
1827         `post-user`.`global` AS `global`,
1828         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
1829         `post-user`.`network` AS `network`,
1830         `post-user`.`protocol` AS `protocol`,
1831         `post-user`.`vid` AS `vid`,
1832         `post-user`.`psid` AS `psid`,
1833         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1834         `post-content`.`title` AS `title`,
1835         `post-content`.`content-warning` AS `content-warning`,
1836         `post-content`.`raw-body` AS `raw-body`,
1837         IFNULL (`post-content`.`body`, '') AS `body`,
1838         `post-content`.`rendered-hash` AS `rendered-hash`,
1839         `post-content`.`rendered-html` AS `rendered-html`,
1840         `post-content`.`language` AS `language`,
1841         `post-content`.`plink` AS `plink`,
1842         `post-content`.`location` AS `location`,
1843         `post-content`.`coord` AS `coord`,
1844         `post-content`.`app` AS `app`,
1845         `post-content`.`object-type` AS `object-type`,
1846         `post-content`.`object` AS `object`,
1847         `post-content`.`target-type` AS `target-type`,
1848         `post-content`.`target` AS `target`,
1849         `post-content`.`resource-id` AS `resource-id`,
1850         `post-user`.`contact-id` AS `contact-id`,
1851         `contact`.`uri-id` AS `contact-uri-id`,
1852         `contact`.`url` AS `contact-link`,
1853         `contact`.`addr` AS `contact-addr`,
1854         `contact`.`name` AS `contact-name`,
1855         `contact`.`nick` AS `contact-nick`,
1856         `contact`.`thumb` AS `contact-avatar`,
1857         `contact`.`network` AS `contact-network`,
1858         `contact`.`blocked` AS `contact-blocked`,
1859         `contact`.`hidden` AS `contact-hidden`,
1860         `contact`.`readonly` AS `contact-readonly`,
1861         `contact`.`archive` AS `contact-archive`,
1862         `contact`.`pending` AS `contact-pending`,
1863         `contact`.`rel` AS `contact-rel`,
1864         `contact`.`uid` AS `contact-uid`,
1865         `contact`.`contact-type` AS `contact-contact-type`,
1866         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1867         `contact`.`self` AS `self`,
1868         `contact`.`id` AS `cid`,
1869         `contact`.`alias` AS `alias`,
1870         `contact`.`photo` AS `photo`,
1871         `contact`.`name-date` AS `name-date`,
1872         `contact`.`uri-date` AS `uri-date`,
1873         `contact`.`avatar-date` AS `avatar-date`,
1874         `contact`.`thumb` AS `thumb`,
1875         `post-user`.`author-id` AS `author-id`,
1876         `author`.`uri-id` AS `author-uri-id`,
1877         `author`.`url` AS `author-link`,
1878         `author`.`addr` AS `author-addr`,
1879         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1880         `author`.`nick` AS `author-nick`,
1881         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1882         `author`.`network` AS `author-network`,
1883         `author`.`blocked` AS `author-blocked`,
1884         `author`.`hidden` AS `author-hidden`,
1885         `author`.`updated` AS `author-updated`,
1886         `author`.`gsid` AS `author-gsid`,
1887         `post-user`.`owner-id` AS `owner-id`,
1888         `owner`.`uri-id` AS `owner-uri-id`,
1889         `owner`.`url` AS `owner-link`,
1890         `owner`.`addr` AS `owner-addr`,
1891         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1892         `owner`.`nick` AS `owner-nick`,
1893         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1894         `owner`.`network` AS `owner-network`,
1895         `owner`.`blocked` AS `owner-blocked`,
1896         `owner`.`hidden` AS `owner-hidden`,
1897         `owner`.`updated` AS `owner-updated`,
1898         `owner`.`contact-type` AS `owner-contact-type`,
1899         `post-user`.`causer-id` AS `causer-id`,
1900         `causer`.`uri-id` AS `causer-uri-id`,
1901         `causer`.`url` AS `causer-link`,
1902         `causer`.`addr` AS `causer-addr`,
1903         `causer`.`name` AS `causer-name`,
1904         `causer`.`nick` AS `causer-nick`,
1905         `causer`.`thumb` AS `causer-avatar`,
1906         `causer`.`network` AS `causer-network`,
1907         `causer`.`blocked` AS `causer-blocked`,
1908         `causer`.`hidden` AS `causer-hidden`,
1909         `causer`.`contact-type` AS `causer-contact-type`,
1910         `post-delivery-data`.`postopts` AS `postopts`,
1911         `post-delivery-data`.`inform` AS `inform`,
1912         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1913         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1914         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1915         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1916         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1917         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1918         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1919         `post-user`.`event-id` AS `event-id`,
1920         `event`.`created` AS `event-created`,
1921         `event`.`edited` AS `event-edited`,
1922         `event`.`start` AS `event-start`,
1923         `event`.`finish` AS `event-finish`,
1924         `event`.`summary` AS `event-summary`,
1925         `event`.`desc` AS `event-desc`,
1926         `event`.`location` AS `event-location`,
1927         `event`.`type` AS `event-type`,
1928         `event`.`nofinish` AS `event-nofinish`,
1929         `event`.`ignore` AS `event-ignore`,
1930         `post-question`.`id` AS `question-id`,
1931         `post-question`.`multiple` AS `question-multiple`,
1932         `post-question`.`voters` AS `question-voters`,
1933         `post-question`.`end-time` AS `question-end-time`,
1934         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`,
1935         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-user`.`uri-id`) AS `has-media`,
1936         `diaspora-interaction`.`interaction` AS `signed_text`,
1937         `parent-item-uri`.`guid` AS `parent-guid`,
1938         `parent-post`.`network` AS `parent-network`,
1939         `parent-post`.`author-id` AS `parent-author-id`,
1940         `parent-post-author`.`url` AS `parent-author-link`,
1941         `parent-post-author`.`name` AS `parent-author-name`,
1942         `parent-post-author`.`nick` AS `parent-author-nick`,
1943         `parent-post-author`.`network` AS `parent-author-network`,
1944         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1945         `parent-post-author`.`hidden` AS `parent-author-hidden`
1946         FROM `post-user`
1947                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1948                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1949                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1950                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1951                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1952                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1953                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1954                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1955                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
1956                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1957                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1958                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1959                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1960                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1961                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1962                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
1963                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1964                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1965                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1966
1967 --
1968 -- VIEW post-thread-user-view
1969 --
1970 DROP VIEW IF EXISTS `post-thread-user-view`;
1971 CREATE VIEW `post-thread-user-view` AS SELECT 
1972         `post-user`.`id` AS `id`,
1973         `post-user`.`id` AS `post-user-id`,
1974         `post-thread-user`.`uid` AS `uid`,
1975         `parent-post`.`id` AS `parent`,
1976         `item-uri`.`uri` AS `uri`,
1977         `post-thread-user`.`uri-id` AS `uri-id`,
1978         `parent-item-uri`.`uri` AS `parent-uri`,
1979         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1980         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1981         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1982         `conversation-item-uri`.`uri` AS `conversation`,
1983         `post-thread-user`.`conversation-id` AS `conversation-id`,
1984         `item-uri`.`guid` AS `guid`,
1985         `post-thread-user`.`wall` AS `wall`,
1986         `post-user`.`gravity` AS `gravity`,
1987         `external-item-uri`.`uri` AS `extid`,
1988         `post-user`.`external-id` AS `external-id`,
1989         `post-thread-user`.`created` AS `created`,
1990         `post-user`.`edited` AS `edited`,
1991         `post-thread-user`.`commented` AS `commented`,
1992         `post-thread-user`.`received` AS `received`,
1993         `post-thread-user`.`changed` AS `changed`,
1994         `post-user`.`post-type` AS `post-type`,
1995         `post-user`.`post-reason` AS `post-reason`,
1996         `post-user`.`private` AS `private`,
1997         `post-thread-user`.`pubmail` AS `pubmail`,
1998         `post-thread-user`.`ignored` AS `ignored`,
1999         `post-user`.`visible` AS `visible`,
2000         `post-thread-user`.`starred` AS `starred`,
2001         `post-thread-user`.`unseen` AS `unseen`,
2002         `post-user`.`deleted` AS `deleted`,
2003         `post-thread-user`.`origin` AS `origin`,
2004         `post-thread-user`.`mention` AS `mention`,
2005         `post-user`.`global` AS `global`,
2006         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
2007         `post-thread-user`.`network` AS `network`,
2008         `post-user`.`vid` AS `vid`,
2009         `post-thread-user`.`psid` AS `psid`,
2010         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2011         `post-content`.`title` AS `title`,
2012         `post-content`.`content-warning` AS `content-warning`,
2013         `post-content`.`raw-body` AS `raw-body`,
2014         `post-content`.`body` AS `body`,
2015         `post-content`.`rendered-hash` AS `rendered-hash`,
2016         `post-content`.`rendered-html` AS `rendered-html`,
2017         `post-content`.`language` AS `language`,
2018         `post-content`.`plink` AS `plink`,
2019         `post-content`.`location` AS `location`,
2020         `post-content`.`coord` AS `coord`,
2021         `post-content`.`app` AS `app`,
2022         `post-content`.`object-type` AS `object-type`,
2023         `post-content`.`object` AS `object`,
2024         `post-content`.`target-type` AS `target-type`,
2025         `post-content`.`target` AS `target`,
2026         `post-content`.`resource-id` AS `resource-id`,
2027         `post-thread-user`.`contact-id` AS `contact-id`,
2028         `contact`.`uri-id` AS `contact-uri-id`,
2029         `contact`.`url` AS `contact-link`,
2030         `contact`.`addr` AS `contact-addr`,
2031         `contact`.`name` AS `contact-name`,
2032         `contact`.`nick` AS `contact-nick`,
2033         `contact`.`thumb` AS `contact-avatar`,
2034         `contact`.`network` AS `contact-network`,
2035         `contact`.`blocked` AS `contact-blocked`,
2036         `contact`.`hidden` AS `contact-hidden`,
2037         `contact`.`readonly` AS `contact-readonly`,
2038         `contact`.`archive` AS `contact-archive`,
2039         `contact`.`pending` AS `contact-pending`,
2040         `contact`.`rel` AS `contact-rel`,
2041         `contact`.`uid` AS `contact-uid`,
2042         `contact`.`contact-type` AS `contact-contact-type`,
2043         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
2044         `contact`.`self` AS `self`,
2045         `contact`.`id` AS `cid`,
2046         `contact`.`alias` AS `alias`,
2047         `contact`.`photo` AS `photo`,
2048         `contact`.`name-date` AS `name-date`,
2049         `contact`.`uri-date` AS `uri-date`,
2050         `contact`.`avatar-date` AS `avatar-date`,
2051         `contact`.`thumb` AS `thumb`,
2052         `post-thread-user`.`author-id` AS `author-id`,
2053         `author`.`uri-id` AS `author-uri-id`,
2054         `author`.`url` AS `author-link`,
2055         `author`.`addr` AS `author-addr`,
2056         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
2057         `author`.`nick` AS `author-nick`,
2058         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
2059         `author`.`network` AS `author-network`,
2060         `author`.`blocked` AS `author-blocked`,
2061         `author`.`hidden` AS `author-hidden`,
2062         `author`.`updated` AS `author-updated`,
2063         `author`.`gsid` AS `author-gsid`,
2064         `post-thread-user`.`owner-id` AS `owner-id`,
2065         `owner`.`uri-id` AS `owner-uri-id`,
2066         `owner`.`url` AS `owner-link`,
2067         `owner`.`addr` AS `owner-addr`,
2068         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
2069         `owner`.`nick` AS `owner-nick`,
2070         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
2071         `owner`.`network` AS `owner-network`,
2072         `owner`.`blocked` AS `owner-blocked`,
2073         `owner`.`hidden` AS `owner-hidden`,
2074         `owner`.`updated` AS `owner-updated`,
2075         `owner`.`contact-type` AS `owner-contact-type`,
2076         `post-thread-user`.`causer-id` AS `causer-id`,
2077         `causer`.`uri-id` AS `causer-uri-id`,
2078         `causer`.`url` AS `causer-link`,
2079         `causer`.`addr` AS `causer-addr`,
2080         `causer`.`name` AS `causer-name`,
2081         `causer`.`nick` AS `causer-nick`,
2082         `causer`.`thumb` AS `causer-avatar`,
2083         `causer`.`network` AS `causer-network`,
2084         `causer`.`blocked` AS `causer-blocked`,
2085         `causer`.`hidden` AS `causer-hidden`,
2086         `causer`.`contact-type` AS `causer-contact-type`,
2087         `post-delivery-data`.`postopts` AS `postopts`,
2088         `post-delivery-data`.`inform` AS `inform`,
2089         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
2090         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
2091         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
2092         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
2093         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
2094         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
2095         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
2096         `post-user`.`event-id` AS `event-id`,
2097         `event`.`created` AS `event-created`,
2098         `event`.`edited` AS `event-edited`,
2099         `event`.`start` AS `event-start`,
2100         `event`.`finish` AS `event-finish`,
2101         `event`.`summary` AS `event-summary`,
2102         `event`.`desc` AS `event-desc`,
2103         `event`.`location` AS `event-location`,
2104         `event`.`type` AS `event-type`,
2105         `event`.`nofinish` AS `event-nofinish`,
2106         `event`.`ignore` AS `event-ignore`,
2107         `post-question`.`id` AS `question-id`,
2108         `post-question`.`multiple` AS `question-multiple`,
2109         `post-question`.`voters` AS `question-voters`,
2110         `post-question`.`end-time` AS `question-end-time`,
2111         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`,
2112         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-user`.`uri-id`) AS `has-media`,
2113         `diaspora-interaction`.`interaction` AS `signed_text`,
2114         `parent-item-uri`.`guid` AS `parent-guid`,
2115         `parent-post`.`network` AS `parent-network`,
2116         `parent-post`.`author-id` AS `parent-author-id`,
2117         `parent-post-author`.`url` AS `parent-author-link`,
2118         `parent-post-author`.`name` AS `parent-author-name`,
2119         `parent-post-author`.`network` AS `parent-author-network`,
2120         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2121         `parent-post-author`.`hidden` AS `parent-author-hidden`
2122         FROM `post-thread-user`
2123                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2124                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2125                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
2126                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
2127                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
2128                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
2129                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
2130                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
2131                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread-user`.`conversation-id`
2132                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
2133                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
2134                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
2135                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
2136                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
2137                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
2138                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
2139                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
2140                         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`
2141                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2142
2143 --
2144 -- VIEW post-view
2145 --
2146 DROP VIEW IF EXISTS `post-view`;
2147 CREATE VIEW `post-view` AS SELECT 
2148         `item-uri`.`uri` AS `uri`,
2149         `post`.`uri-id` AS `uri-id`,
2150         `parent-item-uri`.`uri` AS `parent-uri`,
2151         `post`.`parent-uri-id` AS `parent-uri-id`,
2152         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2153         `post`.`thr-parent-id` AS `thr-parent-id`,
2154         `conversation-item-uri`.`uri` AS `conversation`,
2155         `post-thread`.`conversation-id` AS `conversation-id`,
2156         `item-uri`.`guid` AS `guid`,
2157         `post`.`gravity` AS `gravity`,
2158         `external-item-uri`.`uri` AS `extid`,
2159         `post`.`external-id` AS `external-id`,
2160         `post`.`created` AS `created`,
2161         `post`.`edited` AS `edited`,
2162         `post-thread`.`commented` AS `commented`,
2163         `post`.`received` AS `received`,
2164         `post-thread`.`changed` AS `changed`,
2165         `post`.`post-type` AS `post-type`,
2166         `post`.`private` AS `private`,
2167         `post`.`visible` AS `visible`,
2168         `post`.`deleted` AS `deleted`,
2169         `post`.`global` AS `global`,
2170         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
2171         `post`.`network` AS `network`,
2172         `post`.`vid` AS `vid`,
2173         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2174         `post-content`.`title` AS `title`,
2175         `post-content`.`content-warning` AS `content-warning`,
2176         `post-content`.`raw-body` AS `raw-body`,
2177         `post-content`.`body` AS `body`,
2178         `post-content`.`rendered-hash` AS `rendered-hash`,
2179         `post-content`.`rendered-html` AS `rendered-html`,
2180         `post-content`.`language` AS `language`,
2181         `post-content`.`plink` AS `plink`,
2182         `post-content`.`location` AS `location`,
2183         `post-content`.`coord` AS `coord`,
2184         `post-content`.`app` AS `app`,
2185         `post-content`.`object-type` AS `object-type`,
2186         `post-content`.`object` AS `object`,
2187         `post-content`.`target-type` AS `target-type`,
2188         `post-content`.`target` AS `target`,
2189         `post-content`.`resource-id` AS `resource-id`,
2190         `post`.`author-id` AS `contact-id`,
2191         `author`.`uri-id` AS `contact-uri-id`,
2192         `author`.`url` AS `contact-link`,
2193         `author`.`addr` AS `contact-addr`,
2194         `author`.`name` AS `contact-name`,
2195         `author`.`nick` AS `contact-nick`,
2196         `author`.`thumb` AS `contact-avatar`,
2197         `author`.`network` AS `contact-network`,
2198         `author`.`blocked` AS `contact-blocked`,
2199         `author`.`hidden` AS `contact-hidden`,
2200         `author`.`readonly` AS `contact-readonly`,
2201         `author`.`archive` AS `contact-archive`,
2202         `author`.`pending` AS `contact-pending`,
2203         `author`.`rel` AS `contact-rel`,
2204         `author`.`uid` AS `contact-uid`,
2205         `author`.`contact-type` AS `contact-contact-type`,
2206         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2207         false AS `self`,
2208         `author`.`id` AS `cid`,
2209         `author`.`alias` AS `alias`,
2210         `author`.`photo` AS `photo`,
2211         `author`.`name-date` AS `name-date`,
2212         `author`.`uri-date` AS `uri-date`,
2213         `author`.`avatar-date` AS `avatar-date`,
2214         `author`.`thumb` AS `thumb`,
2215         `post`.`author-id` AS `author-id`,
2216         `author`.`uri-id` AS `author-uri-id`,
2217         `author`.`url` AS `author-link`,
2218         `author`.`addr` AS `author-addr`,
2219         `author`.`name` AS `author-name`,
2220         `author`.`nick` AS `author-nick`,
2221         `author`.`thumb` AS `author-avatar`,
2222         `author`.`network` AS `author-network`,
2223         `author`.`blocked` AS `author-blocked`,
2224         `author`.`hidden` AS `author-hidden`,
2225         `author`.`updated` AS `author-updated`,
2226         `author`.`gsid` AS `author-gsid`,
2227         `post`.`owner-id` AS `owner-id`,
2228         `owner`.`uri-id` AS `owner-uri-id`,
2229         `owner`.`url` AS `owner-link`,
2230         `owner`.`addr` AS `owner-addr`,
2231         `owner`.`name` AS `owner-name`,
2232         `owner`.`nick` AS `owner-nick`,
2233         `owner`.`thumb` AS `owner-avatar`,
2234         `owner`.`network` AS `owner-network`,
2235         `owner`.`blocked` AS `owner-blocked`,
2236         `owner`.`hidden` AS `owner-hidden`,
2237         `owner`.`updated` AS `owner-updated`,
2238         `owner`.`contact-type` AS `owner-contact-type`,
2239         `post`.`causer-id` AS `causer-id`,
2240         `causer`.`uri-id` AS `causer-uri-id`,
2241         `causer`.`url` AS `causer-link`,
2242         `causer`.`addr` AS `causer-addr`,
2243         `causer`.`name` AS `causer-name`,
2244         `causer`.`nick` AS `causer-nick`,
2245         `causer`.`thumb` AS `causer-avatar`,
2246         `causer`.`network` AS `causer-network`,
2247         `causer`.`blocked` AS `causer-blocked`,
2248         `causer`.`hidden` AS `causer-hidden`,
2249         `causer`.`contact-type` AS `causer-contact-type`,
2250         `post-question`.`id` AS `question-id`,
2251         `post-question`.`multiple` AS `question-multiple`,
2252         `post-question`.`voters` AS `question-voters`,
2253         `post-question`.`end-time` AS `question-end-time`,
2254         0 AS `has-categories`,
2255         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post`.`uri-id`) AS `has-media`,
2256         `diaspora-interaction`.`interaction` AS `signed_text`,
2257         `parent-item-uri`.`guid` AS `parent-guid`,
2258         `parent-post`.`network` AS `parent-network`,
2259         `parent-post`.`author-id` AS `parent-author-id`,
2260         `parent-post-author`.`url` AS `parent-author-link`,
2261         `parent-post-author`.`name` AS `parent-author-name`,
2262         `parent-post-author`.`network` AS `parent-author-network`,
2263         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2264         `parent-post-author`.`hidden` AS `parent-author-hidden`
2265         FROM `post`
2266                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2267                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2268                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2269                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2270                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2271                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2272                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2273                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2274                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2275                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2276                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2277                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2278                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
2279                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2280                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2281
2282 --
2283 -- VIEW post-thread-view
2284 --
2285 DROP VIEW IF EXISTS `post-thread-view`;
2286 CREATE VIEW `post-thread-view` AS SELECT 
2287         `item-uri`.`uri` AS `uri`,
2288         `post-thread`.`uri-id` AS `uri-id`,
2289         `parent-item-uri`.`uri` AS `parent-uri`,
2290         `post`.`parent-uri-id` AS `parent-uri-id`,
2291         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2292         `post`.`thr-parent-id` AS `thr-parent-id`,
2293         `conversation-item-uri`.`uri` AS `conversation`,
2294         `post-thread`.`conversation-id` AS `conversation-id`,
2295         `item-uri`.`guid` AS `guid`,
2296         `post`.`gravity` AS `gravity`,
2297         `external-item-uri`.`uri` AS `extid`,
2298         `post`.`external-id` AS `external-id`,
2299         `post-thread`.`created` AS `created`,
2300         `post`.`edited` AS `edited`,
2301         `post-thread`.`commented` AS `commented`,
2302         `post-thread`.`received` AS `received`,
2303         `post-thread`.`changed` AS `changed`,
2304         `post`.`post-type` AS `post-type`,
2305         `post`.`private` AS `private`,
2306         `post`.`visible` AS `visible`,
2307         `post`.`deleted` AS `deleted`,
2308         `post`.`global` AS `global`,
2309         EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
2310         `post-thread`.`network` AS `network`,
2311         `post`.`vid` AS `vid`,
2312         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2313         `post-content`.`title` AS `title`,
2314         `post-content`.`content-warning` AS `content-warning`,
2315         `post-content`.`raw-body` AS `raw-body`,
2316         `post-content`.`body` AS `body`,
2317         `post-content`.`rendered-hash` AS `rendered-hash`,
2318         `post-content`.`rendered-html` AS `rendered-html`,
2319         `post-content`.`language` AS `language`,
2320         `post-content`.`plink` AS `plink`,
2321         `post-content`.`location` AS `location`,
2322         `post-content`.`coord` AS `coord`,
2323         `post-content`.`app` AS `app`,
2324         `post-content`.`object-type` AS `object-type`,
2325         `post-content`.`object` AS `object`,
2326         `post-content`.`target-type` AS `target-type`,
2327         `post-content`.`target` AS `target`,
2328         `post-content`.`resource-id` AS `resource-id`,
2329         `post-thread`.`author-id` AS `contact-id`,
2330         `author`.`uri-id` AS `contact-uri-id`,
2331         `author`.`url` AS `contact-link`,
2332         `author`.`addr` AS `contact-addr`,
2333         `author`.`name` AS `contact-name`,
2334         `author`.`nick` AS `contact-nick`,
2335         `author`.`thumb` AS `contact-avatar`,
2336         `author`.`network` AS `contact-network`,
2337         `author`.`blocked` AS `contact-blocked`,
2338         `author`.`hidden` AS `contact-hidden`,
2339         `author`.`readonly` AS `contact-readonly`,
2340         `author`.`archive` AS `contact-archive`,
2341         `author`.`pending` AS `contact-pending`,
2342         `author`.`rel` AS `contact-rel`,
2343         `author`.`uid` AS `contact-uid`,
2344         `author`.`contact-type` AS `contact-contact-type`,
2345         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2346         false AS `self`,
2347         `author`.`id` AS `cid`,
2348         `author`.`alias` AS `alias`,
2349         `author`.`photo` AS `photo`,
2350         `author`.`name-date` AS `name-date`,
2351         `author`.`uri-date` AS `uri-date`,
2352         `author`.`avatar-date` AS `avatar-date`,
2353         `author`.`thumb` AS `thumb`,
2354         `post-thread`.`author-id` AS `author-id`,
2355         `author`.`uri-id` AS `author-uri-id`,
2356         `author`.`url` AS `author-link`,
2357         `author`.`addr` AS `author-addr`,
2358         `author`.`name` AS `author-name`,
2359         `author`.`nick` AS `author-nick`,
2360         `author`.`thumb` AS `author-avatar`,
2361         `author`.`network` AS `author-network`,
2362         `author`.`blocked` AS `author-blocked`,
2363         `author`.`hidden` AS `author-hidden`,
2364         `author`.`updated` AS `author-updated`,
2365         `author`.`gsid` AS `author-gsid`,
2366         `post-thread`.`owner-id` AS `owner-id`,
2367         `owner`.`uri-id` AS `owner-uri-id`,
2368         `owner`.`url` AS `owner-link`,
2369         `owner`.`addr` AS `owner-addr`,
2370         `owner`.`name` AS `owner-name`,
2371         `owner`.`nick` AS `owner-nick`,
2372         `owner`.`thumb` AS `owner-avatar`,
2373         `owner`.`network` AS `owner-network`,
2374         `owner`.`blocked` AS `owner-blocked`,
2375         `owner`.`hidden` AS `owner-hidden`,
2376         `owner`.`updated` AS `owner-updated`,
2377         `owner`.`contact-type` AS `owner-contact-type`,
2378         `post-thread`.`causer-id` AS `causer-id`,
2379         `causer`.`uri-id` AS `causer-uri-id`,
2380         `causer`.`url` AS `causer-link`,
2381         `causer`.`addr` AS `causer-addr`,
2382         `causer`.`name` AS `causer-name`,
2383         `causer`.`nick` AS `causer-nick`,
2384         `causer`.`thumb` AS `causer-avatar`,
2385         `causer`.`network` AS `causer-network`,
2386         `causer`.`blocked` AS `causer-blocked`,
2387         `causer`.`hidden` AS `causer-hidden`,
2388         `causer`.`contact-type` AS `causer-contact-type`,
2389         `post-question`.`id` AS `question-id`,
2390         `post-question`.`multiple` AS `question-multiple`,
2391         `post-question`.`voters` AS `question-voters`,
2392         `post-question`.`end-time` AS `question-end-time`,
2393         0 AS `has-categories`,
2394         EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`) AS `has-media`,
2395         `diaspora-interaction`.`interaction` AS `signed_text`,
2396         `parent-item-uri`.`guid` AS `parent-guid`,
2397         `parent-post`.`network` AS `parent-network`,
2398         `parent-post`.`author-id` AS `parent-author-id`,
2399         `parent-post-author`.`url` AS `parent-author-link`,
2400         `parent-post-author`.`name` AS `parent-author-name`,
2401         `parent-post-author`.`network` AS `parent-author-network`,
2402         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2403         `parent-post-author`.`hidden` AS `parent-author-hidden`
2404         FROM `post-thread`
2405                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2406                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2407                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2408                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2409                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2410                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2411                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2412                         LEFT JOIN `item-uri` AS `conversation-item-uri` ON `conversation-item-uri`.`id` = `post-thread`.`conversation-id`
2413                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2414                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2415                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2416                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2417                         LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`
2418                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2419                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2420
2421 --
2422 -- VIEW category-view
2423 --
2424 DROP VIEW IF EXISTS `category-view`;
2425 CREATE VIEW `category-view` AS SELECT 
2426         `post-category`.`uri-id` AS `uri-id`,
2427         `post-category`.`uid` AS `uid`,
2428         `post-category`.`type` AS `type`,
2429         `post-category`.`tid` AS `tid`,
2430         `tag`.`name` AS `name`,
2431         `tag`.`url` AS `url`
2432         FROM `post-category`
2433                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2434
2435 --
2436 -- VIEW collection-view
2437 --
2438 DROP VIEW IF EXISTS `collection-view`;
2439 CREATE VIEW `collection-view` AS SELECT 
2440         `post-collection`.`uri-id` AS `uri-id`,
2441         `post-collection`.`type` AS `type`,
2442         `post-collection`.`author-id` AS `cid`,
2443         `post`.`received` AS `received`,
2444         `post`.`created` AS `created`,
2445         `post-thread`.`commented` AS `commented`,
2446         `post`.`private` AS `private`,
2447         `post`.`visible` AS `visible`,
2448         `post`.`deleted` AS `deleted`,
2449         `post`.`thr-parent-id` AS `thr-parent-id`,
2450         `post-collection`.`author-id` AS `author-id`,
2451         `post`.`gravity` AS `gravity`
2452         FROM `post-collection`
2453                         INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
2454                         INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`;
2455
2456 --
2457 -- VIEW tag-view
2458 --
2459 DROP VIEW IF EXISTS `tag-view`;
2460 CREATE VIEW `tag-view` AS SELECT 
2461         `post-tag`.`uri-id` AS `uri-id`,
2462         `post-tag`.`type` AS `type`,
2463         `post-tag`.`tid` AS `tid`,
2464         `post-tag`.`cid` AS `cid`,
2465         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2466         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`,
2467         CASE `cid` WHEN 0 THEN `tag`.`type` ELSE 1 END AS `tag-type`
2468         FROM `post-tag`
2469                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2470                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2471
2472 --
2473 -- VIEW network-item-view
2474 --
2475 DROP VIEW IF EXISTS `network-item-view`;
2476 CREATE VIEW `network-item-view` AS SELECT 
2477         `post-user`.`uri-id` AS `uri-id`,
2478         `parent-post`.`id` AS `parent`,
2479         `post-user`.`received` AS `received`,
2480         `post-thread-user`.`commented` AS `commented`,
2481         `post-user`.`created` AS `created`,
2482         `post-user`.`uid` AS `uid`,
2483         `post-thread-user`.`starred` AS `starred`,
2484         `post-thread-user`.`mention` AS `mention`,
2485         `post-user`.`network` AS `network`,
2486         `post-user`.`unseen` AS `unseen`,
2487         `post-user`.`gravity` AS `gravity`,
2488         `post-user`.`contact-id` AS `contact-id`,
2489         `ownercontact`.`contact-type` AS `contact-type`
2490         FROM `post-user`
2491                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2492                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2493                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2494                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2495                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2496                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2497                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2498                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2499                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2500                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2501                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2502
2503 --
2504 -- VIEW network-thread-view
2505 --
2506 DROP VIEW IF EXISTS `network-thread-view`;
2507 CREATE VIEW `network-thread-view` AS SELECT 
2508         `post-thread-user`.`uri-id` AS `uri-id`,
2509         `parent-post`.`id` AS `parent`,
2510         `post-thread-user`.`received` AS `received`,
2511         `post-thread-user`.`commented` AS `commented`,
2512         `post-thread-user`.`created` AS `created`,
2513         `post-thread-user`.`uid` AS `uid`,
2514         `post-thread-user`.`starred` AS `starred`,
2515         `post-thread-user`.`mention` AS `mention`,
2516         `post-thread-user`.`network` AS `network`,
2517         `post-thread-user`.`contact-id` AS `contact-id`,
2518         `ownercontact`.`contact-type` AS `contact-type`
2519         FROM `post-thread-user`
2520                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2521                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2522                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2523                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2524                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2525                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2526                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2527                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2528                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2529                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2530                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2531
2532 --
2533 -- VIEW owner-view
2534 --
2535 DROP VIEW IF EXISTS `owner-view`;
2536 CREATE VIEW `owner-view` AS SELECT 
2537         `contact`.`id` AS `id`,
2538         `contact`.`uid` AS `uid`,
2539         `contact`.`created` AS `created`,
2540         `contact`.`updated` AS `updated`,
2541         `contact`.`self` AS `self`,
2542         `contact`.`remote_self` AS `remote_self`,
2543         `contact`.`rel` AS `rel`,
2544         `contact`.`network` AS `network`,
2545         `contact`.`protocol` AS `protocol`,
2546         `contact`.`name` AS `name`,
2547         `contact`.`nick` AS `nick`,
2548         `contact`.`location` AS `location`,
2549         `contact`.`about` AS `about`,
2550         `contact`.`keywords` AS `keywords`,
2551         `contact`.`xmpp` AS `xmpp`,
2552         `contact`.`matrix` AS `matrix`,
2553         `contact`.`attag` AS `attag`,
2554         `contact`.`avatar` AS `avatar`,
2555         `contact`.`photo` AS `photo`,
2556         `contact`.`thumb` AS `thumb`,
2557         `contact`.`micro` AS `micro`,
2558         `contact`.`header` AS `header`,
2559         `contact`.`url` AS `url`,
2560         `contact`.`nurl` AS `nurl`,
2561         `contact`.`uri-id` AS `uri-id`,
2562         `contact`.`addr` AS `addr`,
2563         `contact`.`alias` AS `alias`,
2564         `contact`.`pubkey` AS `pubkey`,
2565         `contact`.`prvkey` AS `prvkey`,
2566         `contact`.`batch` AS `batch`,
2567         `contact`.`request` AS `request`,
2568         `contact`.`notify` AS `notify`,
2569         `contact`.`poll` AS `poll`,
2570         `contact`.`confirm` AS `confirm`,
2571         `contact`.`poco` AS `poco`,
2572         `contact`.`subhub` AS `subhub`,
2573         `contact`.`hub-verify` AS `hub-verify`,
2574         `contact`.`last-update` AS `last-update`,
2575         `contact`.`success_update` AS `success_update`,
2576         `contact`.`failure_update` AS `failure_update`,
2577         `contact`.`name-date` AS `name-date`,
2578         `contact`.`uri-date` AS `uri-date`,
2579         `contact`.`avatar-date` AS `avatar-date`,
2580         `contact`.`avatar-date` AS `picdate`,
2581         `contact`.`term-date` AS `term-date`,
2582         `contact`.`last-item` AS `last-item`,
2583         `contact`.`priority` AS `priority`,
2584         `user`.`blocked` AS `blocked`,
2585         `contact`.`block_reason` AS `block_reason`,
2586         `contact`.`readonly` AS `readonly`,
2587         `contact`.`writable` AS `writable`,
2588         `contact`.`forum` AS `forum`,
2589         `contact`.`prv` AS `prv`,
2590         `contact`.`contact-type` AS `contact-type`,
2591         `contact`.`manually-approve` AS `manually-approve`,
2592         `contact`.`hidden` AS `hidden`,
2593         `contact`.`archive` AS `archive`,
2594         `contact`.`pending` AS `pending`,
2595         `contact`.`deleted` AS `deleted`,
2596         `contact`.`unsearchable` AS `unsearchable`,
2597         `contact`.`sensitive` AS `sensitive`,
2598         `contact`.`baseurl` AS `baseurl`,
2599         `contact`.`reason` AS `reason`,
2600         `contact`.`info` AS `info`,
2601         `contact`.`bdyear` AS `bdyear`,
2602         `contact`.`bd` AS `bd`,
2603         `contact`.`notify_new_posts` AS `notify_new_posts`,
2604         `contact`.`fetch_further_information` AS `fetch_further_information`,
2605         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2606         `user`.`parent-uid` AS `parent-uid`,
2607         `user`.`guid` AS `guid`,
2608         `user`.`nickname` AS `nickname`,
2609         `user`.`email` AS `email`,
2610         `user`.`openid` AS `openid`,
2611         `user`.`timezone` AS `timezone`,
2612         `user`.`language` AS `language`,
2613         `user`.`register_date` AS `register_date`,
2614         `user`.`login_date` AS `login_date`,
2615         `user`.`default-location` AS `default-location`,
2616         `user`.`allow_location` AS `allow_location`,
2617         `user`.`theme` AS `theme`,
2618         `user`.`pubkey` AS `upubkey`,
2619         `user`.`prvkey` AS `uprvkey`,
2620         `user`.`sprvkey` AS `sprvkey`,
2621         `user`.`spubkey` AS `spubkey`,
2622         `user`.`verified` AS `verified`,
2623         `user`.`blockwall` AS `blockwall`,
2624         `user`.`hidewall` AS `hidewall`,
2625         `user`.`blocktags` AS `blocktags`,
2626         `user`.`unkmail` AS `unkmail`,
2627         `user`.`cntunkmail` AS `cntunkmail`,
2628         `user`.`notify-flags` AS `notify-flags`,
2629         `user`.`page-flags` AS `page-flags`,
2630         `user`.`account-type` AS `account-type`,
2631         `user`.`prvnets` AS `prvnets`,
2632         `user`.`maxreq` AS `maxreq`,
2633         `user`.`expire` AS `expire`,
2634         `user`.`account_removed` AS `account_removed`,
2635         `user`.`account_expired` AS `account_expired`,
2636         `user`.`account_expires_on` AS `account_expires_on`,
2637         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2638         `user`.`def_gid` AS `def_gid`,
2639         `user`.`allow_cid` AS `allow_cid`,
2640         `user`.`allow_gid` AS `allow_gid`,
2641         `user`.`deny_cid` AS `deny_cid`,
2642         `user`.`deny_gid` AS `deny_gid`,
2643         `user`.`openidserver` AS `openidserver`,
2644         `profile`.`publish` AS `publish`,
2645         `profile`.`net-publish` AS `net-publish`,
2646         `profile`.`hide-friends` AS `hide-friends`,
2647         `profile`.`prv_keywords` AS `prv_keywords`,
2648         `profile`.`pub_keywords` AS `pub_keywords`,
2649         `profile`.`address` AS `address`,
2650         `profile`.`locality` AS `locality`,
2651         `profile`.`region` AS `region`,
2652         `profile`.`postal-code` AS `postal-code`,
2653         `profile`.`country-name` AS `country-name`,
2654         `profile`.`homepage` AS `homepage`,
2655         `profile`.`dob` AS `dob`
2656         FROM `user`
2657                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2658                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2659
2660 --
2661 -- VIEW account-view
2662 --
2663 DROP VIEW IF EXISTS `account-view`;
2664 CREATE VIEW `account-view` AS SELECT 
2665         `contact`.`id` AS `id`,
2666         `contact`.`url` AS `url`,
2667         `contact`.`nurl` AS `nurl`,
2668         `contact`.`uri-id` AS `uri-id`,
2669         `item-uri`.`guid` AS `guid`,
2670         `contact`.`addr` AS `addr`,
2671         `contact`.`alias` AS `alias`,
2672         `contact`.`name` AS `name`,
2673         `contact`.`nick` AS `nick`,
2674         `contact`.`about` AS `about`,
2675         `contact`.`keywords` AS `keywords`,
2676         `contact`.`xmpp` AS `xmpp`,
2677         `contact`.`matrix` AS `matrix`,
2678         `contact`.`avatar` AS `avatar`,
2679         `contact`.`photo` AS `photo`,
2680         `contact`.`thumb` AS `thumb`,
2681         `contact`.`micro` AS `micro`,
2682         `contact`.`header` AS `header`,
2683         `contact`.`created` AS `created`,
2684         `contact`.`updated` AS `updated`,
2685         `contact`.`network` AS `network`,
2686         `contact`.`protocol` AS `protocol`,
2687         `contact`.`location` AS `location`,
2688         `contact`.`attag` AS `attag`,
2689         `contact`.`pubkey` AS `pubkey`,
2690         `contact`.`prvkey` AS `prvkey`,
2691         `contact`.`subscribe` AS `subscribe`,
2692         `contact`.`last-update` AS `last-update`,
2693         `contact`.`success_update` AS `success_update`,
2694         `contact`.`failure_update` AS `failure_update`,
2695         `contact`.`failed` AS `failed`,
2696         `contact`.`last-item` AS `last-item`,
2697         `contact`.`last-discovery` AS `last-discovery`,
2698         `contact`.`contact-type` AS `contact-type`,
2699         `contact`.`manually-approve` AS `manually-approve`,
2700         `contact`.`unsearchable` AS `unsearchable`,
2701         `contact`.`sensitive` AS `sensitive`,
2702         `contact`.`baseurl` AS `baseurl`,
2703         `contact`.`gsid` AS `gsid`,
2704         `contact`.`info` AS `info`,
2705         `contact`.`bdyear` AS `bdyear`,
2706         `contact`.`bd` AS `bd`,
2707         `contact`.`poco` AS `poco`,
2708         `contact`.`name-date` AS `name-date`,
2709         `contact`.`uri-date` AS `uri-date`,
2710         `contact`.`avatar-date` AS `avatar-date`,
2711         `contact`.`term-date` AS `term-date`,
2712         `contact`.`hidden` AS `global-ignored`,
2713         `contact`.`blocked` AS `global-blocked`,
2714         `contact`.`hidden` AS `hidden`,
2715         `contact`.`archive` AS `archive`,
2716         `contact`.`deleted` AS `deleted`,
2717         `contact`.`blocked` AS `blocked`,
2718         `contact`.`notify` AS `dfrn-notify`,
2719         `contact`.`poll` AS `dfrn-poll`,
2720         `fcontact`.`guid` AS `diaspora-guid`,
2721         `fcontact`.`batch` AS `diaspora-batch`,
2722         `fcontact`.`notify` AS `diaspora-notify`,
2723         `fcontact`.`poll` AS `diaspora-poll`,
2724         `fcontact`.`alias` AS `diaspora-alias`,
2725         `apcontact`.`uuid` AS `ap-uuid`,
2726         `apcontact`.`type` AS `ap-type`,
2727         `apcontact`.`following` AS `ap-following`,
2728         `apcontact`.`followers` AS `ap-followers`,
2729         `apcontact`.`inbox` AS `ap-inbox`,
2730         `apcontact`.`outbox` AS `ap-outbox`,
2731         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2732         `apcontact`.`generator` AS `ap-generator`,
2733         `apcontact`.`following_count` AS `ap-following_count`,
2734         `apcontact`.`followers_count` AS `ap-followers_count`,
2735         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2736         `gserver`.`site_name` AS `site_name`,
2737         `gserver`.`platform` AS `platform`,
2738         `gserver`.`version` AS `version`
2739         FROM `contact`
2740                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
2741                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
2742                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
2743                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`
2744                         WHERE `contact`.`uid` = 0;
2745
2746 --
2747 -- VIEW account-user-view
2748 --
2749 DROP VIEW IF EXISTS `account-user-view`;
2750 CREATE VIEW `account-user-view` AS SELECT 
2751         `ucontact`.`id` AS `id`,
2752         `contact`.`id` AS `pid`,
2753         `ucontact`.`uid` AS `uid`,
2754         `contact`.`url` AS `url`,
2755         `contact`.`nurl` AS `nurl`,
2756         `contact`.`uri-id` AS `uri-id`,
2757         `item-uri`.`guid` AS `guid`,
2758         `contact`.`addr` AS `addr`,
2759         `contact`.`alias` AS `alias`,
2760         `contact`.`name` AS `name`,
2761         `contact`.`nick` AS `nick`,
2762         `contact`.`about` AS `about`,
2763         `contact`.`keywords` AS `keywords`,
2764         `contact`.`xmpp` AS `xmpp`,
2765         `contact`.`matrix` AS `matrix`,
2766         `contact`.`avatar` AS `avatar`,
2767         `contact`.`photo` AS `photo`,
2768         `contact`.`thumb` AS `thumb`,
2769         `contact`.`micro` AS `micro`,
2770         `contact`.`header` AS `header`,
2771         `contact`.`created` AS `created`,
2772         `contact`.`updated` AS `updated`,
2773         `ucontact`.`self` AS `self`,
2774         `ucontact`.`remote_self` AS `remote_self`,
2775         `ucontact`.`rel` AS `rel`,
2776         `contact`.`network` AS `network`,
2777         `ucontact`.`protocol` AS `protocol`,
2778         `contact`.`location` AS `location`,
2779         `ucontact`.`attag` AS `attag`,
2780         `contact`.`pubkey` AS `pubkey`,
2781         `contact`.`prvkey` AS `prvkey`,
2782         `contact`.`subscribe` AS `subscribe`,
2783         `contact`.`last-update` AS `last-update`,
2784         `contact`.`success_update` AS `success_update`,
2785         `contact`.`failure_update` AS `failure_update`,
2786         `contact`.`failed` AS `failed`,
2787         `contact`.`last-item` AS `last-item`,
2788         `contact`.`last-discovery` AS `last-discovery`,
2789         `contact`.`contact-type` AS `contact-type`,
2790         `contact`.`manually-approve` AS `manually-approve`,
2791         `contact`.`unsearchable` AS `unsearchable`,
2792         `contact`.`sensitive` AS `sensitive`,
2793         `contact`.`baseurl` AS `baseurl`,
2794         `contact`.`gsid` AS `gsid`,
2795         `ucontact`.`info` AS `info`,
2796         `contact`.`bdyear` AS `bdyear`,
2797         `contact`.`bd` AS `bd`,
2798         `contact`.`poco` AS `poco`,
2799         `contact`.`name-date` AS `name-date`,
2800         `contact`.`uri-date` AS `uri-date`,
2801         `contact`.`avatar-date` AS `avatar-date`,
2802         `contact`.`term-date` AS `term-date`,
2803         `contact`.`hidden` AS `global-ignored`,
2804         `contact`.`blocked` AS `global-blocked`,
2805         `ucontact`.`hidden` AS `hidden`,
2806         `ucontact`.`archive` AS `archive`,
2807         `ucontact`.`pending` AS `pending`,
2808         `ucontact`.`deleted` AS `deleted`,
2809         `ucontact`.`notify_new_posts` AS `notify_new_posts`,
2810         `ucontact`.`fetch_further_information` AS `fetch_further_information`,
2811         `ucontact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2812         `ucontact`.`rating` AS `rating`,
2813         `ucontact`.`readonly` AS `readonly`,
2814         `ucontact`.`blocked` AS `blocked`,
2815         `ucontact`.`block_reason` AS `block_reason`,
2816         `ucontact`.`subhub` AS `subhub`,
2817         `ucontact`.`hub-verify` AS `hub-verify`,
2818         `ucontact`.`reason` AS `reason`,
2819         `contact`.`notify` AS `dfrn-notify`,
2820         `contact`.`poll` AS `dfrn-poll`,
2821         `fcontact`.`guid` AS `diaspora-guid`,
2822         `fcontact`.`batch` AS `diaspora-batch`,
2823         `fcontact`.`notify` AS `diaspora-notify`,
2824         `fcontact`.`poll` AS `diaspora-poll`,
2825         `fcontact`.`alias` AS `diaspora-alias`,
2826         `fcontact`.`interacting_count` AS `diaspora-interacting_count`,
2827         `fcontact`.`interacted_count` AS `diaspora-interacted_count`,
2828         `fcontact`.`post_count` AS `diaspora-post_count`,
2829         `apcontact`.`uuid` AS `ap-uuid`,
2830         `apcontact`.`type` AS `ap-type`,
2831         `apcontact`.`following` AS `ap-following`,
2832         `apcontact`.`followers` AS `ap-followers`,
2833         `apcontact`.`inbox` AS `ap-inbox`,
2834         `apcontact`.`outbox` AS `ap-outbox`,
2835         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2836         `apcontact`.`generator` AS `ap-generator`,
2837         `apcontact`.`following_count` AS `ap-following_count`,
2838         `apcontact`.`followers_count` AS `ap-followers_count`,
2839         `apcontact`.`statuses_count` AS `ap-statuses_count`,
2840         `gserver`.`site_name` AS `site_name`,
2841         `gserver`.`platform` AS `platform`,
2842         `gserver`.`version` AS `version`
2843         FROM `contact` AS `ucontact`
2844                         INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
2845                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
2846                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
2847                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr'
2848                         LEFT JOIN `gserver` ON `gserver`.`id` = contact.`gsid`;
2849
2850 --
2851 -- VIEW pending-view
2852 --
2853 DROP VIEW IF EXISTS `pending-view`;
2854 CREATE VIEW `pending-view` AS SELECT 
2855         `register`.`id` AS `id`,
2856         `register`.`hash` AS `hash`,
2857         `register`.`created` AS `created`,
2858         `register`.`uid` AS `uid`,
2859         `register`.`password` AS `password`,
2860         `register`.`language` AS `language`,
2861         `register`.`note` AS `note`,
2862         `contact`.`self` AS `self`,
2863         `contact`.`name` AS `name`,
2864         `contact`.`url` AS `url`,
2865         `contact`.`micro` AS `micro`,
2866         `user`.`email` AS `email`,
2867         `contact`.`nick` AS `nick`
2868         FROM `register`
2869                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2870                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2871
2872 --
2873 -- VIEW tag-search-view
2874 --
2875 DROP VIEW IF EXISTS `tag-search-view`;
2876 CREATE VIEW `tag-search-view` AS SELECT 
2877         `post-tag`.`uri-id` AS `uri-id`,
2878         `post-user`.`uid` AS `uid`,
2879         `post-user`.`id` AS `iid`,
2880         `post-user`.`private` AS `private`,
2881         `post-user`.`wall` AS `wall`,
2882         `post-user`.`origin` AS `origin`,
2883         `post-user`.`global` AS `global`,
2884         `post-user`.`gravity` AS `gravity`,
2885         `post-user`.`received` AS `received`,
2886         `post-user`.`network` AS `network`,
2887         `post-user`.`author-id` AS `author-id`,
2888         `tag`.`name` AS `name`
2889         FROM `post-tag`
2890                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2891                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2892                         WHERE `post-tag`.`type` = 1;
2893
2894 --
2895 -- VIEW workerqueue-view
2896 --
2897 DROP VIEW IF EXISTS `workerqueue-view`;
2898 CREATE VIEW `workerqueue-view` AS SELECT 
2899         `process`.`pid` AS `pid`,
2900         `workerqueue`.`priority` AS `priority`
2901         FROM `process`
2902                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2903                         WHERE NOT `workerqueue`.`done`;
2904
2905 --
2906 -- VIEW profile_field-view
2907 --
2908 DROP VIEW IF EXISTS `profile_field-view`;
2909 CREATE VIEW `profile_field-view` AS SELECT 
2910         `profile_field`.`id` AS `id`,
2911         `profile_field`.`uid` AS `uid`,
2912         `profile_field`.`label` AS `label`,
2913         `profile_field`.`value` AS `value`,
2914         `profile_field`.`order` AS `order`,
2915         `profile_field`.`psid` AS `psid`,
2916         `permissionset`.`allow_cid` AS `allow_cid`,
2917         `permissionset`.`allow_gid` AS `allow_gid`,
2918         `permissionset`.`deny_cid` AS `deny_cid`,
2919         `permissionset`.`deny_gid` AS `deny_gid`,
2920         `profile_field`.`created` AS `created`,
2921         `profile_field`.`edited` AS `edited`
2922         FROM `profile_field`
2923                         INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`;