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