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