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