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