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