]> git.mxchange.org Git - friendica.git/blob - database.sql
Merge pull request #10277 from very-ape/authenticate-hook
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2021.06-dev (Siberian Iris)
3 -- DB_UPDATE_VERSION 1418
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         `directory-type` tinyint DEFAULT 0 COMMENT 'Type of directory service (Poco, Mastodon)',
20         `poco` varchar(255) NOT NULL DEFAULT '' COMMENT '',
21         `noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
22         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
23         `protocol` tinyint unsigned COMMENT 'The protocol of the server',
24         `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
25         `relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
26         `relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
27         `detection-method` tinyint unsigned COMMENT 'Method that had been used to detect that server',
28         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
29         `last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
30         `last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last successful connection request',
31         `last_failure` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last failed connection request',
32         `failed` boolean COMMENT 'Connection failed',
33         `next_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Next connection request',
34          PRIMARY KEY(`id`),
35          UNIQUE INDEX `nurl` (`nurl`(190)),
36          INDEX `next_contact` (`next_contact`),
37          INDEX `network` (`network`)
38 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers';
39
40 --
41 -- TABLE user
42 --
43 CREATE TABLE IF NOT EXISTS `user` (
44         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
45         `parent-uid` mediumint unsigned COMMENT 'The parent user that has full control about this user',
46         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
47         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
48         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
49         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
50         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
51         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
52         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
53         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
54         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
55         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
56         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
57         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
58         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
59         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
60         `pubkey` text COMMENT 'RSA public key 4096 bit',
61         `prvkey` text COMMENT 'RSA private key 4096 bit',
62         `spubkey` text COMMENT '',
63         `sprvkey` text COMMENT '',
64         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
65         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
66         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
67         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
68         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
69         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
70         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
71         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
72         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
73         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
74         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
75         `pwdreset` varchar(255) COMMENT 'Password reset request token',
76         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
77         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
78         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
79         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
80         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
81         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
82         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
83         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
84         `allow_cid` mediumtext COMMENT 'default permission for this user',
85         `allow_gid` mediumtext COMMENT 'default permission for this user',
86         `deny_cid` mediumtext COMMENT 'default permission for this user',
87         `deny_gid` mediumtext COMMENT 'default permission for this user',
88         `openidserver` text COMMENT '',
89          PRIMARY KEY(`uid`),
90          INDEX `nickname` (`nickname`(32)),
91          INDEX `parent-uid` (`parent-uid`),
92          INDEX `guid` (`guid`),
93          INDEX `email` (`email`(64)),
94         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
95 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
96
97 --
98 -- TABLE contact
99 --
100 CREATE TABLE IF NOT EXISTS `contact` (
101         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
102         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
103         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
104         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
105         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
106         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
107         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
108         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
109         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
110         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
111         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
112         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
113         `location` varchar(255) DEFAULT '' COMMENT '',
114         `about` text COMMENT '',
115         `keywords` text COMMENT 'public keywords (interests) of the contact',
116         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
117         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
118         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
119         `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '',
120         `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
121         `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
122         `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
123         `site-pubkey` text COMMENT '',
124         `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
125         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
126         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
127         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
128         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
129         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
130         `pubkey` text COMMENT 'RSA public key 4096 bit',
131         `prvkey` text COMMENT 'RSA private key 4096 bit',
132         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
133         `request` varchar(255) COMMENT '',
134         `notify` varchar(255) COMMENT '',
135         `poll` varchar(255) COMMENT '',
136         `confirm` varchar(255) COMMENT '',
137         `subscribe` varchar(255) COMMENT '',
138         `poco` varchar(255) COMMENT '',
139         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT '',
140         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT '',
141         `usehub` boolean NOT NULL DEFAULT '0' COMMENT '',
142         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
143         `hub-verify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
144         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
145         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
146         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
147         `failed` boolean COMMENT 'Connection failed',
148         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
149         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
150         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
151         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
152         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
153         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
154         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
155         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
156         `block_reason` text COMMENT 'Node-wide block reason',
157         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
158         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
159         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum',
160         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group',
161         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT '',
162         `manually-approve` boolean COMMENT '',
163         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
164         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
165         `pending` boolean NOT NULL DEFAULT '1' COMMENT '',
166         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
167         `rating` tinyint NOT NULL DEFAULT 0 COMMENT '',
168         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
169         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
170         `baseurl` varchar(255) DEFAULT '' COMMENT 'baseurl of the contact',
171         `gsid` int unsigned COMMENT 'Global Server ID',
172         `reason` text COMMENT '',
173         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT '',
174         `info` mediumtext COMMENT '',
175         `profile-id` int unsigned COMMENT 'Deprecated',
176         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
177         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
178         `notify_new_posts` boolean NOT NULL DEFAULT '0' COMMENT '',
179         `fetch_further_information` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
180         `ffi_keyword_denylist` text COMMENT '',
181          PRIMARY KEY(`id`),
182          INDEX `uid_name` (`uid`,`name`(190)),
183          INDEX `self_uid` (`self`,`uid`),
184          INDEX `alias_uid` (`alias`(128),`uid`),
185          INDEX `pending_uid` (`pending`,`uid`),
186          INDEX `blocked_uid` (`blocked`,`uid`),
187          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
188          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
189          INDEX `batch_contact-type` (`batch`(64),`contact-type`),
190          INDEX `addr_uid` (`addr`(128),`uid`),
191          INDEX `nurl_uid` (`nurl`(128),`uid`),
192          INDEX `nick_uid` (`nick`(128),`uid`),
193          INDEX `attag_uid` (`attag`(96),`uid`),
194          INDEX `dfrn-id` (`dfrn-id`(64)),
195          INDEX `issued-id` (`issued-id`(64)),
196          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
197          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
198          INDEX `uid_lastitem` (`uid`,`last-item`),
199          INDEX `baseurl` (`baseurl`(64)),
200          INDEX `uid_contact-type` (`uid`,`contact-type`),
201          INDEX `uid_self_contact-type` (`uid`,`self`,`contact-type`),
202          INDEX `self_network_uid` (`self`,`network`,`uid`),
203          INDEX `gsid` (`gsid`),
204         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
205         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
206 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
207
208 --
209 -- TABLE item-uri
210 --
211 CREATE TABLE IF NOT EXISTS `item-uri` (
212         `id` int unsigned NOT NULL auto_increment,
213         `uri` varbinary(255) NOT NULL COMMENT 'URI of an item',
214         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
215          PRIMARY KEY(`id`),
216          UNIQUE INDEX `uri` (`uri`),
217          INDEX `guid` (`guid`)
218 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
219
220 --
221 -- TABLE tag
222 --
223 CREATE TABLE IF NOT EXISTS `tag` (
224         `id` int unsigned NOT NULL auto_increment COMMENT '',
225         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
226         `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
227          PRIMARY KEY(`id`),
228          UNIQUE INDEX `type_name_url` (`name`,`url`),
229          INDEX `url` (`url`)
230 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
231
232 --
233 -- TABLE clients
234 --
235 CREATE TABLE IF NOT EXISTS `clients` (
236         `client_id` varchar(20) NOT NULL COMMENT '',
237         `pw` varchar(20) NOT NULL DEFAULT '' COMMENT '',
238         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
239         `name` text COMMENT '',
240         `icon` text COMMENT '',
241         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
242          PRIMARY KEY(`client_id`),
243          INDEX `uid` (`uid`),
244         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
245 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
246
247 --
248 -- TABLE permissionset
249 --
250 CREATE TABLE IF NOT EXISTS `permissionset` (
251         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
252         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
253         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
254         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
255         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
256         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
257          PRIMARY KEY(`id`),
258          INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`uid`,`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)),
259         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
260 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
261
262 --
263 -- TABLE verb
264 --
265 CREATE TABLE IF NOT EXISTS `verb` (
266         `id` smallint unsigned NOT NULL auto_increment,
267         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
268          PRIMARY KEY(`id`),
269          INDEX `name` (`name`)
270 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
271
272 --
273 -- TABLE 2fa_app_specific_password
274 --
275 CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
276         `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
277         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
278         `description` varchar(255) COMMENT 'Description of the usage of the password',
279         `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
280         `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
281         `last_used` datetime COMMENT 'Datetime the password was last used',
282          PRIMARY KEY(`id`),
283          INDEX `uid_description` (`uid`,`description`(190)),
284         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
285 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
286
287 --
288 -- TABLE 2fa_recovery_codes
289 --
290 CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` (
291         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
292         `code` varchar(50) NOT NULL COMMENT 'Recovery code string',
293         `generated` datetime NOT NULL COMMENT 'Datetime the code was generated',
294         `used` datetime COMMENT 'Datetime the code was used',
295          PRIMARY KEY(`uid`,`code`),
296         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
297 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes';
298
299 --
300 -- TABLE 2fa_trusted_browser
301 --
302 CREATE TABLE IF NOT EXISTS `2fa_trusted_browser` (
303         `cookie_hash` varchar(80) NOT NULL COMMENT 'Trusted cookie hash',
304         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
305         `user_agent` text COMMENT 'User agent string',
306         `created` datetime NOT NULL COMMENT 'Datetime the trusted browser was recorded',
307         `last_used` datetime COMMENT 'Datetime the trusted browser was last used',
308          PRIMARY KEY(`cookie_hash`),
309          INDEX `uid` (`uid`),
310         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
311 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication trusted browsers';
312
313 --
314 -- TABLE addon
315 --
316 CREATE TABLE IF NOT EXISTS `addon` (
317         `id` int unsigned NOT NULL auto_increment COMMENT '',
318         `name` varchar(50) NOT NULL DEFAULT '' COMMENT 'addon base (file)name',
319         `version` varchar(50) NOT NULL DEFAULT '' COMMENT 'currently unused',
320         `installed` boolean NOT NULL DEFAULT '0' COMMENT 'currently always 1',
321         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'currently unused',
322         `timestamp` int unsigned NOT NULL DEFAULT 0 COMMENT 'file timestamp to check for reloads',
323         `plugin_admin` boolean NOT NULL DEFAULT '0' COMMENT '1 = has admin config, 0 = has no admin config',
324          PRIMARY KEY(`id`),
325          INDEX `installed_name` (`installed`,`name`),
326          UNIQUE INDEX `name` (`name`)
327 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registered addons';
328
329 --
330 -- TABLE apcontact
331 --
332 CREATE TABLE IF NOT EXISTS `apcontact` (
333         `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
334         `uuid` varchar(255) COMMENT '',
335         `type` varchar(20) NOT NULL COMMENT '',
336         `following` varchar(255) COMMENT '',
337         `followers` varchar(255) COMMENT '',
338         `inbox` varchar(255) NOT NULL COMMENT '',
339         `outbox` varchar(255) COMMENT '',
340         `sharedinbox` varchar(255) COMMENT '',
341         `manually-approve` boolean COMMENT '',
342         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
343         `name` varchar(255) COMMENT '',
344         `about` text COMMENT '',
345         `photo` varchar(255) COMMENT '',
346         `addr` varchar(255) COMMENT '',
347         `alias` varchar(255) COMMENT '',
348         `pubkey` text COMMENT '',
349         `subscribe` varchar(255) COMMENT '',
350         `baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
351         `gsid` int unsigned COMMENT 'Global Server ID',
352         `generator` varchar(255) COMMENT 'Name of the contact\'s system',
353         `following_count` int unsigned DEFAULT 0 COMMENT 'Number of following contacts',
354         `followers_count` int unsigned DEFAULT 0 COMMENT 'Number of followers',
355         `statuses_count` int unsigned DEFAULT 0 COMMENT 'Number of posts',
356         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
357          PRIMARY KEY(`url`),
358          INDEX `addr` (`addr`(32)),
359          INDEX `alias` (`alias`(190)),
360          INDEX `followers` (`followers`(190)),
361          INDEX `baseurl` (`baseurl`(190)),
362          INDEX `sharedinbox` (`sharedinbox`(190)),
363          INDEX `gsid` (`gsid`),
364         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
365 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
366
367 --
368 -- TABLE application
369 --
370 CREATE TABLE IF NOT EXISTS `application` (
371         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
372         `client_id` varchar(64) NOT NULL COMMENT '',
373         `client_secret` varchar(64) NOT NULL COMMENT '',
374         `name` varchar(255) NOT NULL COMMENT '',
375         `redirect_uri` varchar(255) NOT NULL COMMENT '',
376         `website` varchar(255) COMMENT '',
377         `scopes` varchar(255) COMMENT '',
378         `read` boolean COMMENT 'Read scope',
379         `write` boolean COMMENT 'Write scope',
380         `follow` boolean COMMENT 'Follow scope',
381         `push` boolean COMMENT 'Push scope',
382          PRIMARY KEY(`id`),
383          UNIQUE INDEX `client_id` (`client_id`)
384 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth application';
385
386 --
387 -- TABLE application-token
388 --
389 CREATE TABLE IF NOT EXISTS `application-token` (
390         `application-id` int unsigned NOT NULL COMMENT '',
391         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
392         `code` varchar(64) NOT NULL COMMENT '',
393         `access_token` varchar(64) NOT NULL COMMENT '',
394         `created_at` datetime NOT NULL COMMENT 'creation time',
395         `scopes` varchar(255) COMMENT '',
396         `read` boolean COMMENT 'Read scope',
397         `write` boolean COMMENT 'Write scope',
398         `follow` boolean COMMENT 'Follow scope',
399         `push` boolean COMMENT 'Push scope',
400          PRIMARY KEY(`application-id`,`uid`),
401          INDEX `uid_id` (`uid`,`application-id`),
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='OAuth user token';
405
406 --
407 -- TABLE attach
408 --
409 CREATE TABLE IF NOT EXISTS `attach` (
410         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
411         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
412         `hash` varchar(64) NOT NULL DEFAULT '' COMMENT 'hash',
413         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'filename of original',
414         `filetype` varchar(64) NOT NULL DEFAULT '' COMMENT 'mimetype',
415         `filesize` int unsigned NOT NULL DEFAULT 0 COMMENT 'size in bytes',
416         `data` longblob NOT NULL COMMENT 'file data',
417         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
418         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
419         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>',
420         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
421         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
422         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
423         `backend-class` tinytext COMMENT 'Storage backend class',
424         `backend-ref` text COMMENT 'Storage backend data reference',
425          PRIMARY KEY(`id`),
426          INDEX `uid` (`uid`),
427         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
428 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='file attachments';
429
430 --
431 -- TABLE auth_codes
432 --
433 CREATE TABLE IF NOT EXISTS `auth_codes` (
434         `id` varchar(40) NOT NULL COMMENT '',
435         `client_id` varchar(20) NOT NULL DEFAULT '' COMMENT '',
436         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
437         `expires` int NOT NULL DEFAULT 0 COMMENT '',
438         `scope` varchar(250) NOT NULL DEFAULT '' COMMENT '',
439          PRIMARY KEY(`id`),
440          INDEX `client_id` (`client_id`),
441         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE
442 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
443
444 --
445 -- TABLE cache
446 --
447 CREATE TABLE IF NOT EXISTS `cache` (
448         `k` varbinary(255) NOT NULL COMMENT 'cache key',
449         `v` mediumtext COMMENT 'cached serialized value',
450         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
451         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
452          PRIMARY KEY(`k`),
453          INDEX `k_expires` (`k`,`expires`)
454 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
455
456 --
457 -- TABLE challenge
458 --
459 CREATE TABLE IF NOT EXISTS `challenge` (
460         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
461         `challenge` varchar(255) NOT NULL DEFAULT '' COMMENT '',
462         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
463         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
464         `type` varchar(255) NOT NULL DEFAULT '' COMMENT '',
465         `last_update` varchar(255) NOT NULL DEFAULT '' COMMENT '',
466          PRIMARY KEY(`id`),
467          INDEX `expire` (`expire`)
468 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
469
470 --
471 -- TABLE config
472 --
473 CREATE TABLE IF NOT EXISTS `config` (
474         `id` int unsigned NOT NULL auto_increment COMMENT '',
475         `cat` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
476         `k` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
477         `v` mediumtext COMMENT '',
478          PRIMARY KEY(`id`),
479          UNIQUE INDEX `cat_k` (`cat`,`k`)
480 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='main configuration storage';
481
482 --
483 -- TABLE contact-relation
484 --
485 CREATE TABLE IF NOT EXISTS `contact-relation` (
486         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact the related contact had interacted with',
487         `relation-cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'related contact who had interacted with the contact',
488         `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction',
489         `follow-updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last update of the contact relationship',
490         `follows` boolean NOT NULL DEFAULT '0' COMMENT '',
491          PRIMARY KEY(`cid`,`relation-cid`),
492          INDEX `relation-cid` (`relation-cid`),
493         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
494         FOREIGN KEY (`relation-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
495 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Contact relations';
496
497 --
498 -- TABLE conv
499 --
500 CREATE TABLE IF NOT EXISTS `conv` (
501         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
502         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this conversation',
503         `recips` text COMMENT 'sender_handle;recipient_handle',
504         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
505         `creator` varchar(255) NOT NULL DEFAULT '' COMMENT 'handle of creator',
506         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation timestamp',
507         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'edited timestamp',
508         `subject` text COMMENT 'subject of initial message',
509          PRIMARY KEY(`id`),
510          INDEX `uid` (`uid`),
511         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
512 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
513
514 --
515 -- TABLE conversation
516 --
517 CREATE TABLE IF NOT EXISTS `conversation` (
518         `item-uri` varbinary(255) NOT NULL COMMENT 'Original URI of the item - unrelated to the table with the same name',
519         `reply-to-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'URI to which this item is a reply',
520         `conversation-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation URI',
521         `conversation-href` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation link',
522         `protocol` tinyint unsigned NOT NULL DEFAULT 255 COMMENT 'The protocol of the item',
523         `direction` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'How the message arrived here: 1=push, 2=pull',
524         `source` mediumtext COMMENT 'Original source',
525         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Receiving date',
526          PRIMARY KEY(`item-uri`),
527          INDEX `conversation-uri` (`conversation-uri`),
528          INDEX `received` (`received`)
529 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Raw data and structure information for messages';
530
531 --
532 -- TABLE delayed-post
533 --
534 CREATE TABLE IF NOT EXISTS `delayed-post` (
535         `id` int unsigned NOT NULL auto_increment,
536         `uri` varchar(255) COMMENT 'URI of the post that will be distributed later',
537         `uid` mediumint unsigned COMMENT 'Owner User id',
538         `delayed` datetime COMMENT 'delay time',
539          PRIMARY KEY(`id`),
540          UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
541         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
542 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be distributed at a later time';
543
544 --
545 -- TABLE diaspora-interaction
546 --
547 CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
548         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
549         `interaction` mediumtext COMMENT 'The Diaspora interaction',
550          PRIMARY KEY(`uri-id`),
551         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
552 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
553
554 --
555 -- TABLE event
556 --
557 CREATE TABLE IF NOT EXISTS `event` (
558         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
559         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
560         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
561         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact_id (ID of the contact in contact table)',
562         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
563         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
564         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
565         `start` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event start time',
566         `finish` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event end time',
567         `summary` text COMMENT 'short description or title of the event',
568         `desc` text COMMENT 'event description',
569         `location` text COMMENT 'event location',
570         `type` varchar(20) NOT NULL DEFAULT '' COMMENT 'event or birthday',
571         `nofinish` boolean NOT NULL DEFAULT '0' COMMENT 'if event does have no end this is 1',
572         `adjust` boolean NOT NULL DEFAULT '1' COMMENT 'adjust to timezone of the recipient (0 or 1)',
573         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '0 or 1',
574         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
575         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
576         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
577         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
578          PRIMARY KEY(`id`),
579          INDEX `uid_start` (`uid`,`start`),
580          INDEX `cid` (`cid`),
581         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
582         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
583 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events';
584
585 --
586 -- TABLE fcontact
587 --
588 CREATE TABLE IF NOT EXISTS `fcontact` (
589         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
590         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id',
591         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
592         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
593         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
594         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
595         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
596         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
597         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
598         `notify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
599         `poll` varchar(255) NOT NULL DEFAULT '' COMMENT '',
600         `confirm` varchar(255) NOT NULL DEFAULT '' COMMENT '',
601         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
602         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
603         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
604         `pubkey` text COMMENT '',
605         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
606          PRIMARY KEY(`id`),
607          INDEX `addr` (`addr`(32)),
608          UNIQUE INDEX `url` (`url`(190))
609 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
610
611 --
612 -- TABLE fsuggest
613 --
614 CREATE TABLE IF NOT EXISTS `fsuggest` (
615         `id` int unsigned NOT NULL auto_increment COMMENT '',
616         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
617         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
618         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
619         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
620         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
621         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
622         `note` text COMMENT '',
623         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
624          PRIMARY KEY(`id`),
625          INDEX `cid` (`cid`),
626          INDEX `uid` (`uid`),
627         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
628         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
629 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff';
630
631 --
632 -- TABLE group
633 --
634 CREATE TABLE IF NOT EXISTS `group` (
635         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
636         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
637         `visible` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the member list is not private',
638         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the group has been deleted',
639         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'human readable name of group',
640          PRIMARY KEY(`id`),
641          INDEX `uid` (`uid`),
642         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
643 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, group info';
644
645 --
646 -- TABLE group_member
647 --
648 CREATE TABLE IF NOT EXISTS `group_member` (
649         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
650         `gid` int unsigned NOT NULL DEFAULT 0 COMMENT 'groups.id of the associated group',
651         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id of the member assigned to the associated group',
652          PRIMARY KEY(`id`),
653          INDEX `contactid` (`contact-id`),
654          UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`),
655         FOREIGN KEY (`gid`) REFERENCES `group` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
656         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
657 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, member info';
658
659 --
660 -- TABLE gserver-tag
661 --
662 CREATE TABLE IF NOT EXISTS `gserver-tag` (
663         `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
664         `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
665          PRIMARY KEY(`gserver-id`,`tag`),
666          INDEX `tag` (`tag`),
667         FOREIGN KEY (`gserver-id`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
668 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Tags that the server has subscribed';
669
670 --
671 -- TABLE hook
672 --
673 CREATE TABLE IF NOT EXISTS `hook` (
674         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
675         `hook` varbinary(100) NOT NULL DEFAULT '' COMMENT 'name of hook',
676         `file` varbinary(200) NOT NULL DEFAULT '' COMMENT 'relative filename of hook handler',
677         `function` varbinary(200) NOT NULL DEFAULT '' COMMENT 'function name of hook handler',
678         `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',
679          PRIMARY KEY(`id`),
680          INDEX `priority` (`priority`),
681          UNIQUE INDEX `hook_file_function` (`hook`,`file`,`function`)
682 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='addon hook registry';
683
684 --
685 -- TABLE host
686 --
687 CREATE TABLE IF NOT EXISTS `host` (
688         `id` tinyint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
689         `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'The hostname',
690          PRIMARY KEY(`id`),
691          UNIQUE INDEX `name` (`name`)
692 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Hostname';
693
694 --
695 -- TABLE inbox-status
696 --
697 CREATE TABLE IF NOT EXISTS `inbox-status` (
698         `url` varbinary(255) NOT NULL COMMENT 'URL of the inbox',
699         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date of this entry',
700         `success` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful delivery',
701         `failure` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed delivery',
702         `previous` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Previous delivery date',
703         `archive` boolean NOT NULL DEFAULT '0' COMMENT 'Is the inbox archived?',
704         `shared` boolean NOT NULL DEFAULT '0' COMMENT 'Is it a shared inbox?',
705          PRIMARY KEY(`url`)
706 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Status of ActivityPub inboxes';
707
708 --
709 -- TABLE intro
710 --
711 CREATE TABLE IF NOT EXISTS `intro` (
712         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
713         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
714         `fid` int unsigned COMMENT '',
715         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
716         `knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
717         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
718         `note` text COMMENT '',
719         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
720         `datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
721         `blocked` boolean NOT NULL DEFAULT '1' COMMENT '',
722         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '',
723          PRIMARY KEY(`id`),
724          INDEX `contact-id` (`contact-id`),
725          INDEX `uid` (`uid`),
726         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
727         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
728 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
729
730 --
731 -- TABLE locks
732 --
733 CREATE TABLE IF NOT EXISTS `locks` (
734         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
735         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
736         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
737         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
738         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
739          PRIMARY KEY(`id`),
740          INDEX `name_expires` (`name`,`expires`)
741 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
742
743 --
744 -- TABLE mail
745 --
746 CREATE TABLE IF NOT EXISTS `mail` (
747         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
748         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
749         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
750         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
751         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
752         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
753         `contact-id` varchar(255) COMMENT 'contact.id',
754         `convid` int unsigned COMMENT 'conv.id',
755         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
756         `body` mediumtext COMMENT '',
757         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
758         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
759         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
760         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
761         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
762         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
763         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
764          PRIMARY KEY(`id`),
765          INDEX `uid_seen` (`uid`,`seen`),
766          INDEX `convid` (`convid`),
767          INDEX `uri` (`uri`(64)),
768          INDEX `parent-uri` (`parent-uri`(64)),
769          INDEX `contactid` (`contact-id`(32)),
770         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
771 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
772
773 --
774 -- TABLE mailacct
775 --
776 CREATE TABLE IF NOT EXISTS `mailacct` (
777         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
778         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
779         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
780         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
781         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
782         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
783         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
784         `pass` text COMMENT '',
785         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
786         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
787         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
788         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
789         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
790          PRIMARY KEY(`id`),
791          INDEX `uid` (`uid`),
792         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
793 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
794
795 --
796 -- TABLE manage
797 --
798 CREATE TABLE IF NOT EXISTS `manage` (
799         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
800         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
801         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
802          PRIMARY KEY(`id`),
803          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
804          INDEX `mid` (`mid`),
805         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
806         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
807 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
808
809 --
810 -- TABLE notify
811 --
812 CREATE TABLE IF NOT EXISTS `notify` (
813         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
814         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
815         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
816         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
817         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
818         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
819         `msg` mediumtext COMMENT '',
820         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
821         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
822         `iid` int unsigned COMMENT '',
823         `parent` int unsigned COMMENT '',
824         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
825         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
826         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
827         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
828         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
829         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
830         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
831          PRIMARY KEY(`id`),
832          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
833          INDEX `uid_date` (`uid`,`date`),
834          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
835          INDEX `uri-id` (`uri-id`),
836          INDEX `parent-uri-id` (`parent-uri-id`),
837         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
838         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
839         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
840 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
841
842 --
843 -- TABLE notify-threads
844 --
845 CREATE TABLE IF NOT EXISTS `notify-threads` (
846         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
847         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
848         `master-parent-item` int unsigned COMMENT 'Deprecated',
849         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
850         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
851         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
852          PRIMARY KEY(`id`),
853          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
854          INDEX `receiver-uid` (`receiver-uid`),
855          INDEX `notify-id` (`notify-id`),
856         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
857         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
858         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
859 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
860
861 --
862 -- TABLE oembed
863 --
864 CREATE TABLE IF NOT EXISTS `oembed` (
865         `url` varbinary(255) NOT NULL COMMENT 'page url',
866         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
867         `content` mediumtext COMMENT 'OEmbed data of the page',
868         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
869          PRIMARY KEY(`url`,`maxwidth`),
870          INDEX `created` (`created`)
871 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
872
873 --
874 -- TABLE openwebauth-token
875 --
876 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
877         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
878         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
879         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
880         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
881         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
882         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
883          PRIMARY KEY(`id`),
884          INDEX `uid` (`uid`),
885         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
886 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
887
888 --
889 -- TABLE parsed_url
890 --
891 CREATE TABLE IF NOT EXISTS `parsed_url` (
892         `url_hash` binary(64) NOT NULL COMMENT 'page url hash',
893         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
894         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
895         `url` text NOT NULL COMMENT 'page url',
896         `content` mediumtext COMMENT 'page data',
897         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
898         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of expiration',
899          PRIMARY KEY(`url_hash`,`guessing`,`oembed`),
900          INDEX `created` (`created`),
901          INDEX `expires` (`expires`)
902 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
903
904 --
905 -- TABLE pconfig
906 --
907 CREATE TABLE IF NOT EXISTS `pconfig` (
908         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
909         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
910         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
911         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
912         `v` mediumtext COMMENT 'Value',
913          PRIMARY KEY(`id`),
914          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
915         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
916 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
917
918 --
919 -- TABLE photo
920 --
921 CREATE TABLE IF NOT EXISTS `photo` (
922         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
923         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
924         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
925         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
926         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
927         `hash` char(32) COMMENT 'hash value of the photo',
928         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
929         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
930         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
931         `desc` text COMMENT '',
932         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
933         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
934         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
935         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
936         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
937         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
938         `data` mediumblob NOT NULL COMMENT '',
939         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
940         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
941         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
942         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
943         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
944         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
945         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
946         `backend-class` tinytext COMMENT 'Storage backend class',
947         `backend-ref` text COMMENT 'Storage backend data reference',
948         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
949          PRIMARY KEY(`id`),
950          INDEX `contactid` (`contact-id`),
951          INDEX `uid_contactid` (`uid`,`contact-id`),
952          INDEX `uid_profile` (`uid`,`profile`),
953          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
954          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
955          INDEX `resource-id` (`resource-id`),
956         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
957         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
958 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
959
960 --
961 -- TABLE post
962 --
963 CREATE TABLE IF NOT EXISTS `post` (
964         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
965         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
966         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
967         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
968         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
969         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
970         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
971         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
972         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
973         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
974         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
975         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
976         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
977         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
978         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
979         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
980         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
981         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
982          PRIMARY KEY(`uri-id`),
983          INDEX `parent-uri-id` (`parent-uri-id`),
984          INDEX `thr-parent-id` (`thr-parent-id`),
985          INDEX `external-id` (`external-id`),
986          INDEX `owner-id` (`owner-id`),
987          INDEX `author-id` (`author-id`),
988          INDEX `causer-id` (`causer-id`),
989          INDEX `vid` (`vid`),
990         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
991         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
992         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
993         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
994         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
995         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
996         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
997         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
998 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
999
1000 --
1001 -- TABLE post-category
1002 --
1003 CREATE TABLE IF NOT EXISTS `post-category` (
1004         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1005         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1006         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1007         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1008          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1009          INDEX `uri-id` (`tid`),
1010          INDEX `uid` (`uid`),
1011         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1012         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1013         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1014 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1015
1016 --
1017 -- TABLE post-content
1018 --
1019 CREATE TABLE IF NOT EXISTS `post-content` (
1020         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1021         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1022         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1023         `body` mediumtext COMMENT 'item body content',
1024         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1025         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1026         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1027         `language` text COMMENT 'Language information about this post',
1028         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1029         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1030         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1031         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1032         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1033         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1034         `target` text COMMENT 'JSON encoded target structure if used',
1035         `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',
1036         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1037          PRIMARY KEY(`uri-id`),
1038          INDEX `plink` (`plink`(191)),
1039          INDEX `resource-id` (`resource-id`),
1040          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1041         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1042 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1043
1044 --
1045 -- TABLE post-delivery-data
1046 --
1047 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1048         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1049         `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',
1050         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1051         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1052         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1053         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1054         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1055         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1056         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1057         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1058         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1059          PRIMARY KEY(`uri-id`),
1060         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1061 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1062
1063 --
1064 -- TABLE post-media
1065 --
1066 CREATE TABLE IF NOT EXISTS `post-media` (
1067         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1068         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1069         `url` varbinary(511) NOT NULL COMMENT 'Media URL',
1070         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1071         `mimetype` varchar(60) COMMENT '',
1072         `height` smallint unsigned COMMENT 'Height of the media',
1073         `width` smallint unsigned COMMENT 'Width of the media',
1074         `size` int unsigned COMMENT 'Media size',
1075         `preview` varbinary(255) COMMENT 'Preview URL',
1076         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1077         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1078         `description` text COMMENT '',
1079         `name` varchar(255) COMMENT 'Name of the media',
1080         `author-url` varbinary(255) COMMENT 'URL of the author of the media',
1081         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1082         `author-image` varbinary(255) COMMENT 'Image of the author of the media',
1083         `publisher-url` varbinary(255) COMMENT 'URL of the publisher of the media',
1084         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1085         `publisher-image` varbinary(255) COMMENT 'Image of the publisher of the media',
1086          PRIMARY KEY(`id`),
1087          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1088         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1089 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1090
1091 --
1092 -- TABLE post-tag
1093 --
1094 CREATE TABLE IF NOT EXISTS `post-tag` (
1095         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1096         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1097         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1098         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1099          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1100          INDEX `tid` (`tid`),
1101          INDEX `cid` (`cid`),
1102         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1103         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1104         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1105 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1106
1107 --
1108 -- TABLE post-thread
1109 --
1110 CREATE TABLE IF NOT EXISTS `post-thread` (
1111         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1112         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1113         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1114         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1115         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1116         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1117         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1118         `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',
1119         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1120          PRIMARY KEY(`uri-id`),
1121          INDEX `owner-id` (`owner-id`),
1122          INDEX `author-id` (`author-id`),
1123          INDEX `causer-id` (`causer-id`),
1124          INDEX `received` (`received`),
1125          INDEX `commented` (`commented`),
1126         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1127         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1128         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1129         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1130 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1131
1132 --
1133 -- TABLE post-user
1134 --
1135 CREATE TABLE IF NOT EXISTS `post-user` (
1136         `id` int unsigned NOT NULL auto_increment,
1137         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1138         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1139         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1140         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1141         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1142         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1143         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1144         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1145         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1146         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1147         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1148         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1149         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1150         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1151         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1152         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1153         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1154         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1155         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1156         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1157         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1158         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1159         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1160         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1161         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1162         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1163         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1164         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1165         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1166          PRIMARY KEY(`id`),
1167          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1168          INDEX `uri-id` (`uri-id`),
1169          INDEX `parent-uri-id` (`parent-uri-id`),
1170          INDEX `thr-parent-id` (`thr-parent-id`),
1171          INDEX `external-id` (`external-id`),
1172          INDEX `owner-id` (`owner-id`),
1173          INDEX `author-id` (`author-id`),
1174          INDEX `causer-id` (`causer-id`),
1175          INDEX `vid` (`vid`),
1176          INDEX `contact-id` (`contact-id`),
1177          INDEX `event-id` (`event-id`),
1178          INDEX `psid` (`psid`),
1179          INDEX `author-id_uid` (`author-id`,`uid`),
1180          INDEX `author-id_received` (`author-id`,`received`),
1181          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1182          INDEX `uid_contactid` (`uid`,`contact-id`),
1183          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1184          INDEX `uid_unseen` (`uid`,`unseen`),
1185          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1186         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1187         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1188         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1189         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1190         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1191         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1192         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1193         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1194         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1195         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1196         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1197         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1198 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1199
1200 --
1201 -- TABLE post-thread-user
1202 --
1203 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1204         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1205         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1206         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1207         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1208         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1209         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1210         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1211         `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',
1212         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1213         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1214         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'The thread is pinned on the profile page',
1215         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1216         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1217         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1218         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1219         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1220         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1221         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1222         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1223         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1224         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1225         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1226         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1227          PRIMARY KEY(`uid`,`uri-id`),
1228          INDEX `uri-id` (`uri-id`),
1229          INDEX `owner-id` (`owner-id`),
1230          INDEX `author-id` (`author-id`),
1231          INDEX `causer-id` (`causer-id`),
1232          INDEX `uid` (`uid`),
1233          INDEX `contact-id` (`contact-id`),
1234          INDEX `psid` (`psid`),
1235          INDEX `post-user-id` (`post-user-id`),
1236          INDEX `commented` (`commented`),
1237          INDEX `uid_received` (`uid`,`received`),
1238          INDEX `uid_pinned` (`uid`,`pinned`),
1239          INDEX `uid_commented` (`uid`,`commented`),
1240          INDEX `uid_starred` (`uid`,`starred`),
1241          INDEX `uid_mention` (`uid`,`mention`),
1242         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1243         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1244         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1245         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1246         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1247         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1248         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1249         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1250 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1251
1252 --
1253 -- TABLE post-user-notification
1254 --
1255 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1256         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1257         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1258         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1259          PRIMARY KEY(`uid`,`uri-id`),
1260          INDEX `uri-id` (`uri-id`),
1261         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1262         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1263 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1264
1265 --
1266 -- TABLE process
1267 --
1268 CREATE TABLE IF NOT EXISTS `process` (
1269         `pid` int unsigned NOT NULL COMMENT '',
1270         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1271         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1272          PRIMARY KEY(`pid`),
1273          INDEX `command` (`command`)
1274 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1275
1276 --
1277 -- TABLE profile
1278 --
1279 CREATE TABLE IF NOT EXISTS `profile` (
1280         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1281         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1282         `profile-name` varchar(255) COMMENT 'Deprecated',
1283         `is-default` boolean COMMENT 'Deprecated',
1284         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1285         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1286         `pdesc` varchar(255) COMMENT 'Deprecated',
1287         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1288         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1289         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1290         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1291         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1292         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1293         `hometown` varchar(255) COMMENT 'Deprecated',
1294         `gender` varchar(32) COMMENT 'Deprecated',
1295         `marital` varchar(255) COMMENT 'Deprecated',
1296         `with` text COMMENT 'Deprecated',
1297         `howlong` datetime COMMENT 'Deprecated',
1298         `sexual` varchar(255) COMMENT 'Deprecated',
1299         `politic` varchar(255) COMMENT 'Deprecated',
1300         `religion` varchar(255) COMMENT 'Deprecated',
1301         `pub_keywords` text COMMENT '',
1302         `prv_keywords` text COMMENT '',
1303         `likes` text COMMENT 'Deprecated',
1304         `dislikes` text COMMENT 'Deprecated',
1305         `about` text COMMENT 'Profile description',
1306         `summary` varchar(255) COMMENT 'Deprecated',
1307         `music` text COMMENT 'Deprecated',
1308         `book` text COMMENT 'Deprecated',
1309         `tv` text COMMENT 'Deprecated',
1310         `film` text COMMENT 'Deprecated',
1311         `interest` text COMMENT 'Deprecated',
1312         `romance` text COMMENT 'Deprecated',
1313         `work` text COMMENT 'Deprecated',
1314         `education` text COMMENT 'Deprecated',
1315         `contact` text COMMENT 'Deprecated',
1316         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1317         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1318         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1319         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1320         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1321         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1322          PRIMARY KEY(`id`),
1323          INDEX `uid_is-default` (`uid`,`is-default`),
1324          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1325         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1326 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1327
1328 --
1329 -- TABLE profile_check
1330 --
1331 CREATE TABLE IF NOT EXISTS `profile_check` (
1332         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1333         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1334         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1335         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1336         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1337         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1338          PRIMARY KEY(`id`),
1339          INDEX `uid` (`uid`),
1340          INDEX `cid` (`cid`),
1341         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1342         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1343 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1344
1345 --
1346 -- TABLE profile_field
1347 --
1348 CREATE TABLE IF NOT EXISTS `profile_field` (
1349         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1350         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1351         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1352         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1353         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1354         `value` text COMMENT 'Value of the field',
1355         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1356         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1357          PRIMARY KEY(`id`),
1358          INDEX `uid` (`uid`),
1359          INDEX `order` (`order`),
1360          INDEX `psid` (`psid`),
1361         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1362         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1363 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1364
1365 --
1366 -- TABLE push_subscriber
1367 --
1368 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1369         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1370         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1371         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1372         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1373         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1374         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1375         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1376         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1377         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1378         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1379          PRIMARY KEY(`id`),
1380          INDEX `next_try` (`next_try`),
1381          INDEX `uid` (`uid`),
1382         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1383 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1384
1385 --
1386 -- TABLE register
1387 --
1388 CREATE TABLE IF NOT EXISTS `register` (
1389         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1390         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1391         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1392         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1393         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1394         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1395         `note` text COMMENT '',
1396          PRIMARY KEY(`id`),
1397          INDEX `uid` (`uid`),
1398         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1399 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1400
1401 --
1402 -- TABLE search
1403 --
1404 CREATE TABLE IF NOT EXISTS `search` (
1405         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1406         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1407         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1408          PRIMARY KEY(`id`),
1409          INDEX `uid_term` (`uid`,`term`(64)),
1410          INDEX `term` (`term`(64)),
1411         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1412 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1413
1414 --
1415 -- TABLE session
1416 --
1417 CREATE TABLE IF NOT EXISTS `session` (
1418         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1419         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1420         `data` text COMMENT '',
1421         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1422          PRIMARY KEY(`id`),
1423          INDEX `sid` (`sid`(64)),
1424          INDEX `expire` (`expire`)
1425 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1426
1427 --
1428 -- TABLE storage
1429 --
1430 CREATE TABLE IF NOT EXISTS `storage` (
1431         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1432         `data` longblob NOT NULL COMMENT 'file data',
1433          PRIMARY KEY(`id`)
1434 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1435
1436 --
1437 -- TABLE tokens
1438 --
1439 CREATE TABLE IF NOT EXISTS `tokens` (
1440         `id` varchar(40) NOT NULL COMMENT '',
1441         `secret` text COMMENT '',
1442         `client_id` varchar(20) NOT NULL DEFAULT '',
1443         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1444         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1445         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1446          PRIMARY KEY(`id`),
1447          INDEX `client_id` (`client_id`),
1448          INDEX `uid` (`uid`),
1449         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1450         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1451 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1452
1453 --
1454 -- TABLE userd
1455 --
1456 CREATE TABLE IF NOT EXISTS `userd` (
1457         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1458         `username` varchar(255) NOT NULL COMMENT '',
1459          PRIMARY KEY(`id`),
1460          INDEX `username` (`username`(32))
1461 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1462
1463 --
1464 -- TABLE user-contact
1465 --
1466 CREATE TABLE IF NOT EXISTS `user-contact` (
1467         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1468         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1469         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1470         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1471         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1472          PRIMARY KEY(`uid`,`cid`),
1473          INDEX `cid` (`cid`),
1474         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1475         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1476 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1477
1478 --
1479 -- TABLE worker-ipc
1480 --
1481 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1482         `key` int NOT NULL COMMENT '',
1483         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1484          PRIMARY KEY(`key`)
1485 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1486
1487 --
1488 -- TABLE workerqueue
1489 --
1490 CREATE TABLE IF NOT EXISTS `workerqueue` (
1491         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1492         `command` varchar(100) COMMENT 'Task command',
1493         `parameter` mediumtext COMMENT 'Task parameter',
1494         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1495         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1496         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1497         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1498         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1499         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1500         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1501          PRIMARY KEY(`id`),
1502          INDEX `command` (`command`),
1503          INDEX `done_command_parameter` (`done`,`command`,`parameter`(64)),
1504          INDEX `done_executed` (`done`,`executed`),
1505          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
1506          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1507          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1508          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1509          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1510 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1511
1512 --
1513 -- VIEW application-view
1514 --
1515 DROP VIEW IF EXISTS `application-view`;
1516 CREATE VIEW `application-view` AS SELECT 
1517         `application`.`id` AS `id`,
1518         `application-token`.`uid` AS `uid`,
1519         `application`.`name` AS `name`,
1520         `application`.`redirect_uri` AS `redirect_uri`,
1521         `application`.`website` AS `website`,
1522         `application`.`client_id` AS `client_id`,
1523         `application`.`client_secret` AS `client_secret`,
1524         `application-token`.`code` AS `code`,
1525         `application-token`.`access_token` AS `access_token`,
1526         `application-token`.`created_at` AS `created_at`,
1527         `application-token`.`scopes` AS `scopes`,
1528         `application-token`.`read` AS `read`,
1529         `application-token`.`write` AS `write`,
1530         `application-token`.`follow` AS `follow`,
1531         `application-token`.`push` AS `push`
1532         FROM `application-token`
1533                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1534
1535 --
1536 -- VIEW post-user-view
1537 --
1538 DROP VIEW IF EXISTS `post-user-view`;
1539 CREATE VIEW `post-user-view` AS SELECT 
1540         `post-user`.`id` AS `id`,
1541         `post-user`.`id` AS `post-user-id`,
1542         `post-user`.`uid` AS `uid`,
1543         `parent-post`.`id` AS `parent`,
1544         `item-uri`.`uri` AS `uri`,
1545         `post-user`.`uri-id` AS `uri-id`,
1546         `parent-item-uri`.`uri` AS `parent-uri`,
1547         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1548         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1549         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1550         `item-uri`.`guid` AS `guid`,
1551         `post-user`.`wall` AS `wall`,
1552         `post-user`.`gravity` AS `gravity`,
1553         `external-item-uri`.`uri` AS `extid`,
1554         `post-user`.`external-id` AS `external-id`,
1555         `post-user`.`created` AS `created`,
1556         `post-user`.`edited` AS `edited`,
1557         `post-thread-user`.`commented` AS `commented`,
1558         `post-user`.`received` AS `received`,
1559         `post-thread-user`.`changed` AS `changed`,
1560         `post-user`.`post-type` AS `post-type`,
1561         `post-user`.`post-reason` AS `post-reason`,
1562         `post-user`.`private` AS `private`,
1563         `post-thread-user`.`pubmail` AS `pubmail`,
1564         `post-user`.`visible` AS `visible`,
1565         `post-thread-user`.`starred` AS `starred`,
1566         `post-thread-user`.`pinned` AS `pinned`,
1567         `post-user`.`unseen` AS `unseen`,
1568         `post-user`.`deleted` AS `deleted`,
1569         `post-user`.`origin` AS `origin`,
1570         `post-thread-user`.`origin` AS `parent-origin`,
1571         `post-thread-user`.`forum_mode` AS `forum_mode`,
1572         `post-thread-user`.`mention` AS `mention`,
1573         `post-user`.`global` AS `global`,
1574         `post-user`.`network` AS `network`,
1575         `post-user`.`vid` AS `vid`,
1576         `post-user`.`psid` AS `psid`,
1577         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1578         `post-content`.`title` AS `title`,
1579         `post-content`.`content-warning` AS `content-warning`,
1580         `post-content`.`raw-body` AS `raw-body`,
1581         `post-content`.`body` AS `body`,
1582         `post-content`.`rendered-hash` AS `rendered-hash`,
1583         `post-content`.`rendered-html` AS `rendered-html`,
1584         `post-content`.`language` AS `language`,
1585         `post-content`.`plink` AS `plink`,
1586         `post-content`.`location` AS `location`,
1587         `post-content`.`coord` AS `coord`,
1588         `post-content`.`app` AS `app`,
1589         `post-content`.`object-type` AS `object-type`,
1590         `post-content`.`object` AS `object`,
1591         `post-content`.`target-type` AS `target-type`,
1592         `post-content`.`target` AS `target`,
1593         `post-content`.`resource-id` AS `resource-id`,
1594         `post-user`.`contact-id` AS `contact-id`,
1595         `contact`.`url` AS `contact-link`,
1596         `contact`.`addr` AS `contact-addr`,
1597         `contact`.`name` AS `contact-name`,
1598         `contact`.`nick` AS `contact-nick`,
1599         `contact`.`thumb` AS `contact-avatar`,
1600         `contact`.`network` AS `contact-network`,
1601         `contact`.`blocked` AS `contact-blocked`,
1602         `contact`.`hidden` AS `contact-hidden`,
1603         `contact`.`readonly` AS `contact-readonly`,
1604         `contact`.`archive` AS `contact-archive`,
1605         `contact`.`pending` AS `contact-pending`,
1606         `contact`.`rel` AS `contact-rel`,
1607         `contact`.`uid` AS `contact-uid`,
1608         `contact`.`contact-type` AS `contact-contact-type`,
1609         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1610         `contact`.`self` AS `self`,
1611         `contact`.`id` AS `cid`,
1612         `contact`.`alias` AS `alias`,
1613         `contact`.`photo` AS `photo`,
1614         `contact`.`name-date` AS `name-date`,
1615         `contact`.`uri-date` AS `uri-date`,
1616         `contact`.`avatar-date` AS `avatar-date`,
1617         `contact`.`thumb` AS `thumb`,
1618         `contact`.`dfrn-id` AS `dfrn-id`,
1619         `post-user`.`author-id` AS `author-id`,
1620         `author`.`url` AS `author-link`,
1621         `author`.`addr` AS `author-addr`,
1622         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1623         `author`.`nick` AS `author-nick`,
1624         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1625         `author`.`network` AS `author-network`,
1626         `author`.`blocked` AS `author-blocked`,
1627         `author`.`hidden` AS `author-hidden`,
1628         `post-user`.`owner-id` AS `owner-id`,
1629         `owner`.`url` AS `owner-link`,
1630         `owner`.`addr` AS `owner-addr`,
1631         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1632         `owner`.`nick` AS `owner-nick`,
1633         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1634         `owner`.`network` AS `owner-network`,
1635         `owner`.`blocked` AS `owner-blocked`,
1636         `owner`.`hidden` AS `owner-hidden`,
1637         `owner`.`contact-type` AS `owner-contact-type`,
1638         `post-user`.`causer-id` AS `causer-id`,
1639         `causer`.`url` AS `causer-link`,
1640         `causer`.`addr` AS `causer-addr`,
1641         `causer`.`name` AS `causer-name`,
1642         `causer`.`nick` AS `causer-nick`,
1643         `causer`.`thumb` AS `causer-avatar`,
1644         `causer`.`network` AS `causer-network`,
1645         `causer`.`blocked` AS `causer-blocked`,
1646         `causer`.`hidden` AS `causer-hidden`,
1647         `causer`.`contact-type` AS `causer-contact-type`,
1648         `post-delivery-data`.`postopts` AS `postopts`,
1649         `post-delivery-data`.`inform` AS `inform`,
1650         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1651         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1652         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1653         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1654         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1655         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1656         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1657         `post-user`.`event-id` AS `event-id`,
1658         `event`.`created` AS `event-created`,
1659         `event`.`edited` AS `event-edited`,
1660         `event`.`start` AS `event-start`,
1661         `event`.`finish` AS `event-finish`,
1662         `event`.`summary` AS `event-summary`,
1663         `event`.`desc` AS `event-desc`,
1664         `event`.`location` AS `event-location`,
1665         `event`.`type` AS `event-type`,
1666         `event`.`nofinish` AS `event-nofinish`,
1667         `event`.`adjust` AS `event-adjust`,
1668         `event`.`ignore` AS `event-ignore`,
1669         `diaspora-interaction`.`interaction` AS `signed_text`,
1670         `parent-item-uri`.`guid` AS `parent-guid`,
1671         `parent-post`.`network` AS `parent-network`,
1672         `parent-post`.`author-id` AS `parent-author-id`,
1673         `parent-post-author`.`url` AS `parent-author-link`,
1674         `parent-post-author`.`name` AS `parent-author-name`,
1675         `parent-post-author`.`network` AS `parent-author-network`
1676         FROM `post-user`
1677                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1678                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1679                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1680                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1681                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1682                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1683                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1684                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1685                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1686                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1687                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1688                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1689                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1690                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1691                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1692                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1693                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1694
1695 --
1696 -- VIEW post-thread-user-view
1697 --
1698 DROP VIEW IF EXISTS `post-thread-user-view`;
1699 CREATE VIEW `post-thread-user-view` AS SELECT 
1700         `post-user`.`id` AS `id`,
1701         `post-user`.`id` AS `post-user-id`,
1702         `post-thread-user`.`uid` AS `uid`,
1703         `parent-post`.`id` AS `parent`,
1704         `item-uri`.`uri` AS `uri`,
1705         `post-thread-user`.`uri-id` AS `uri-id`,
1706         `parent-item-uri`.`uri` AS `parent-uri`,
1707         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1708         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1709         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1710         `item-uri`.`guid` AS `guid`,
1711         `post-thread-user`.`wall` AS `wall`,
1712         `post-user`.`gravity` AS `gravity`,
1713         `external-item-uri`.`uri` AS `extid`,
1714         `post-user`.`external-id` AS `external-id`,
1715         `post-thread-user`.`created` AS `created`,
1716         `post-user`.`edited` AS `edited`,
1717         `post-thread-user`.`commented` AS `commented`,
1718         `post-thread-user`.`received` AS `received`,
1719         `post-thread-user`.`changed` AS `changed`,
1720         `post-user`.`post-type` AS `post-type`,
1721         `post-user`.`post-reason` AS `post-reason`,
1722         `post-user`.`private` AS `private`,
1723         `post-thread-user`.`pubmail` AS `pubmail`,
1724         `post-thread-user`.`ignored` AS `ignored`,
1725         `post-user`.`visible` AS `visible`,
1726         `post-thread-user`.`starred` AS `starred`,
1727         `post-thread-user`.`pinned` AS `pinned`,
1728         `post-thread-user`.`unseen` AS `unseen`,
1729         `post-user`.`deleted` AS `deleted`,
1730         `post-thread-user`.`origin` AS `origin`,
1731         `post-thread-user`.`forum_mode` AS `forum_mode`,
1732         `post-thread-user`.`mention` AS `mention`,
1733         `post-user`.`global` AS `global`,
1734         `post-thread-user`.`network` AS `network`,
1735         `post-user`.`vid` AS `vid`,
1736         `post-thread-user`.`psid` AS `psid`,
1737         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1738         `post-content`.`title` AS `title`,
1739         `post-content`.`content-warning` AS `content-warning`,
1740         `post-content`.`raw-body` AS `raw-body`,
1741         `post-content`.`body` AS `body`,
1742         `post-content`.`rendered-hash` AS `rendered-hash`,
1743         `post-content`.`rendered-html` AS `rendered-html`,
1744         `post-content`.`language` AS `language`,
1745         `post-content`.`plink` AS `plink`,
1746         `post-content`.`location` AS `location`,
1747         `post-content`.`coord` AS `coord`,
1748         `post-content`.`app` AS `app`,
1749         `post-content`.`object-type` AS `object-type`,
1750         `post-content`.`object` AS `object`,
1751         `post-content`.`target-type` AS `target-type`,
1752         `post-content`.`target` AS `target`,
1753         `post-content`.`resource-id` AS `resource-id`,
1754         `post-thread-user`.`contact-id` AS `contact-id`,
1755         `contact`.`url` AS `contact-link`,
1756         `contact`.`addr` AS `contact-addr`,
1757         `contact`.`name` AS `contact-name`,
1758         `contact`.`nick` AS `contact-nick`,
1759         `contact`.`thumb` AS `contact-avatar`,
1760         `contact`.`network` AS `contact-network`,
1761         `contact`.`blocked` AS `contact-blocked`,
1762         `contact`.`hidden` AS `contact-hidden`,
1763         `contact`.`readonly` AS `contact-readonly`,
1764         `contact`.`archive` AS `contact-archive`,
1765         `contact`.`pending` AS `contact-pending`,
1766         `contact`.`rel` AS `contact-rel`,
1767         `contact`.`uid` AS `contact-uid`,
1768         `contact`.`contact-type` AS `contact-contact-type`,
1769         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1770         `contact`.`self` AS `self`,
1771         `contact`.`id` AS `cid`,
1772         `contact`.`alias` AS `alias`,
1773         `contact`.`photo` AS `photo`,
1774         `contact`.`name-date` AS `name-date`,
1775         `contact`.`uri-date` AS `uri-date`,
1776         `contact`.`avatar-date` AS `avatar-date`,
1777         `contact`.`thumb` AS `thumb`,
1778         `contact`.`dfrn-id` AS `dfrn-id`,
1779         `post-thread-user`.`author-id` AS `author-id`,
1780         `author`.`url` AS `author-link`,
1781         `author`.`addr` AS `author-addr`,
1782         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1783         `author`.`nick` AS `author-nick`,
1784         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1785         `author`.`network` AS `author-network`,
1786         `author`.`blocked` AS `author-blocked`,
1787         `author`.`hidden` AS `author-hidden`,
1788         `post-thread-user`.`owner-id` AS `owner-id`,
1789         `owner`.`url` AS `owner-link`,
1790         `owner`.`addr` AS `owner-addr`,
1791         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1792         `owner`.`nick` AS `owner-nick`,
1793         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1794         `owner`.`network` AS `owner-network`,
1795         `owner`.`blocked` AS `owner-blocked`,
1796         `owner`.`hidden` AS `owner-hidden`,
1797         `owner`.`contact-type` AS `owner-contact-type`,
1798         `post-thread-user`.`causer-id` AS `causer-id`,
1799         `causer`.`url` AS `causer-link`,
1800         `causer`.`addr` AS `causer-addr`,
1801         `causer`.`name` AS `causer-name`,
1802         `causer`.`nick` AS `causer-nick`,
1803         `causer`.`thumb` AS `causer-avatar`,
1804         `causer`.`network` AS `causer-network`,
1805         `causer`.`blocked` AS `causer-blocked`,
1806         `causer`.`hidden` AS `causer-hidden`,
1807         `causer`.`contact-type` AS `causer-contact-type`,
1808         `post-delivery-data`.`postopts` AS `postopts`,
1809         `post-delivery-data`.`inform` AS `inform`,
1810         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1811         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1812         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1813         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1814         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1815         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1816         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1817         `post-user`.`event-id` AS `event-id`,
1818         `event`.`created` AS `event-created`,
1819         `event`.`edited` AS `event-edited`,
1820         `event`.`start` AS `event-start`,
1821         `event`.`finish` AS `event-finish`,
1822         `event`.`summary` AS `event-summary`,
1823         `event`.`desc` AS `event-desc`,
1824         `event`.`location` AS `event-location`,
1825         `event`.`type` AS `event-type`,
1826         `event`.`nofinish` AS `event-nofinish`,
1827         `event`.`adjust` AS `event-adjust`,
1828         `event`.`ignore` AS `event-ignore`,
1829         `diaspora-interaction`.`interaction` AS `signed_text`,
1830         `parent-item-uri`.`guid` AS `parent-guid`,
1831         `parent-post`.`network` AS `parent-network`,
1832         `parent-post`.`author-id` AS `parent-author-id`,
1833         `parent-post-author`.`url` AS `parent-author-link`,
1834         `parent-post-author`.`name` AS `parent-author-name`,
1835         `parent-post-author`.`network` AS `parent-author-network`
1836         FROM `post-thread-user`
1837                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
1838                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1839                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
1840                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
1841                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
1842                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
1843                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1844                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1845                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1846                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1847                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1848                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
1849                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
1850                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
1851                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
1852                         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`
1853                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1854
1855 --
1856 -- VIEW post-view
1857 --
1858 DROP VIEW IF EXISTS `post-view`;
1859 CREATE VIEW `post-view` AS SELECT 
1860         `item-uri`.`uri` AS `uri`,
1861         `post`.`uri-id` AS `uri-id`,
1862         `parent-item-uri`.`uri` AS `parent-uri`,
1863         `post`.`parent-uri-id` AS `parent-uri-id`,
1864         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1865         `post`.`thr-parent-id` AS `thr-parent-id`,
1866         `item-uri`.`guid` AS `guid`,
1867         `post`.`gravity` AS `gravity`,
1868         `external-item-uri`.`uri` AS `extid`,
1869         `post`.`external-id` AS `external-id`,
1870         `post`.`created` AS `created`,
1871         `post`.`edited` AS `edited`,
1872         `post-thread`.`commented` AS `commented`,
1873         `post`.`received` AS `received`,
1874         `post-thread`.`changed` AS `changed`,
1875         `post`.`post-type` AS `post-type`,
1876         `post`.`private` AS `private`,
1877         `post`.`visible` AS `visible`,
1878         `post`.`deleted` AS `deleted`,
1879         `post`.`global` AS `global`,
1880         `post`.`network` AS `network`,
1881         `post`.`vid` AS `vid`,
1882         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1883         `post-content`.`title` AS `title`,
1884         `post-content`.`content-warning` AS `content-warning`,
1885         `post-content`.`raw-body` AS `raw-body`,
1886         `post-content`.`body` AS `body`,
1887         `post-content`.`rendered-hash` AS `rendered-hash`,
1888         `post-content`.`rendered-html` AS `rendered-html`,
1889         `post-content`.`language` AS `language`,
1890         `post-content`.`plink` AS `plink`,
1891         `post-content`.`location` AS `location`,
1892         `post-content`.`coord` AS `coord`,
1893         `post-content`.`app` AS `app`,
1894         `post-content`.`object-type` AS `object-type`,
1895         `post-content`.`object` AS `object`,
1896         `post-content`.`target-type` AS `target-type`,
1897         `post-content`.`target` AS `target`,
1898         `post-content`.`resource-id` AS `resource-id`,
1899         `post`.`author-id` AS `author-id`,
1900         `author`.`url` AS `author-link`,
1901         `author`.`addr` AS `author-addr`,
1902         `author`.`name` AS `author-name`,
1903         `author`.`nick` AS `author-nick`,
1904         `author`.`thumb` AS `author-avatar`,
1905         `author`.`network` AS `author-network`,
1906         `author`.`blocked` AS `author-blocked`,
1907         `author`.`hidden` AS `author-hidden`,
1908         `post`.`owner-id` AS `owner-id`,
1909         `owner`.`url` AS `owner-link`,
1910         `owner`.`addr` AS `owner-addr`,
1911         `owner`.`name` AS `owner-name`,
1912         `owner`.`nick` AS `owner-nick`,
1913         `owner`.`thumb` AS `owner-avatar`,
1914         `owner`.`network` AS `owner-network`,
1915         `owner`.`blocked` AS `owner-blocked`,
1916         `owner`.`hidden` AS `owner-hidden`,
1917         `owner`.`contact-type` AS `owner-contact-type`,
1918         `post`.`causer-id` AS `causer-id`,
1919         `causer`.`url` AS `causer-link`,
1920         `causer`.`addr` AS `causer-addr`,
1921         `causer`.`name` AS `causer-name`,
1922         `causer`.`nick` AS `causer-nick`,
1923         `causer`.`thumb` AS `causer-avatar`,
1924         `causer`.`network` AS `causer-network`,
1925         `causer`.`blocked` AS `causer-blocked`,
1926         `causer`.`hidden` AS `causer-hidden`,
1927         `causer`.`contact-type` AS `causer-contact-type`,
1928         `diaspora-interaction`.`interaction` AS `signed_text`,
1929         `parent-item-uri`.`guid` AS `parent-guid`,
1930         `parent-post`.`network` AS `parent-network`,
1931         `parent-post`.`author-id` AS `parent-author-id`,
1932         `parent-post-author`.`url` AS `parent-author-link`,
1933         `parent-post-author`.`name` AS `parent-author-name`,
1934         `parent-post-author`.`network` AS `parent-author-network`
1935         FROM `post`
1936                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
1937                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
1938                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
1939                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
1940                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
1941                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
1942                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
1943                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
1944                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
1945                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
1946                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
1947                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
1948                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1949
1950 --
1951 -- VIEW post-thread-view
1952 --
1953 DROP VIEW IF EXISTS `post-thread-view`;
1954 CREATE VIEW `post-thread-view` AS SELECT 
1955         `item-uri`.`uri` AS `uri`,
1956         `post-thread`.`uri-id` AS `uri-id`,
1957         `parent-item-uri`.`uri` AS `parent-uri`,
1958         `post`.`parent-uri-id` AS `parent-uri-id`,
1959         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1960         `post`.`thr-parent-id` AS `thr-parent-id`,
1961         `item-uri`.`guid` AS `guid`,
1962         `post`.`gravity` AS `gravity`,
1963         `external-item-uri`.`uri` AS `extid`,
1964         `post`.`external-id` AS `external-id`,
1965         `post-thread`.`created` AS `created`,
1966         `post`.`edited` AS `edited`,
1967         `post-thread`.`commented` AS `commented`,
1968         `post-thread`.`received` AS `received`,
1969         `post-thread`.`changed` AS `changed`,
1970         `post`.`post-type` AS `post-type`,
1971         `post`.`private` AS `private`,
1972         `post`.`visible` AS `visible`,
1973         `post`.`deleted` AS `deleted`,
1974         `post`.`global` AS `global`,
1975         `post-thread`.`network` AS `network`,
1976         `post`.`vid` AS `vid`,
1977         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1978         `post-content`.`title` AS `title`,
1979         `post-content`.`content-warning` AS `content-warning`,
1980         `post-content`.`raw-body` AS `raw-body`,
1981         `post-content`.`body` AS `body`,
1982         `post-content`.`rendered-hash` AS `rendered-hash`,
1983         `post-content`.`rendered-html` AS `rendered-html`,
1984         `post-content`.`language` AS `language`,
1985         `post-content`.`plink` AS `plink`,
1986         `post-content`.`location` AS `location`,
1987         `post-content`.`coord` AS `coord`,
1988         `post-content`.`app` AS `app`,
1989         `post-content`.`object-type` AS `object-type`,
1990         `post-content`.`object` AS `object`,
1991         `post-content`.`target-type` AS `target-type`,
1992         `post-content`.`target` AS `target`,
1993         `post-content`.`resource-id` AS `resource-id`,
1994         `post-thread`.`author-id` AS `author-id`,
1995         `author`.`url` AS `author-link`,
1996         `author`.`addr` AS `author-addr`,
1997         `author`.`name` AS `author-name`,
1998         `author`.`nick` AS `author-nick`,
1999         `author`.`thumb` AS `author-avatar`,
2000         `author`.`network` AS `author-network`,
2001         `author`.`blocked` AS `author-blocked`,
2002         `author`.`hidden` AS `author-hidden`,
2003         `post-thread`.`owner-id` AS `owner-id`,
2004         `owner`.`url` AS `owner-link`,
2005         `owner`.`addr` AS `owner-addr`,
2006         `owner`.`name` AS `owner-name`,
2007         `owner`.`nick` AS `owner-nick`,
2008         `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`.`contact-type` AS `owner-contact-type`,
2013         `post-thread`.`causer-id` AS `causer-id`,
2014         `causer`.`url` AS `causer-link`,
2015         `causer`.`addr` AS `causer-addr`,
2016         `causer`.`name` AS `causer-name`,
2017         `causer`.`nick` AS `causer-nick`,
2018         `causer`.`thumb` AS `causer-avatar`,
2019         `causer`.`network` AS `causer-network`,
2020         `causer`.`blocked` AS `causer-blocked`,
2021         `causer`.`hidden` AS `causer-hidden`,
2022         `causer`.`contact-type` AS `causer-contact-type`,
2023         `diaspora-interaction`.`interaction` AS `signed_text`,
2024         `parent-item-uri`.`guid` AS `parent-guid`,
2025         `parent-post`.`network` AS `parent-network`,
2026         `parent-post`.`author-id` AS `parent-author-id`,
2027         `parent-post-author`.`url` AS `parent-author-link`,
2028         `parent-post-author`.`name` AS `parent-author-name`,
2029         `parent-post-author`.`network` AS `parent-author-network`
2030         FROM `post-thread`
2031                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2032                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2033                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2034                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2035                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2036                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2037                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2038                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2039                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2040                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2041                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2042                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2043                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2044
2045 --
2046 -- VIEW category-view
2047 --
2048 DROP VIEW IF EXISTS `category-view`;
2049 CREATE VIEW `category-view` AS SELECT 
2050         `post-category`.`uri-id` AS `uri-id`,
2051         `post-category`.`uid` AS `uid`,
2052         `post-category`.`type` AS `type`,
2053         `post-category`.`tid` AS `tid`,
2054         `tag`.`name` AS `name`,
2055         `tag`.`url` AS `url`
2056         FROM `post-category`
2057                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2058
2059 --
2060 -- VIEW tag-view
2061 --
2062 DROP VIEW IF EXISTS `tag-view`;
2063 CREATE VIEW `tag-view` AS SELECT 
2064         `post-tag`.`uri-id` AS `uri-id`,
2065         `post-tag`.`type` AS `type`,
2066         `post-tag`.`tid` AS `tid`,
2067         `post-tag`.`cid` AS `cid`,
2068         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2069         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
2070         FROM `post-tag`
2071                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2072                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2073
2074 --
2075 -- VIEW network-item-view
2076 --
2077 DROP VIEW IF EXISTS `network-item-view`;
2078 CREATE VIEW `network-item-view` AS SELECT 
2079         `post-user`.`uri-id` AS `uri-id`,
2080         `parent-post`.`id` AS `parent`,
2081         `post-user`.`received` AS `received`,
2082         `post-thread-user`.`commented` AS `commented`,
2083         `post-user`.`created` AS `created`,
2084         `post-user`.`uid` AS `uid`,
2085         `post-thread-user`.`starred` AS `starred`,
2086         `post-thread-user`.`mention` AS `mention`,
2087         `post-user`.`network` AS `network`,
2088         `post-user`.`unseen` AS `unseen`,
2089         `post-user`.`gravity` AS `gravity`,
2090         `post-user`.`contact-id` AS `contact-id`,
2091         `ownercontact`.`contact-type` AS `contact-type`
2092         FROM `post-user`
2093                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2094                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2095                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2096                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2097                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2098                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2099                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2100                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2101                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2102                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2103                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2104
2105 --
2106 -- VIEW network-thread-view
2107 --
2108 DROP VIEW IF EXISTS `network-thread-view`;
2109 CREATE VIEW `network-thread-view` AS SELECT 
2110         `post-thread-user`.`uri-id` AS `uri-id`,
2111         `parent-post`.`id` AS `parent`,
2112         `post-thread-user`.`received` AS `received`,
2113         `post-thread-user`.`commented` AS `commented`,
2114         `post-thread-user`.`created` AS `created`,
2115         `post-thread-user`.`uid` AS `uid`,
2116         `post-thread-user`.`starred` AS `starred`,
2117         `post-thread-user`.`mention` AS `mention`,
2118         `post-thread-user`.`network` AS `network`,
2119         `post-thread-user`.`contact-id` AS `contact-id`,
2120         `ownercontact`.`contact-type` AS `contact-type`
2121         FROM `post-thread-user`
2122                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2123                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2124                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2125                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2126                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2127                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2128                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2129                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2130                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2131                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2132                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2133
2134 --
2135 -- VIEW owner-view
2136 --
2137 DROP VIEW IF EXISTS `owner-view`;
2138 CREATE VIEW `owner-view` AS SELECT 
2139         `contact`.`id` AS `id`,
2140         `contact`.`uid` AS `uid`,
2141         `contact`.`created` AS `created`,
2142         `contact`.`updated` AS `updated`,
2143         `contact`.`self` AS `self`,
2144         `contact`.`remote_self` AS `remote_self`,
2145         `contact`.`rel` AS `rel`,
2146         `contact`.`duplex` AS `duplex`,
2147         `contact`.`network` AS `network`,
2148         `contact`.`protocol` AS `protocol`,
2149         `contact`.`name` AS `name`,
2150         `contact`.`nick` AS `nick`,
2151         `contact`.`location` AS `location`,
2152         `contact`.`about` AS `about`,
2153         `contact`.`keywords` AS `keywords`,
2154         `contact`.`gender` AS `gender`,
2155         `contact`.`xmpp` AS `xmpp`,
2156         `contact`.`attag` AS `attag`,
2157         `contact`.`avatar` AS `avatar`,
2158         `contact`.`photo` AS `photo`,
2159         `contact`.`thumb` AS `thumb`,
2160         `contact`.`micro` AS `micro`,
2161         `contact`.`site-pubkey` AS `site-pubkey`,
2162         `contact`.`issued-id` AS `issued-id`,
2163         `contact`.`dfrn-id` AS `dfrn-id`,
2164         `contact`.`url` AS `url`,
2165         `contact`.`nurl` AS `nurl`,
2166         `contact`.`addr` AS `addr`,
2167         `contact`.`alias` AS `alias`,
2168         `contact`.`pubkey` AS `pubkey`,
2169         `contact`.`prvkey` AS `prvkey`,
2170         `contact`.`batch` AS `batch`,
2171         `contact`.`request` AS `request`,
2172         `contact`.`notify` AS `notify`,
2173         `contact`.`poll` AS `poll`,
2174         `contact`.`confirm` AS `confirm`,
2175         `contact`.`poco` AS `poco`,
2176         `contact`.`aes_allow` AS `aes_allow`,
2177         `contact`.`ret-aes` AS `ret-aes`,
2178         `contact`.`usehub` AS `usehub`,
2179         `contact`.`subhub` AS `subhub`,
2180         `contact`.`hub-verify` AS `hub-verify`,
2181         `contact`.`last-update` AS `last-update`,
2182         `contact`.`success_update` AS `success_update`,
2183         `contact`.`failure_update` AS `failure_update`,
2184         `contact`.`name-date` AS `name-date`,
2185         `contact`.`uri-date` AS `uri-date`,
2186         `contact`.`avatar-date` AS `avatar-date`,
2187         `contact`.`avatar-date` AS `picdate`,
2188         `contact`.`term-date` AS `term-date`,
2189         `contact`.`last-item` AS `last-item`,
2190         `contact`.`priority` AS `priority`,
2191         `user`.`blocked` AS `blocked`,
2192         `contact`.`block_reason` AS `block_reason`,
2193         `contact`.`readonly` AS `readonly`,
2194         `contact`.`writable` AS `writable`,
2195         `contact`.`forum` AS `forum`,
2196         `contact`.`prv` AS `prv`,
2197         `contact`.`contact-type` AS `contact-type`,
2198         `contact`.`manually-approve` AS `manually-approve`,
2199         `contact`.`hidden` AS `hidden`,
2200         `contact`.`archive` AS `archive`,
2201         `contact`.`pending` AS `pending`,
2202         `contact`.`deleted` AS `deleted`,
2203         `contact`.`unsearchable` AS `unsearchable`,
2204         `contact`.`sensitive` AS `sensitive`,
2205         `contact`.`baseurl` AS `baseurl`,
2206         `contact`.`reason` AS `reason`,
2207         `contact`.`closeness` AS `closeness`,
2208         `contact`.`info` AS `info`,
2209         `contact`.`profile-id` AS `profile-id`,
2210         `contact`.`bdyear` AS `bdyear`,
2211         `contact`.`bd` AS `bd`,
2212         `contact`.`notify_new_posts` AS `notify_new_posts`,
2213         `contact`.`fetch_further_information` AS `fetch_further_information`,
2214         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2215         `user`.`parent-uid` AS `parent-uid`,
2216         `user`.`guid` AS `guid`,
2217         `user`.`nickname` AS `nickname`,
2218         `user`.`email` AS `email`,
2219         `user`.`openid` AS `openid`,
2220         `user`.`timezone` AS `timezone`,
2221         `user`.`language` AS `language`,
2222         `user`.`register_date` AS `register_date`,
2223         `user`.`login_date` AS `login_date`,
2224         `user`.`default-location` AS `default-location`,
2225         `user`.`allow_location` AS `allow_location`,
2226         `user`.`theme` AS `theme`,
2227         `user`.`pubkey` AS `upubkey`,
2228         `user`.`prvkey` AS `uprvkey`,
2229         `user`.`sprvkey` AS `sprvkey`,
2230         `user`.`spubkey` AS `spubkey`,
2231         `user`.`verified` AS `verified`,
2232         `user`.`blockwall` AS `blockwall`,
2233         `user`.`hidewall` AS `hidewall`,
2234         `user`.`blocktags` AS `blocktags`,
2235         `user`.`unkmail` AS `unkmail`,
2236         `user`.`cntunkmail` AS `cntunkmail`,
2237         `user`.`notify-flags` AS `notify-flags`,
2238         `user`.`page-flags` AS `page-flags`,
2239         `user`.`account-type` AS `account-type`,
2240         `user`.`prvnets` AS `prvnets`,
2241         `user`.`maxreq` AS `maxreq`,
2242         `user`.`expire` AS `expire`,
2243         `user`.`account_removed` AS `account_removed`,
2244         `user`.`account_expired` AS `account_expired`,
2245         `user`.`account_expires_on` AS `account_expires_on`,
2246         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2247         `user`.`def_gid` AS `def_gid`,
2248         `user`.`allow_cid` AS `allow_cid`,
2249         `user`.`allow_gid` AS `allow_gid`,
2250         `user`.`deny_cid` AS `deny_cid`,
2251         `user`.`deny_gid` AS `deny_gid`,
2252         `user`.`openidserver` AS `openidserver`,
2253         `profile`.`publish` AS `publish`,
2254         `profile`.`net-publish` AS `net-publish`,
2255         `profile`.`hide-friends` AS `hide-friends`,
2256         `profile`.`prv_keywords` AS `prv_keywords`,
2257         `profile`.`pub_keywords` AS `pub_keywords`,
2258         `profile`.`address` AS `address`,
2259         `profile`.`locality` AS `locality`,
2260         `profile`.`region` AS `region`,
2261         `profile`.`postal-code` AS `postal-code`,
2262         `profile`.`country-name` AS `country-name`,
2263         `profile`.`homepage` AS `homepage`,
2264         `profile`.`dob` AS `dob`
2265         FROM `user`
2266                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2267                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2268
2269 --
2270 -- VIEW pending-view
2271 --
2272 DROP VIEW IF EXISTS `pending-view`;
2273 CREATE VIEW `pending-view` AS SELECT 
2274         `register`.`id` AS `id`,
2275         `register`.`hash` AS `hash`,
2276         `register`.`created` AS `created`,
2277         `register`.`uid` AS `uid`,
2278         `register`.`password` AS `password`,
2279         `register`.`language` AS `language`,
2280         `register`.`note` AS `note`,
2281         `contact`.`self` AS `self`,
2282         `contact`.`name` AS `name`,
2283         `contact`.`url` AS `url`,
2284         `contact`.`micro` AS `micro`,
2285         `user`.`email` AS `email`,
2286         `contact`.`nick` AS `nick`
2287         FROM `register`
2288                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2289                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2290
2291 --
2292 -- VIEW tag-search-view
2293 --
2294 DROP VIEW IF EXISTS `tag-search-view`;
2295 CREATE VIEW `tag-search-view` AS SELECT 
2296         `post-tag`.`uri-id` AS `uri-id`,
2297         `post-user`.`uid` AS `uid`,
2298         `post-user`.`id` AS `iid`,
2299         `post-user`.`private` AS `private`,
2300         `post-user`.`wall` AS `wall`,
2301         `post-user`.`origin` AS `origin`,
2302         `post-user`.`global` AS `global`,
2303         `post-user`.`gravity` AS `gravity`,
2304         `post-user`.`received` AS `received`,
2305         `post-user`.`network` AS `network`,
2306         `post-user`.`author-id` AS `author-id`,
2307         `tag`.`name` AS `name`
2308         FROM `post-tag`
2309                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2310                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2311                         WHERE `post-tag`.`type` = 1;
2312
2313 --
2314 -- VIEW workerqueue-view
2315 --
2316 DROP VIEW IF EXISTS `workerqueue-view`;
2317 CREATE VIEW `workerqueue-view` AS SELECT 
2318         `process`.`pid` AS `pid`,
2319         `workerqueue`.`priority` AS `priority`
2320         FROM `process`
2321                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2322                         WHERE NOT `workerqueue`.`done`;