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