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