]> git.mxchange.org Git - friendica.git/blob - database.sql
Merge pull request #10461 from annando/ap-preview
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2021.06-rc (Siberian Iris)
3 -- DB_UPDATE_VERSION 1424
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-media
1108 --
1109 CREATE TABLE IF NOT EXISTS `post-media` (
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 'Media URL',
1113         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1114         `mimetype` varchar(60) COMMENT '',
1115         `height` smallint unsigned COMMENT 'Height of the media',
1116         `width` smallint unsigned COMMENT 'Width of the media',
1117         `size` int unsigned COMMENT 'Media size',
1118         `preview` varbinary(255) COMMENT 'Preview URL',
1119         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1120         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1121         `description` text COMMENT '',
1122         `name` varchar(255) COMMENT 'Name of the media',
1123         `author-url` varbinary(255) COMMENT 'URL of the author of the media',
1124         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1125         `author-image` varbinary(255) COMMENT 'Image of the author of the media',
1126         `publisher-url` varbinary(255) COMMENT 'URL of the publisher of the media',
1127         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1128         `publisher-image` varbinary(255) COMMENT 'Image of the publisher of the media',
1129          PRIMARY KEY(`id`),
1130          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1131         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1132 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1133
1134 --
1135 -- TABLE post-tag
1136 --
1137 CREATE TABLE IF NOT EXISTS `post-tag` (
1138         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1139         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1140         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1141         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1142          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1143          INDEX `tid` (`tid`),
1144          INDEX `cid` (`cid`),
1145         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1146         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1147         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1148 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1149
1150 --
1151 -- TABLE post-thread
1152 --
1153 CREATE TABLE IF NOT EXISTS `post-thread` (
1154         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1155         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1156         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1157         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1158         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1159         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1160         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1161         `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',
1162         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1163          PRIMARY KEY(`uri-id`),
1164          INDEX `owner-id` (`owner-id`),
1165          INDEX `author-id` (`author-id`),
1166          INDEX `causer-id` (`causer-id`),
1167          INDEX `received` (`received`),
1168          INDEX `commented` (`commented`),
1169         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1170         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1171         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1172         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1173 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1174
1175 --
1176 -- TABLE post-user
1177 --
1178 CREATE TABLE IF NOT EXISTS `post-user` (
1179         `id` int unsigned NOT NULL auto_increment,
1180         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1181         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1182         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1183         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1184         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1185         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1186         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1187         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1188         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1189         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1190         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1191         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1192         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1193         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1194         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1195         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1196         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1197         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1198         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1199         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1200         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1201         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1202         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1203         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1204         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1205         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1206         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1207         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1208         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1209          PRIMARY KEY(`id`),
1210          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1211          INDEX `uri-id` (`uri-id`),
1212          INDEX `parent-uri-id` (`parent-uri-id`),
1213          INDEX `thr-parent-id` (`thr-parent-id`),
1214          INDEX `external-id` (`external-id`),
1215          INDEX `owner-id` (`owner-id`),
1216          INDEX `author-id` (`author-id`),
1217          INDEX `causer-id` (`causer-id`),
1218          INDEX `vid` (`vid`),
1219          INDEX `contact-id` (`contact-id`),
1220          INDEX `event-id` (`event-id`),
1221          INDEX `psid` (`psid`),
1222          INDEX `author-id_uid` (`author-id`,`uid`),
1223          INDEX `author-id_received` (`author-id`,`received`),
1224          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1225          INDEX `uid_contactid` (`uid`,`contact-id`),
1226          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1227          INDEX `uid_unseen` (`uid`,`unseen`),
1228          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1229         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1230         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1231         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1232         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1233         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1234         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1235         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1236         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1237         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1238         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1239         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1240         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1241 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1242
1243 --
1244 -- TABLE post-thread-user
1245 --
1246 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1247         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1248         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1249         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1250         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1251         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1252         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1253         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1254         `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',
1255         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1256         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1257         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'The thread is pinned on the profile page',
1258         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1259         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1260         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1261         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1262         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1263         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1264         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1265         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1266         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1267         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1268         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1269         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1270          PRIMARY KEY(`uid`,`uri-id`),
1271          INDEX `uri-id` (`uri-id`),
1272          INDEX `owner-id` (`owner-id`),
1273          INDEX `author-id` (`author-id`),
1274          INDEX `causer-id` (`causer-id`),
1275          INDEX `uid` (`uid`),
1276          INDEX `contact-id` (`contact-id`),
1277          INDEX `psid` (`psid`),
1278          INDEX `post-user-id` (`post-user-id`),
1279          INDEX `commented` (`commented`),
1280          INDEX `uid_received` (`uid`,`received`),
1281          INDEX `uid_pinned` (`uid`,`pinned`),
1282          INDEX `uid_commented` (`uid`,`commented`),
1283          INDEX `uid_starred` (`uid`,`starred`),
1284          INDEX `uid_mention` (`uid`,`mention`),
1285         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1286         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1287         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1288         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1289         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1290         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1291         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1292         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1293 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1294
1295 --
1296 -- TABLE post-user-notification
1297 --
1298 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1299         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1300         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1301         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1302          PRIMARY KEY(`uid`,`uri-id`),
1303          INDEX `uri-id` (`uri-id`),
1304         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1305         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1306 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1307
1308 --
1309 -- TABLE process
1310 --
1311 CREATE TABLE IF NOT EXISTS `process` (
1312         `pid` int unsigned NOT NULL COMMENT '',
1313         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1314         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1315          PRIMARY KEY(`pid`),
1316          INDEX `command` (`command`)
1317 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1318
1319 --
1320 -- TABLE profile
1321 --
1322 CREATE TABLE IF NOT EXISTS `profile` (
1323         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1324         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1325         `profile-name` varchar(255) COMMENT 'Deprecated',
1326         `is-default` boolean COMMENT 'Deprecated',
1327         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1328         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1329         `pdesc` varchar(255) COMMENT 'Deprecated',
1330         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1331         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1332         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1333         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1334         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1335         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1336         `hometown` varchar(255) COMMENT 'Deprecated',
1337         `gender` varchar(32) COMMENT 'Deprecated',
1338         `marital` varchar(255) COMMENT 'Deprecated',
1339         `with` text COMMENT 'Deprecated',
1340         `howlong` datetime COMMENT 'Deprecated',
1341         `sexual` varchar(255) COMMENT 'Deprecated',
1342         `politic` varchar(255) COMMENT 'Deprecated',
1343         `religion` varchar(255) COMMENT 'Deprecated',
1344         `pub_keywords` text COMMENT '',
1345         `prv_keywords` text COMMENT '',
1346         `likes` text COMMENT 'Deprecated',
1347         `dislikes` text COMMENT 'Deprecated',
1348         `about` text COMMENT 'Profile description',
1349         `summary` varchar(255) COMMENT 'Deprecated',
1350         `music` text COMMENT 'Deprecated',
1351         `book` text COMMENT 'Deprecated',
1352         `tv` text COMMENT 'Deprecated',
1353         `film` text COMMENT 'Deprecated',
1354         `interest` text COMMENT 'Deprecated',
1355         `romance` text COMMENT 'Deprecated',
1356         `work` text COMMENT 'Deprecated',
1357         `education` text COMMENT 'Deprecated',
1358         `contact` text COMMENT 'Deprecated',
1359         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1360         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1361         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1362         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1363         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1364         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1365          PRIMARY KEY(`id`),
1366          INDEX `uid_is-default` (`uid`,`is-default`),
1367          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1368         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1369 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1370
1371 --
1372 -- TABLE profile_check
1373 --
1374 CREATE TABLE IF NOT EXISTS `profile_check` (
1375         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1376         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1377         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1378         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1379         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1380         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1381          PRIMARY KEY(`id`),
1382          INDEX `uid` (`uid`),
1383          INDEX `cid` (`cid`),
1384         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1385         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1386 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1387
1388 --
1389 -- TABLE profile_field
1390 --
1391 CREATE TABLE IF NOT EXISTS `profile_field` (
1392         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1393         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1394         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1395         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1396         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1397         `value` text COMMENT 'Value of the field',
1398         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1399         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1400          PRIMARY KEY(`id`),
1401          INDEX `uid` (`uid`),
1402          INDEX `order` (`order`),
1403          INDEX `psid` (`psid`),
1404         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1405         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1406 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1407
1408 --
1409 -- TABLE push_subscriber
1410 --
1411 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1412         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1413         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1414         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1415         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1416         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1417         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1418         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1419         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1420         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1421         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1422          PRIMARY KEY(`id`),
1423          INDEX `next_try` (`next_try`),
1424          INDEX `uid` (`uid`),
1425         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1426 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1427
1428 --
1429 -- TABLE register
1430 --
1431 CREATE TABLE IF NOT EXISTS `register` (
1432         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1433         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1434         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1435         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1436         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1437         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1438         `note` text COMMENT '',
1439          PRIMARY KEY(`id`),
1440          INDEX `uid` (`uid`),
1441         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1442 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1443
1444 --
1445 -- TABLE search
1446 --
1447 CREATE TABLE IF NOT EXISTS `search` (
1448         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1449         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1450         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1451          PRIMARY KEY(`id`),
1452          INDEX `uid_term` (`uid`,`term`(64)),
1453          INDEX `term` (`term`(64)),
1454         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1455 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1456
1457 --
1458 -- TABLE session
1459 --
1460 CREATE TABLE IF NOT EXISTS `session` (
1461         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1462         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1463         `data` text COMMENT '',
1464         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1465          PRIMARY KEY(`id`),
1466          INDEX `sid` (`sid`(64)),
1467          INDEX `expire` (`expire`)
1468 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1469
1470 --
1471 -- TABLE storage
1472 --
1473 CREATE TABLE IF NOT EXISTS `storage` (
1474         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1475         `data` longblob NOT NULL COMMENT 'file data',
1476          PRIMARY KEY(`id`)
1477 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1478
1479 --
1480 -- TABLE tokens
1481 --
1482 CREATE TABLE IF NOT EXISTS `tokens` (
1483         `id` varchar(40) NOT NULL COMMENT '',
1484         `secret` text COMMENT '',
1485         `client_id` varchar(20) NOT NULL DEFAULT '',
1486         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1487         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1488         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1489          PRIMARY KEY(`id`),
1490          INDEX `client_id` (`client_id`),
1491          INDEX `uid` (`uid`),
1492         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1493         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1494 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1495
1496 --
1497 -- TABLE userd
1498 --
1499 CREATE TABLE IF NOT EXISTS `userd` (
1500         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1501         `username` varchar(255) NOT NULL COMMENT '',
1502          PRIMARY KEY(`id`),
1503          INDEX `username` (`username`(32))
1504 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1505
1506 --
1507 -- TABLE user-contact
1508 --
1509 CREATE TABLE IF NOT EXISTS `user-contact` (
1510         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1511         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1512         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1513         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1514         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1515          PRIMARY KEY(`uid`,`cid`),
1516          INDEX `cid` (`cid`),
1517         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1518         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1519 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1520
1521 --
1522 -- TABLE worker-ipc
1523 --
1524 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1525         `key` int NOT NULL COMMENT '',
1526         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1527          PRIMARY KEY(`key`)
1528 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1529
1530 --
1531 -- TABLE workerqueue
1532 --
1533 CREATE TABLE IF NOT EXISTS `workerqueue` (
1534         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1535         `command` varchar(100) COMMENT 'Task command',
1536         `parameter` mediumtext COMMENT 'Task parameter',
1537         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1538         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1539         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1540         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1541         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1542         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1543         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1544          PRIMARY KEY(`id`),
1545          INDEX `command` (`command`),
1546          INDEX `done_command_parameter` (`done`,`command`,`parameter`(64)),
1547          INDEX `done_executed` (`done`,`executed`),
1548          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
1549          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1550          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1551          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1552          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1553 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1554
1555 --
1556 -- VIEW application-view
1557 --
1558 DROP VIEW IF EXISTS `application-view`;
1559 CREATE VIEW `application-view` AS SELECT 
1560         `application`.`id` AS `id`,
1561         `application-token`.`uid` AS `uid`,
1562         `application`.`name` AS `name`,
1563         `application`.`redirect_uri` AS `redirect_uri`,
1564         `application`.`website` AS `website`,
1565         `application`.`client_id` AS `client_id`,
1566         `application`.`client_secret` AS `client_secret`,
1567         `application-token`.`code` AS `code`,
1568         `application-token`.`access_token` AS `access_token`,
1569         `application-token`.`created_at` AS `created_at`,
1570         `application-token`.`scopes` AS `scopes`,
1571         `application-token`.`read` AS `read`,
1572         `application-token`.`write` AS `write`,
1573         `application-token`.`follow` AS `follow`,
1574         `application-token`.`push` AS `push`
1575         FROM `application-token`
1576                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1577
1578 --
1579 -- VIEW post-user-view
1580 --
1581 DROP VIEW IF EXISTS `post-user-view`;
1582 CREATE VIEW `post-user-view` AS SELECT 
1583         `post-user`.`id` AS `id`,
1584         `post-user`.`id` AS `post-user-id`,
1585         `post-user`.`uid` AS `uid`,
1586         `parent-post`.`id` AS `parent`,
1587         `item-uri`.`uri` AS `uri`,
1588         `post-user`.`uri-id` AS `uri-id`,
1589         `parent-item-uri`.`uri` AS `parent-uri`,
1590         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1591         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1592         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1593         `item-uri`.`guid` AS `guid`,
1594         `post-user`.`wall` AS `wall`,
1595         `post-user`.`gravity` AS `gravity`,
1596         `external-item-uri`.`uri` AS `extid`,
1597         `post-user`.`external-id` AS `external-id`,
1598         `post-user`.`created` AS `created`,
1599         `post-user`.`edited` AS `edited`,
1600         `post-thread-user`.`commented` AS `commented`,
1601         `post-user`.`received` AS `received`,
1602         `post-thread-user`.`changed` AS `changed`,
1603         `post-user`.`post-type` AS `post-type`,
1604         `post-user`.`post-reason` AS `post-reason`,
1605         `post-user`.`private` AS `private`,
1606         `post-thread-user`.`pubmail` AS `pubmail`,
1607         `post-user`.`visible` AS `visible`,
1608         `post-thread-user`.`starred` AS `starred`,
1609         `post-thread-user`.`pinned` AS `pinned`,
1610         `post-user`.`unseen` AS `unseen`,
1611         `post-user`.`deleted` AS `deleted`,
1612         `post-user`.`origin` AS `origin`,
1613         `post-thread-user`.`origin` AS `parent-origin`,
1614         `post-thread-user`.`forum_mode` AS `forum_mode`,
1615         `post-thread-user`.`mention` AS `mention`,
1616         `post-user`.`global` AS `global`,
1617         `post-user`.`network` AS `network`,
1618         `post-user`.`vid` AS `vid`,
1619         `post-user`.`psid` AS `psid`,
1620         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1621         `post-content`.`title` AS `title`,
1622         `post-content`.`content-warning` AS `content-warning`,
1623         `post-content`.`raw-body` AS `raw-body`,
1624         `post-content`.`body` AS `body`,
1625         `post-content`.`rendered-hash` AS `rendered-hash`,
1626         `post-content`.`rendered-html` AS `rendered-html`,
1627         `post-content`.`language` AS `language`,
1628         `post-content`.`plink` AS `plink`,
1629         `post-content`.`location` AS `location`,
1630         `post-content`.`coord` AS `coord`,
1631         `post-content`.`app` AS `app`,
1632         `post-content`.`object-type` AS `object-type`,
1633         `post-content`.`object` AS `object`,
1634         `post-content`.`target-type` AS `target-type`,
1635         `post-content`.`target` AS `target`,
1636         `post-content`.`resource-id` AS `resource-id`,
1637         `post-user`.`contact-id` AS `contact-id`,
1638         `contact`.`url` AS `contact-link`,
1639         `contact`.`addr` AS `contact-addr`,
1640         `contact`.`name` AS `contact-name`,
1641         `contact`.`nick` AS `contact-nick`,
1642         `contact`.`thumb` AS `contact-avatar`,
1643         `contact`.`network` AS `contact-network`,
1644         `contact`.`blocked` AS `contact-blocked`,
1645         `contact`.`hidden` AS `contact-hidden`,
1646         `contact`.`readonly` AS `contact-readonly`,
1647         `contact`.`archive` AS `contact-archive`,
1648         `contact`.`pending` AS `contact-pending`,
1649         `contact`.`rel` AS `contact-rel`,
1650         `contact`.`uid` AS `contact-uid`,
1651         `contact`.`contact-type` AS `contact-contact-type`,
1652         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1653         `contact`.`self` AS `self`,
1654         `contact`.`id` AS `cid`,
1655         `contact`.`alias` AS `alias`,
1656         `contact`.`photo` AS `photo`,
1657         `contact`.`name-date` AS `name-date`,
1658         `contact`.`uri-date` AS `uri-date`,
1659         `contact`.`avatar-date` AS `avatar-date`,
1660         `contact`.`thumb` AS `thumb`,
1661         `contact`.`dfrn-id` AS `dfrn-id`,
1662         `post-user`.`author-id` AS `author-id`,
1663         `author`.`url` AS `author-link`,
1664         `author`.`addr` AS `author-addr`,
1665         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1666         `author`.`nick` AS `author-nick`,
1667         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1668         `author`.`network` AS `author-network`,
1669         `author`.`blocked` AS `author-blocked`,
1670         `author`.`hidden` AS `author-hidden`,
1671         `post-user`.`owner-id` AS `owner-id`,
1672         `owner`.`url` AS `owner-link`,
1673         `owner`.`addr` AS `owner-addr`,
1674         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1675         `owner`.`nick` AS `owner-nick`,
1676         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1677         `owner`.`network` AS `owner-network`,
1678         `owner`.`blocked` AS `owner-blocked`,
1679         `owner`.`hidden` AS `owner-hidden`,
1680         `owner`.`contact-type` AS `owner-contact-type`,
1681         `post-user`.`causer-id` AS `causer-id`,
1682         `causer`.`url` AS `causer-link`,
1683         `causer`.`addr` AS `causer-addr`,
1684         `causer`.`name` AS `causer-name`,
1685         `causer`.`nick` AS `causer-nick`,
1686         `causer`.`thumb` AS `causer-avatar`,
1687         `causer`.`network` AS `causer-network`,
1688         `causer`.`blocked` AS `causer-blocked`,
1689         `causer`.`hidden` AS `causer-hidden`,
1690         `causer`.`contact-type` AS `causer-contact-type`,
1691         `post-delivery-data`.`postopts` AS `postopts`,
1692         `post-delivery-data`.`inform` AS `inform`,
1693         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1694         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1695         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1696         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1697         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1698         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1699         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1700         `post-user`.`event-id` AS `event-id`,
1701         `event`.`created` AS `event-created`,
1702         `event`.`edited` AS `event-edited`,
1703         `event`.`start` AS `event-start`,
1704         `event`.`finish` AS `event-finish`,
1705         `event`.`summary` AS `event-summary`,
1706         `event`.`desc` AS `event-desc`,
1707         `event`.`location` AS `event-location`,
1708         `event`.`type` AS `event-type`,
1709         `event`.`nofinish` AS `event-nofinish`,
1710         `event`.`adjust` AS `event-adjust`,
1711         `event`.`ignore` AS `event-ignore`,
1712         `diaspora-interaction`.`interaction` AS `signed_text`,
1713         `parent-item-uri`.`guid` AS `parent-guid`,
1714         `parent-post`.`network` AS `parent-network`,
1715         `parent-post`.`author-id` AS `parent-author-id`,
1716         `parent-post-author`.`url` AS `parent-author-link`,
1717         `parent-post-author`.`name` AS `parent-author-name`,
1718         `parent-post-author`.`network` AS `parent-author-network`,
1719         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1720         `parent-post-author`.`hidden` AS `parent-author-hidden`
1721         FROM `post-user`
1722                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1723                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1724                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1725                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1726                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1727                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1728                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1729                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1730                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1731                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1732                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1733                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1734                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1735                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1736                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1737                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1738                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1739
1740 --
1741 -- VIEW post-thread-user-view
1742 --
1743 DROP VIEW IF EXISTS `post-thread-user-view`;
1744 CREATE VIEW `post-thread-user-view` AS SELECT 
1745         `post-user`.`id` AS `id`,
1746         `post-user`.`id` AS `post-user-id`,
1747         `post-thread-user`.`uid` AS `uid`,
1748         `parent-post`.`id` AS `parent`,
1749         `item-uri`.`uri` AS `uri`,
1750         `post-thread-user`.`uri-id` AS `uri-id`,
1751         `parent-item-uri`.`uri` AS `parent-uri`,
1752         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1753         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1754         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1755         `item-uri`.`guid` AS `guid`,
1756         `post-thread-user`.`wall` AS `wall`,
1757         `post-user`.`gravity` AS `gravity`,
1758         `external-item-uri`.`uri` AS `extid`,
1759         `post-user`.`external-id` AS `external-id`,
1760         `post-thread-user`.`created` AS `created`,
1761         `post-user`.`edited` AS `edited`,
1762         `post-thread-user`.`commented` AS `commented`,
1763         `post-thread-user`.`received` AS `received`,
1764         `post-thread-user`.`changed` AS `changed`,
1765         `post-user`.`post-type` AS `post-type`,
1766         `post-user`.`post-reason` AS `post-reason`,
1767         `post-user`.`private` AS `private`,
1768         `post-thread-user`.`pubmail` AS `pubmail`,
1769         `post-thread-user`.`ignored` AS `ignored`,
1770         `post-user`.`visible` AS `visible`,
1771         `post-thread-user`.`starred` AS `starred`,
1772         `post-thread-user`.`pinned` AS `pinned`,
1773         `post-thread-user`.`unseen` AS `unseen`,
1774         `post-user`.`deleted` AS `deleted`,
1775         `post-thread-user`.`origin` AS `origin`,
1776         `post-thread-user`.`forum_mode` AS `forum_mode`,
1777         `post-thread-user`.`mention` AS `mention`,
1778         `post-user`.`global` AS `global`,
1779         `post-thread-user`.`network` AS `network`,
1780         `post-user`.`vid` AS `vid`,
1781         `post-thread-user`.`psid` AS `psid`,
1782         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1783         `post-content`.`title` AS `title`,
1784         `post-content`.`content-warning` AS `content-warning`,
1785         `post-content`.`raw-body` AS `raw-body`,
1786         `post-content`.`body` AS `body`,
1787         `post-content`.`rendered-hash` AS `rendered-hash`,
1788         `post-content`.`rendered-html` AS `rendered-html`,
1789         `post-content`.`language` AS `language`,
1790         `post-content`.`plink` AS `plink`,
1791         `post-content`.`location` AS `location`,
1792         `post-content`.`coord` AS `coord`,
1793         `post-content`.`app` AS `app`,
1794         `post-content`.`object-type` AS `object-type`,
1795         `post-content`.`object` AS `object`,
1796         `post-content`.`target-type` AS `target-type`,
1797         `post-content`.`target` AS `target`,
1798         `post-content`.`resource-id` AS `resource-id`,
1799         `post-thread-user`.`contact-id` AS `contact-id`,
1800         `contact`.`url` AS `contact-link`,
1801         `contact`.`addr` AS `contact-addr`,
1802         `contact`.`name` AS `contact-name`,
1803         `contact`.`nick` AS `contact-nick`,
1804         `contact`.`thumb` AS `contact-avatar`,
1805         `contact`.`network` AS `contact-network`,
1806         `contact`.`blocked` AS `contact-blocked`,
1807         `contact`.`hidden` AS `contact-hidden`,
1808         `contact`.`readonly` AS `contact-readonly`,
1809         `contact`.`archive` AS `contact-archive`,
1810         `contact`.`pending` AS `contact-pending`,
1811         `contact`.`rel` AS `contact-rel`,
1812         `contact`.`uid` AS `contact-uid`,
1813         `contact`.`contact-type` AS `contact-contact-type`,
1814         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1815         `contact`.`self` AS `self`,
1816         `contact`.`id` AS `cid`,
1817         `contact`.`alias` AS `alias`,
1818         `contact`.`photo` AS `photo`,
1819         `contact`.`name-date` AS `name-date`,
1820         `contact`.`uri-date` AS `uri-date`,
1821         `contact`.`avatar-date` AS `avatar-date`,
1822         `contact`.`thumb` AS `thumb`,
1823         `contact`.`dfrn-id` AS `dfrn-id`,
1824         `post-thread-user`.`author-id` AS `author-id`,
1825         `author`.`url` AS `author-link`,
1826         `author`.`addr` AS `author-addr`,
1827         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1828         `author`.`nick` AS `author-nick`,
1829         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1830         `author`.`network` AS `author-network`,
1831         `author`.`blocked` AS `author-blocked`,
1832         `author`.`hidden` AS `author-hidden`,
1833         `post-thread-user`.`owner-id` AS `owner-id`,
1834         `owner`.`url` AS `owner-link`,
1835         `owner`.`addr` AS `owner-addr`,
1836         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1837         `owner`.`nick` AS `owner-nick`,
1838         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1839         `owner`.`network` AS `owner-network`,
1840         `owner`.`blocked` AS `owner-blocked`,
1841         `owner`.`hidden` AS `owner-hidden`,
1842         `owner`.`contact-type` AS `owner-contact-type`,
1843         `post-thread-user`.`causer-id` AS `causer-id`,
1844         `causer`.`url` AS `causer-link`,
1845         `causer`.`addr` AS `causer-addr`,
1846         `causer`.`name` AS `causer-name`,
1847         `causer`.`nick` AS `causer-nick`,
1848         `causer`.`thumb` AS `causer-avatar`,
1849         `causer`.`network` AS `causer-network`,
1850         `causer`.`blocked` AS `causer-blocked`,
1851         `causer`.`hidden` AS `causer-hidden`,
1852         `causer`.`contact-type` AS `causer-contact-type`,
1853         `post-delivery-data`.`postopts` AS `postopts`,
1854         `post-delivery-data`.`inform` AS `inform`,
1855         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1856         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1857         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1858         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1859         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1860         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1861         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1862         `post-user`.`event-id` AS `event-id`,
1863         `event`.`created` AS `event-created`,
1864         `event`.`edited` AS `event-edited`,
1865         `event`.`start` AS `event-start`,
1866         `event`.`finish` AS `event-finish`,
1867         `event`.`summary` AS `event-summary`,
1868         `event`.`desc` AS `event-desc`,
1869         `event`.`location` AS `event-location`,
1870         `event`.`type` AS `event-type`,
1871         `event`.`nofinish` AS `event-nofinish`,
1872         `event`.`adjust` AS `event-adjust`,
1873         `event`.`ignore` AS `event-ignore`,
1874         `diaspora-interaction`.`interaction` AS `signed_text`,
1875         `parent-item-uri`.`guid` AS `parent-guid`,
1876         `parent-post`.`network` AS `parent-network`,
1877         `parent-post`.`author-id` AS `parent-author-id`,
1878         `parent-post-author`.`url` AS `parent-author-link`,
1879         `parent-post-author`.`name` AS `parent-author-name`,
1880         `parent-post-author`.`network` AS `parent-author-network`,
1881         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1882         `parent-post-author`.`hidden` AS `parent-author-hidden`
1883         FROM `post-thread-user`
1884                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
1885                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1886                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
1887                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
1888                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
1889                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
1890                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1891                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1892                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1893                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1894                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1895                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
1896                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
1897                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
1898                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
1899                         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`
1900                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1901
1902 --
1903 -- VIEW post-view
1904 --
1905 DROP VIEW IF EXISTS `post-view`;
1906 CREATE VIEW `post-view` AS SELECT 
1907         `item-uri`.`uri` AS `uri`,
1908         `post`.`uri-id` AS `uri-id`,
1909         `parent-item-uri`.`uri` AS `parent-uri`,
1910         `post`.`parent-uri-id` AS `parent-uri-id`,
1911         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1912         `post`.`thr-parent-id` AS `thr-parent-id`,
1913         `item-uri`.`guid` AS `guid`,
1914         `post`.`gravity` AS `gravity`,
1915         `external-item-uri`.`uri` AS `extid`,
1916         `post`.`external-id` AS `external-id`,
1917         `post`.`created` AS `created`,
1918         `post`.`edited` AS `edited`,
1919         `post-thread`.`commented` AS `commented`,
1920         `post`.`received` AS `received`,
1921         `post-thread`.`changed` AS `changed`,
1922         `post`.`post-type` AS `post-type`,
1923         `post`.`private` AS `private`,
1924         `post`.`visible` AS `visible`,
1925         `post`.`deleted` AS `deleted`,
1926         `post`.`global` AS `global`,
1927         `post`.`network` AS `network`,
1928         `post`.`vid` AS `vid`,
1929         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1930         `post-content`.`title` AS `title`,
1931         `post-content`.`content-warning` AS `content-warning`,
1932         `post-content`.`raw-body` AS `raw-body`,
1933         `post-content`.`body` AS `body`,
1934         `post-content`.`rendered-hash` AS `rendered-hash`,
1935         `post-content`.`rendered-html` AS `rendered-html`,
1936         `post-content`.`language` AS `language`,
1937         `post-content`.`plink` AS `plink`,
1938         `post-content`.`location` AS `location`,
1939         `post-content`.`coord` AS `coord`,
1940         `post-content`.`app` AS `app`,
1941         `post-content`.`object-type` AS `object-type`,
1942         `post-content`.`object` AS `object`,
1943         `post-content`.`target-type` AS `target-type`,
1944         `post-content`.`target` AS `target`,
1945         `post-content`.`resource-id` AS `resource-id`,
1946         `post`.`author-id` AS `contact-id`,
1947         `author`.`url` AS `contact-link`,
1948         `author`.`addr` AS `contact-addr`,
1949         `author`.`name` AS `contact-name`,
1950         `author`.`nick` AS `contact-nick`,
1951         `author`.`thumb` AS `contact-avatar`,
1952         `author`.`network` AS `contact-network`,
1953         `author`.`blocked` AS `contact-blocked`,
1954         `author`.`hidden` AS `contact-hidden`,
1955         `author`.`readonly` AS `contact-readonly`,
1956         `author`.`archive` AS `contact-archive`,
1957         `author`.`pending` AS `contact-pending`,
1958         `author`.`rel` AS `contact-rel`,
1959         `author`.`uid` AS `contact-uid`,
1960         `author`.`contact-type` AS `contact-contact-type`,
1961         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
1962         false AS `self`,
1963         `author`.`id` AS `cid`,
1964         `author`.`alias` AS `alias`,
1965         `author`.`photo` AS `photo`,
1966         `author`.`name-date` AS `name-date`,
1967         `author`.`uri-date` AS `uri-date`,
1968         `author`.`avatar-date` AS `avatar-date`,
1969         `author`.`thumb` AS `thumb`,
1970         `author`.`dfrn-id` AS `dfrn-id`,
1971         `post`.`author-id` AS `author-id`,
1972         `author`.`url` AS `author-link`,
1973         `author`.`addr` AS `author-addr`,
1974         `author`.`name` AS `author-name`,
1975         `author`.`nick` AS `author-nick`,
1976         `author`.`thumb` AS `author-avatar`,
1977         `author`.`network` AS `author-network`,
1978         `author`.`blocked` AS `author-blocked`,
1979         `author`.`hidden` AS `author-hidden`,
1980         `post`.`owner-id` AS `owner-id`,
1981         `owner`.`url` AS `owner-link`,
1982         `owner`.`addr` AS `owner-addr`,
1983         `owner`.`name` AS `owner-name`,
1984         `owner`.`nick` AS `owner-nick`,
1985         `owner`.`thumb` AS `owner-avatar`,
1986         `owner`.`network` AS `owner-network`,
1987         `owner`.`blocked` AS `owner-blocked`,
1988         `owner`.`hidden` AS `owner-hidden`,
1989         `owner`.`contact-type` AS `owner-contact-type`,
1990         `post`.`causer-id` AS `causer-id`,
1991         `causer`.`url` AS `causer-link`,
1992         `causer`.`addr` AS `causer-addr`,
1993         `causer`.`name` AS `causer-name`,
1994         `causer`.`nick` AS `causer-nick`,
1995         `causer`.`thumb` AS `causer-avatar`,
1996         `causer`.`network` AS `causer-network`,
1997         `causer`.`blocked` AS `causer-blocked`,
1998         `causer`.`hidden` AS `causer-hidden`,
1999         `causer`.`contact-type` AS `causer-contact-type`,
2000         `diaspora-interaction`.`interaction` AS `signed_text`,
2001         `parent-item-uri`.`guid` AS `parent-guid`,
2002         `parent-post`.`network` AS `parent-network`,
2003         `parent-post`.`author-id` AS `parent-author-id`,
2004         `parent-post-author`.`url` AS `parent-author-link`,
2005         `parent-post-author`.`name` AS `parent-author-name`,
2006         `parent-post-author`.`network` AS `parent-author-network`,
2007         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2008         `parent-post-author`.`hidden` AS `parent-author-hidden`
2009         FROM `post`
2010                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2011                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2012                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2013                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2014                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2015                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2016                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2017                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2018                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2019                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2020                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2021                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2022                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2023
2024 --
2025 -- VIEW post-thread-view
2026 --
2027 DROP VIEW IF EXISTS `post-thread-view`;
2028 CREATE VIEW `post-thread-view` AS SELECT 
2029         `item-uri`.`uri` AS `uri`,
2030         `post-thread`.`uri-id` AS `uri-id`,
2031         `parent-item-uri`.`uri` AS `parent-uri`,
2032         `post`.`parent-uri-id` AS `parent-uri-id`,
2033         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2034         `post`.`thr-parent-id` AS `thr-parent-id`,
2035         `item-uri`.`guid` AS `guid`,
2036         `post`.`gravity` AS `gravity`,
2037         `external-item-uri`.`uri` AS `extid`,
2038         `post`.`external-id` AS `external-id`,
2039         `post-thread`.`created` AS `created`,
2040         `post`.`edited` AS `edited`,
2041         `post-thread`.`commented` AS `commented`,
2042         `post-thread`.`received` AS `received`,
2043         `post-thread`.`changed` AS `changed`,
2044         `post`.`post-type` AS `post-type`,
2045         `post`.`private` AS `private`,
2046         `post`.`visible` AS `visible`,
2047         `post`.`deleted` AS `deleted`,
2048         `post`.`global` AS `global`,
2049         `post-thread`.`network` AS `network`,
2050         `post`.`vid` AS `vid`,
2051         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2052         `post-content`.`title` AS `title`,
2053         `post-content`.`content-warning` AS `content-warning`,
2054         `post-content`.`raw-body` AS `raw-body`,
2055         `post-content`.`body` AS `body`,
2056         `post-content`.`rendered-hash` AS `rendered-hash`,
2057         `post-content`.`rendered-html` AS `rendered-html`,
2058         `post-content`.`language` AS `language`,
2059         `post-content`.`plink` AS `plink`,
2060         `post-content`.`location` AS `location`,
2061         `post-content`.`coord` AS `coord`,
2062         `post-content`.`app` AS `app`,
2063         `post-content`.`object-type` AS `object-type`,
2064         `post-content`.`object` AS `object`,
2065         `post-content`.`target-type` AS `target-type`,
2066         `post-content`.`target` AS `target`,
2067         `post-content`.`resource-id` AS `resource-id`,
2068         `post-thread`.`author-id` AS `contact-id`,
2069         `author`.`url` AS `contact-link`,
2070         `author`.`addr` AS `contact-addr`,
2071         `author`.`name` AS `contact-name`,
2072         `author`.`nick` AS `contact-nick`,
2073         `author`.`thumb` AS `contact-avatar`,
2074         `author`.`network` AS `contact-network`,
2075         `author`.`blocked` AS `contact-blocked`,
2076         `author`.`hidden` AS `contact-hidden`,
2077         `author`.`readonly` AS `contact-readonly`,
2078         `author`.`archive` AS `contact-archive`,
2079         `author`.`pending` AS `contact-pending`,
2080         `author`.`rel` AS `contact-rel`,
2081         `author`.`uid` AS `contact-uid`,
2082         `author`.`contact-type` AS `contact-contact-type`,
2083         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2084         false AS `self`,
2085         `author`.`id` AS `cid`,
2086         `author`.`alias` AS `alias`,
2087         `author`.`photo` AS `photo`,
2088         `author`.`name-date` AS `name-date`,
2089         `author`.`uri-date` AS `uri-date`,
2090         `author`.`avatar-date` AS `avatar-date`,
2091         `author`.`thumb` AS `thumb`,
2092         `author`.`dfrn-id` AS `dfrn-id`,
2093         `post-thread`.`author-id` AS `author-id`,
2094         `author`.`url` AS `author-link`,
2095         `author`.`addr` AS `author-addr`,
2096         `author`.`name` AS `author-name`,
2097         `author`.`nick` AS `author-nick`,
2098         `author`.`thumb` AS `author-avatar`,
2099         `author`.`network` AS `author-network`,
2100         `author`.`blocked` AS `author-blocked`,
2101         `author`.`hidden` AS `author-hidden`,
2102         `post-thread`.`owner-id` AS `owner-id`,
2103         `owner`.`url` AS `owner-link`,
2104         `owner`.`addr` AS `owner-addr`,
2105         `owner`.`name` AS `owner-name`,
2106         `owner`.`nick` AS `owner-nick`,
2107         `owner`.`thumb` AS `owner-avatar`,
2108         `owner`.`network` AS `owner-network`,
2109         `owner`.`blocked` AS `owner-blocked`,
2110         `owner`.`hidden` AS `owner-hidden`,
2111         `owner`.`contact-type` AS `owner-contact-type`,
2112         `post-thread`.`causer-id` AS `causer-id`,
2113         `causer`.`url` AS `causer-link`,
2114         `causer`.`addr` AS `causer-addr`,
2115         `causer`.`name` AS `causer-name`,
2116         `causer`.`nick` AS `causer-nick`,
2117         `causer`.`thumb` AS `causer-avatar`,
2118         `causer`.`network` AS `causer-network`,
2119         `causer`.`blocked` AS `causer-blocked`,
2120         `causer`.`hidden` AS `causer-hidden`,
2121         `causer`.`contact-type` AS `causer-contact-type`,
2122         `diaspora-interaction`.`interaction` AS `signed_text`,
2123         `parent-item-uri`.`guid` AS `parent-guid`,
2124         `parent-post`.`network` AS `parent-network`,
2125         `parent-post`.`author-id` AS `parent-author-id`,
2126         `parent-post-author`.`url` AS `parent-author-link`,
2127         `parent-post-author`.`name` AS `parent-author-name`,
2128         `parent-post-author`.`network` AS `parent-author-network`,
2129         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2130         `parent-post-author`.`hidden` AS `parent-author-hidden`
2131         FROM `post-thread`
2132                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2133                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2134                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2135                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2136                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2137                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2138                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2139                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2140                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2141                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2142                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2143                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2144                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2145
2146 --
2147 -- VIEW category-view
2148 --
2149 DROP VIEW IF EXISTS `category-view`;
2150 CREATE VIEW `category-view` AS SELECT 
2151         `post-category`.`uri-id` AS `uri-id`,
2152         `post-category`.`uid` AS `uid`,
2153         `post-category`.`type` AS `type`,
2154         `post-category`.`tid` AS `tid`,
2155         `tag`.`name` AS `name`,
2156         `tag`.`url` AS `url`
2157         FROM `post-category`
2158                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2159
2160 --
2161 -- VIEW tag-view
2162 --
2163 DROP VIEW IF EXISTS `tag-view`;
2164 CREATE VIEW `tag-view` AS SELECT 
2165         `post-tag`.`uri-id` AS `uri-id`,
2166         `post-tag`.`type` AS `type`,
2167         `post-tag`.`tid` AS `tid`,
2168         `post-tag`.`cid` AS `cid`,
2169         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2170         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
2171         FROM `post-tag`
2172                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2173                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2174
2175 --
2176 -- VIEW network-item-view
2177 --
2178 DROP VIEW IF EXISTS `network-item-view`;
2179 CREATE VIEW `network-item-view` AS SELECT 
2180         `post-user`.`uri-id` AS `uri-id`,
2181         `parent-post`.`id` AS `parent`,
2182         `post-user`.`received` AS `received`,
2183         `post-thread-user`.`commented` AS `commented`,
2184         `post-user`.`created` AS `created`,
2185         `post-user`.`uid` AS `uid`,
2186         `post-thread-user`.`starred` AS `starred`,
2187         `post-thread-user`.`mention` AS `mention`,
2188         `post-user`.`network` AS `network`,
2189         `post-user`.`unseen` AS `unseen`,
2190         `post-user`.`gravity` AS `gravity`,
2191         `post-user`.`contact-id` AS `contact-id`,
2192         `ownercontact`.`contact-type` AS `contact-type`
2193         FROM `post-user`
2194                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2195                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2196                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2197                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2198                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2199                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2200                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2201                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2202                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2203                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2204                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2205
2206 --
2207 -- VIEW network-thread-view
2208 --
2209 DROP VIEW IF EXISTS `network-thread-view`;
2210 CREATE VIEW `network-thread-view` AS SELECT 
2211         `post-thread-user`.`uri-id` AS `uri-id`,
2212         `parent-post`.`id` AS `parent`,
2213         `post-thread-user`.`received` AS `received`,
2214         `post-thread-user`.`commented` AS `commented`,
2215         `post-thread-user`.`created` AS `created`,
2216         `post-thread-user`.`uid` AS `uid`,
2217         `post-thread-user`.`starred` AS `starred`,
2218         `post-thread-user`.`mention` AS `mention`,
2219         `post-thread-user`.`network` AS `network`,
2220         `post-thread-user`.`contact-id` AS `contact-id`,
2221         `ownercontact`.`contact-type` AS `contact-type`
2222         FROM `post-thread-user`
2223                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2224                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2225                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2226                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2227                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2228                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2229                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2230                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2231                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2232                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2233                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2234
2235 --
2236 -- VIEW owner-view
2237 --
2238 DROP VIEW IF EXISTS `owner-view`;
2239 CREATE VIEW `owner-view` AS SELECT 
2240         `contact`.`id` AS `id`,
2241         `contact`.`uid` AS `uid`,
2242         `contact`.`created` AS `created`,
2243         `contact`.`updated` AS `updated`,
2244         `contact`.`self` AS `self`,
2245         `contact`.`remote_self` AS `remote_self`,
2246         `contact`.`rel` AS `rel`,
2247         `contact`.`duplex` AS `duplex`,
2248         `contact`.`network` AS `network`,
2249         `contact`.`protocol` AS `protocol`,
2250         `contact`.`name` AS `name`,
2251         `contact`.`nick` AS `nick`,
2252         `contact`.`location` AS `location`,
2253         `contact`.`about` AS `about`,
2254         `contact`.`keywords` AS `keywords`,
2255         `contact`.`gender` AS `gender`,
2256         `contact`.`xmpp` AS `xmpp`,
2257         `contact`.`attag` AS `attag`,
2258         `contact`.`avatar` AS `avatar`,
2259         `contact`.`photo` AS `photo`,
2260         `contact`.`thumb` AS `thumb`,
2261         `contact`.`micro` AS `micro`,
2262         `contact`.`header` AS `header`,
2263         `contact`.`site-pubkey` AS `site-pubkey`,
2264         `contact`.`issued-id` AS `issued-id`,
2265         `contact`.`dfrn-id` AS `dfrn-id`,
2266         `contact`.`url` AS `url`,
2267         `contact`.`nurl` AS `nurl`,
2268         `contact`.`addr` AS `addr`,
2269         `contact`.`alias` AS `alias`,
2270         `contact`.`pubkey` AS `pubkey`,
2271         `contact`.`prvkey` AS `prvkey`,
2272         `contact`.`batch` AS `batch`,
2273         `contact`.`request` AS `request`,
2274         `contact`.`notify` AS `notify`,
2275         `contact`.`poll` AS `poll`,
2276         `contact`.`confirm` AS `confirm`,
2277         `contact`.`poco` AS `poco`,
2278         `contact`.`aes_allow` AS `aes_allow`,
2279         `contact`.`ret-aes` AS `ret-aes`,
2280         `contact`.`usehub` AS `usehub`,
2281         `contact`.`subhub` AS `subhub`,
2282         `contact`.`hub-verify` AS `hub-verify`,
2283         `contact`.`last-update` AS `last-update`,
2284         `contact`.`success_update` AS `success_update`,
2285         `contact`.`failure_update` AS `failure_update`,
2286         `contact`.`name-date` AS `name-date`,
2287         `contact`.`uri-date` AS `uri-date`,
2288         `contact`.`avatar-date` AS `avatar-date`,
2289         `contact`.`avatar-date` AS `picdate`,
2290         `contact`.`term-date` AS `term-date`,
2291         `contact`.`last-item` AS `last-item`,
2292         `contact`.`priority` AS `priority`,
2293         `user`.`blocked` AS `blocked`,
2294         `contact`.`block_reason` AS `block_reason`,
2295         `contact`.`readonly` AS `readonly`,
2296         `contact`.`writable` AS `writable`,
2297         `contact`.`forum` AS `forum`,
2298         `contact`.`prv` AS `prv`,
2299         `contact`.`contact-type` AS `contact-type`,
2300         `contact`.`manually-approve` AS `manually-approve`,
2301         `contact`.`hidden` AS `hidden`,
2302         `contact`.`archive` AS `archive`,
2303         `contact`.`pending` AS `pending`,
2304         `contact`.`deleted` AS `deleted`,
2305         `contact`.`unsearchable` AS `unsearchable`,
2306         `contact`.`sensitive` AS `sensitive`,
2307         `contact`.`baseurl` AS `baseurl`,
2308         `contact`.`reason` AS `reason`,
2309         `contact`.`closeness` AS `closeness`,
2310         `contact`.`info` AS `info`,
2311         `contact`.`profile-id` AS `profile-id`,
2312         `contact`.`bdyear` AS `bdyear`,
2313         `contact`.`bd` AS `bd`,
2314         `contact`.`notify_new_posts` AS `notify_new_posts`,
2315         `contact`.`fetch_further_information` AS `fetch_further_information`,
2316         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2317         `user`.`parent-uid` AS `parent-uid`,
2318         `user`.`guid` AS `guid`,
2319         `user`.`nickname` AS `nickname`,
2320         `user`.`email` AS `email`,
2321         `user`.`openid` AS `openid`,
2322         `user`.`timezone` AS `timezone`,
2323         `user`.`language` AS `language`,
2324         `user`.`register_date` AS `register_date`,
2325         `user`.`login_date` AS `login_date`,
2326         `user`.`default-location` AS `default-location`,
2327         `user`.`allow_location` AS `allow_location`,
2328         `user`.`theme` AS `theme`,
2329         `user`.`pubkey` AS `upubkey`,
2330         `user`.`prvkey` AS `uprvkey`,
2331         `user`.`sprvkey` AS `sprvkey`,
2332         `user`.`spubkey` AS `spubkey`,
2333         `user`.`verified` AS `verified`,
2334         `user`.`blockwall` AS `blockwall`,
2335         `user`.`hidewall` AS `hidewall`,
2336         `user`.`blocktags` AS `blocktags`,
2337         `user`.`unkmail` AS `unkmail`,
2338         `user`.`cntunkmail` AS `cntunkmail`,
2339         `user`.`notify-flags` AS `notify-flags`,
2340         `user`.`page-flags` AS `page-flags`,
2341         `user`.`account-type` AS `account-type`,
2342         `user`.`prvnets` AS `prvnets`,
2343         `user`.`maxreq` AS `maxreq`,
2344         `user`.`expire` AS `expire`,
2345         `user`.`account_removed` AS `account_removed`,
2346         `user`.`account_expired` AS `account_expired`,
2347         `user`.`account_expires_on` AS `account_expires_on`,
2348         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2349         `user`.`def_gid` AS `def_gid`,
2350         `user`.`allow_cid` AS `allow_cid`,
2351         `user`.`allow_gid` AS `allow_gid`,
2352         `user`.`deny_cid` AS `deny_cid`,
2353         `user`.`deny_gid` AS `deny_gid`,
2354         `user`.`openidserver` AS `openidserver`,
2355         `profile`.`publish` AS `publish`,
2356         `profile`.`net-publish` AS `net-publish`,
2357         `profile`.`hide-friends` AS `hide-friends`,
2358         `profile`.`prv_keywords` AS `prv_keywords`,
2359         `profile`.`pub_keywords` AS `pub_keywords`,
2360         `profile`.`address` AS `address`,
2361         `profile`.`locality` AS `locality`,
2362         `profile`.`region` AS `region`,
2363         `profile`.`postal-code` AS `postal-code`,
2364         `profile`.`country-name` AS `country-name`,
2365         `profile`.`homepage` AS `homepage`,
2366         `profile`.`dob` AS `dob`
2367         FROM `user`
2368                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2369                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2370
2371 --
2372 -- VIEW pending-view
2373 --
2374 DROP VIEW IF EXISTS `pending-view`;
2375 CREATE VIEW `pending-view` AS SELECT 
2376         `register`.`id` AS `id`,
2377         `register`.`hash` AS `hash`,
2378         `register`.`created` AS `created`,
2379         `register`.`uid` AS `uid`,
2380         `register`.`password` AS `password`,
2381         `register`.`language` AS `language`,
2382         `register`.`note` AS `note`,
2383         `contact`.`self` AS `self`,
2384         `contact`.`name` AS `name`,
2385         `contact`.`url` AS `url`,
2386         `contact`.`micro` AS `micro`,
2387         `user`.`email` AS `email`,
2388         `contact`.`nick` AS `nick`
2389         FROM `register`
2390                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2391                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2392
2393 --
2394 -- VIEW tag-search-view
2395 --
2396 DROP VIEW IF EXISTS `tag-search-view`;
2397 CREATE VIEW `tag-search-view` AS SELECT 
2398         `post-tag`.`uri-id` AS `uri-id`,
2399         `post-user`.`uid` AS `uid`,
2400         `post-user`.`id` AS `iid`,
2401         `post-user`.`private` AS `private`,
2402         `post-user`.`wall` AS `wall`,
2403         `post-user`.`origin` AS `origin`,
2404         `post-user`.`global` AS `global`,
2405         `post-user`.`gravity` AS `gravity`,
2406         `post-user`.`received` AS `received`,
2407         `post-user`.`network` AS `network`,
2408         `post-user`.`author-id` AS `author-id`,
2409         `tag`.`name` AS `name`
2410         FROM `post-tag`
2411                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2412                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2413                         WHERE `post-tag`.`type` = 1;
2414
2415 --
2416 -- VIEW workerqueue-view
2417 --
2418 DROP VIEW IF EXISTS `workerqueue-view`;
2419 CREATE VIEW `workerqueue-view` AS SELECT 
2420         `process`.`pid` AS `pid`,
2421         `workerqueue`.`priority` AS `priority`
2422         FROM `process`
2423                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2424                         WHERE NOT `workerqueue`.`done`;