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