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