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