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