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