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