]> git.mxchange.org Git - friendica.git/blob - database.sql
Some more foreign keys added
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2020.12-dev (Red Hot Poker)
3 -- DB_UPDATE_VERSION 1377
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 user
38 --
39 CREATE TABLE IF NOT EXISTS `user` (
40         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
41         `parent-uid` mediumint unsigned COMMENT 'The parent user that has full control about this user',
42         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
43         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
44         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
45         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
46         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
47         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
48         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
49         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
50         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
51         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
52         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
53         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
54         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
55         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
56         `pubkey` text COMMENT 'RSA public key 4096 bit',
57         `prvkey` text COMMENT 'RSA private key 4096 bit',
58         `spubkey` text COMMENT '',
59         `sprvkey` text COMMENT '',
60         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
61         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
62         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
63         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
64         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
65         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
66         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
67         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
68         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
69         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
70         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
71         `pwdreset` varchar(255) COMMENT 'Password reset request token',
72         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
73         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
74         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
75         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
76         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
77         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
78         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
79         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
80         `allow_cid` mediumtext COMMENT 'default permission for this user',
81         `allow_gid` mediumtext COMMENT 'default permission for this user',
82         `deny_cid` mediumtext COMMENT 'default permission for this user',
83         `deny_gid` mediumtext COMMENT 'default permission for this user',
84         `openidserver` text COMMENT '',
85          PRIMARY KEY(`uid`),
86          INDEX `nickname` (`nickname`(32)),
87          INDEX `parent-uid` (`parent-uid`),
88         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
89 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
90
91 --
92 -- TABLE contact
93 --
94 CREATE TABLE IF NOT EXISTS `contact` (
95         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
96         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
97         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
98         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
99         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
100         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
101         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
102         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
103         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
104         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
105         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
106         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
107         `location` varchar(255) DEFAULT '' COMMENT '',
108         `about` text COMMENT '',
109         `keywords` text COMMENT 'public keywords (interests) of the contact',
110         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
111         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
112         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
113         `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '',
114         `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
115         `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
116         `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
117         `site-pubkey` text COMMENT '',
118         `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
119         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
120         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
121         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
122         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
123         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
124         `pubkey` text COMMENT 'RSA public key 4096 bit',
125         `prvkey` text COMMENT 'RSA private key 4096 bit',
126         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
127         `request` varchar(255) COMMENT '',
128         `notify` varchar(255) COMMENT '',
129         `poll` varchar(255) COMMENT '',
130         `confirm` varchar(255) COMMENT '',
131         `subscribe` varchar(255) COMMENT '',
132         `poco` varchar(255) COMMENT '',
133         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT '',
134         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT '',
135         `usehub` boolean NOT NULL DEFAULT '0' COMMENT '',
136         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
137         `hub-verify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
138         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
139         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
140         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
141         `failed` boolean COMMENT 'Connection failed',
142         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
143         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
144         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
145         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
146         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
147         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
148         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
149         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
150         `block_reason` text COMMENT 'Node-wide block reason',
151         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
152         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
153         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum',
154         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group',
155         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT '',
156         `manually-approve` boolean COMMENT '',
157         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
158         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
159         `pending` boolean NOT NULL DEFAULT '1' COMMENT '',
160         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
161         `rating` tinyint NOT NULL DEFAULT 0 COMMENT '',
162         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
163         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
164         `baseurl` varchar(255) DEFAULT '' COMMENT 'baseurl of the contact',
165         `gsid` int unsigned COMMENT 'Global Server ID',
166         `reason` text COMMENT '',
167         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT '',
168         `info` mediumtext COMMENT '',
169         `profile-id` int unsigned COMMENT 'Deprecated',
170         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
171         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
172         `notify_new_posts` boolean NOT NULL DEFAULT '0' COMMENT '',
173         `fetch_further_information` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
174         `ffi_keyword_denylist` text COMMENT '',
175          PRIMARY KEY(`id`),
176          INDEX `uid_name` (`uid`,`name`(190)),
177          INDEX `self_uid` (`self`,`uid`),
178          INDEX `alias_uid` (`alias`(96),`uid`),
179          INDEX `pending_uid` (`pending`,`uid`),
180          INDEX `blocked_uid` (`blocked`,`uid`),
181          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
182          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
183          INDEX `addr_uid` (`addr`(96),`uid`),
184          INDEX `nurl_uid` (`nurl`(96),`uid`),
185          INDEX `nick_uid` (`nick`(32),`uid`),
186          INDEX `attag_uid` (`attag`(96),`uid`),
187          INDEX `dfrn-id` (`dfrn-id`(64)),
188          INDEX `issued-id` (`issued-id`(64)),
189          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
190          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
191          INDEX `uid_lastitem` (`uid`,`last-item`),
192          INDEX `gsid` (`gsid`),
193         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
194         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
195 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
196
197 --
198 -- TABLE item-uri
199 --
200 CREATE TABLE IF NOT EXISTS `item-uri` (
201         `id` int unsigned NOT NULL auto_increment,
202         `uri` varbinary(255) NOT NULL COMMENT 'URI of an item',
203         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
204          PRIMARY KEY(`id`),
205          UNIQUE INDEX `uri` (`uri`),
206          INDEX `guid` (`guid`)
207 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
208
209 --
210 -- TABLE tag
211 --
212 CREATE TABLE IF NOT EXISTS `tag` (
213         `id` int unsigned NOT NULL auto_increment COMMENT '',
214         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
215         `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
216          PRIMARY KEY(`id`),
217          UNIQUE INDEX `type_name_url` (`name`,`url`),
218          INDEX `url` (`url`)
219 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
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 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 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         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
665         `extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
666         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
667         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
668         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
669         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
670         `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
671         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
672         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
673         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
674         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
675         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
676         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
677         `starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
678         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
679         `mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
680         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
681         `psid` int unsigned COMMENT 'ID of the permission set of this post',
682         `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',
683         `event-id` int unsigned COMMENT 'Used to link to the event.id',
684         `iaid` int unsigned COMMENT 'Deprecated',
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 `vid` (`vid`),
745          INDEX `psid_wall` (`psid`,`wall`),
746          INDEX `uri-id` (`uri-id`),
747          INDEX `parent-uri-id` (`parent-uri-id`),
748          INDEX `thr-parent-id` (`thr-parent-id`),
749          INDEX `causer-id` (`causer-id`),
750         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
751         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
752         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
753         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
754         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
755         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
756         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
757         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
758         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
759         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
760 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
761
762 --
763 -- TABLE item-activity
764 --
765 CREATE TABLE IF NOT EXISTS `item-activity` (
766         `id` int unsigned NOT NULL auto_increment,
767         `uri` varchar(255) COMMENT '',
768         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
769         `uri-hash` varchar(80) NOT NULL DEFAULT '' COMMENT 'RIPEMD-128 hash from uri',
770         `activity` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
771          PRIMARY KEY(`id`),
772          UNIQUE INDEX `uri-hash` (`uri-hash`),
773          INDEX `uri` (`uri`(191)),
774          INDEX `uri-id` (`uri-id`),
775         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
776 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activities for items';
777
778 --
779 -- TABLE item-content
780 --
781 CREATE TABLE IF NOT EXISTS `item-content` (
782         `id` int unsigned NOT NULL auto_increment,
783         `uri` varchar(255) COMMENT '',
784         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
785         `uri-plink-hash` varchar(80) NOT NULL DEFAULT '' COMMENT 'RIPEMD-128 hash from uri',
786         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
787         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
788         `body` mediumtext COMMENT 'item body content',
789         `raw-body` mediumtext COMMENT 'Body without embedded media links',
790         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
791         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
792         `language` text COMMENT 'Language information about this post',
793         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
794         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
795         `rendered-html` mediumtext COMMENT 'item.body converted to html',
796         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
797         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
798         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
799         `target` text COMMENT 'JSON encoded target structure if used',
800         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
801         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams verb',
802          PRIMARY KEY(`id`),
803          UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`),
804          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
805          INDEX `uri` (`uri`(191)),
806          INDEX `plink` (`plink`(191)),
807          INDEX `uri-id` (`uri-id`),
808         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
809 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
810
811 --
812 -- TABLE locks
813 --
814 CREATE TABLE IF NOT EXISTS `locks` (
815         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
816         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
817         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
818         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
819         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
820          PRIMARY KEY(`id`),
821          INDEX `name_expires` (`name`,`expires`)
822 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
823
824 --
825 -- TABLE mail
826 --
827 CREATE TABLE IF NOT EXISTS `mail` (
828         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
829         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
830         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
831         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
832         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
833         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
834         `contact-id` varchar(255) COMMENT 'contact.id',
835         `convid` int unsigned COMMENT 'conv.id',
836         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
837         `body` mediumtext COMMENT '',
838         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
839         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
840         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
841         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
842         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
843         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
844         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
845          PRIMARY KEY(`id`),
846          INDEX `uid_seen` (`uid`,`seen`),
847          INDEX `convid` (`convid`),
848          INDEX `uri` (`uri`(64)),
849          INDEX `parent-uri` (`parent-uri`(64)),
850          INDEX `contactid` (`contact-id`(32)),
851         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
852 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
853
854 --
855 -- TABLE mailacct
856 --
857 CREATE TABLE IF NOT EXISTS `mailacct` (
858         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
859         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
860         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
861         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
862         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
863         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
864         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
865         `pass` text COMMENT '',
866         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
867         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
868         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
869         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
870         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
871          PRIMARY KEY(`id`),
872          INDEX `uid` (`uid`),
873         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
874 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
875
876 --
877 -- TABLE manage
878 --
879 CREATE TABLE IF NOT EXISTS `manage` (
880         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
881         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
882         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
883          PRIMARY KEY(`id`),
884          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
885          INDEX `mid` (`mid`),
886         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
887         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
888 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
889
890 --
891 -- TABLE notify
892 --
893 CREATE TABLE IF NOT EXISTS `notify` (
894         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
895         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
896         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
897         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
898         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
899         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
900         `msg` mediumtext COMMENT '',
901         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
902         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
903         `iid` int unsigned COMMENT 'item.id',
904         `parent` int unsigned COMMENT '',
905         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
906         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
907         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
908         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
909         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
910         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
911         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
912          PRIMARY KEY(`id`),
913          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
914          INDEX `uid_date` (`uid`,`date`),
915          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
916          INDEX `uri-id` (`uri-id`),
917          INDEX `parent-uri-id` (`parent-uri-id`),
918         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
919         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
920         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
921 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
922
923 --
924 -- TABLE notify-threads
925 --
926 CREATE TABLE IF NOT EXISTS `notify-threads` (
927         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
928         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
929         `master-parent-item` int unsigned COMMENT '',
930         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
931         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
932         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
933          PRIMARY KEY(`id`),
934          INDEX `master-parent-item` (`master-parent-item`),
935          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
936          INDEX `receiver-uid` (`receiver-uid`),
937          INDEX `notify-id` (`notify-id`),
938         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
939         FOREIGN KEY (`master-parent-item`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
940         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
941         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
942 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
943
944 --
945 -- TABLE oembed
946 --
947 CREATE TABLE IF NOT EXISTS `oembed` (
948         `url` varbinary(255) NOT NULL COMMENT 'page url',
949         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
950         `content` mediumtext COMMENT 'OEmbed data of the page',
951         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
952          PRIMARY KEY(`url`,`maxwidth`),
953          INDEX `created` (`created`)
954 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
955
956 --
957 -- TABLE openwebauth-token
958 --
959 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
960         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
961         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
962         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
963         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
964         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
965         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
966          PRIMARY KEY(`id`),
967          INDEX `uid` (`uid`),
968         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
969 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
970
971 --
972 -- TABLE parsed_url
973 --
974 CREATE TABLE IF NOT EXISTS `parsed_url` (
975         `url` varbinary(255) NOT NULL COMMENT 'page url',
976         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
977         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
978         `content` mediumtext COMMENT 'page data',
979         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
980          PRIMARY KEY(`url`,`guessing`,`oembed`),
981          INDEX `created` (`created`)
982 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
983
984 --
985 -- TABLE participation
986 --
987 CREATE TABLE IF NOT EXISTS `participation` (
988         `iid` int unsigned NOT NULL COMMENT '',
989         `server` varchar(60) NOT NULL COMMENT '',
990         `cid` int unsigned NOT NULL COMMENT '',
991         `fid` int unsigned NOT NULL COMMENT '',
992          PRIMARY KEY(`iid`,`server`),
993          INDEX `cid` (`cid`),
994          INDEX `fid` (`fid`),
995         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
996         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
997         FOREIGN KEY (`fid`) REFERENCES `fcontact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
998 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Storage for participation messages from Diaspora';
999
1000 --
1001 -- TABLE pconfig
1002 --
1003 CREATE TABLE IF NOT EXISTS `pconfig` (
1004         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
1005         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1006         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
1007         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
1008         `v` mediumtext COMMENT 'Value',
1009          PRIMARY KEY(`id`),
1010          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
1011         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1012 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
1013
1014 --
1015 -- TABLE photo
1016 --
1017 CREATE TABLE IF NOT EXISTS `photo` (
1018         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1019         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1020         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1021         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
1022         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
1023         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
1024         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
1025         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1026         `desc` text COMMENT '',
1027         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
1028         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1029         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
1030         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1031         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1032         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1033         `data` mediumblob NOT NULL COMMENT '',
1034         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1035         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
1036         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
1037         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
1038         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
1039         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
1040         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
1041         `backend-class` tinytext COMMENT 'Storage backend class',
1042         `backend-ref` text COMMENT 'Storage backend data reference',
1043         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1044          PRIMARY KEY(`id`),
1045          INDEX `contactid` (`contact-id`),
1046          INDEX `uid_contactid` (`uid`,`contact-id`),
1047          INDEX `uid_profile` (`uid`,`profile`),
1048          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
1049          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
1050          INDEX `resource-id` (`resource-id`),
1051         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1052         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1053 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1054
1055 --
1056 -- TABLE post-category
1057 --
1058 CREATE TABLE IF NOT EXISTS `post-category` (
1059         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1060         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1061         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1062         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1063          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1064          INDEX `uri-id` (`tid`),
1065          INDEX `uid` (`uid`),
1066         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1067         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1068         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1069 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1070
1071 --
1072 -- TABLE post-delivery-data
1073 --
1074 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1075         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1076         `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',
1077         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1078         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1079         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1080         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1081         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1082         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1083         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1084         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1085         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1086          PRIMARY KEY(`uri-id`),
1087         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1088 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1089
1090 --
1091 -- TABLE post-media
1092 --
1093 CREATE TABLE IF NOT EXISTS `post-media` (
1094         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1095         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1096         `url` varbinary(511) NOT NULL COMMENT 'Media URL',
1097         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1098         `mimetype` varchar(60) COMMENT '',
1099         `height` smallint unsigned COMMENT 'Height of the media',
1100         `width` smallint unsigned COMMENT 'Width of the media',
1101         `size` int unsigned COMMENT 'Media size',
1102         `preview` varbinary(255) COMMENT 'Preview URL',
1103         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1104         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1105         `description` text COMMENT '',
1106          PRIMARY KEY(`id`),
1107          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1108         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1109 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1110
1111 --
1112 -- TABLE post-tag
1113 --
1114 CREATE TABLE IF NOT EXISTS `post-tag` (
1115         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1116         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1117         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1118         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1119          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1120          INDEX `tid` (`tid`),
1121          INDEX `cid` (`cid`),
1122         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1123         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1124         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1125 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1126
1127 --
1128 -- TABLE post-user
1129 --
1130 CREATE TABLE IF NOT EXISTS `post-user` (
1131         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1132         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1133         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1134         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1135         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1136         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1137         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1138         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1139          PRIMARY KEY(`uid`,`uri-id`),
1140          INDEX `uri-id` (`uri-id`),
1141          INDEX `contact-id` (`contact-id`),
1142          INDEX `psid` (`psid`),
1143         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1144         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1145         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1146         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1147 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1148
1149 --
1150 -- TABLE process
1151 --
1152 CREATE TABLE IF NOT EXISTS `process` (
1153         `pid` int unsigned NOT NULL COMMENT '',
1154         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1155         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1156          PRIMARY KEY(`pid`),
1157          INDEX `command` (`command`)
1158 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1159
1160 --
1161 -- TABLE profile
1162 --
1163 CREATE TABLE IF NOT EXISTS `profile` (
1164         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1165         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1166         `profile-name` varchar(255) COMMENT 'Deprecated',
1167         `is-default` boolean COMMENT 'Deprecated',
1168         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1169         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1170         `pdesc` varchar(255) COMMENT 'Deprecated',
1171         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1172         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1173         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1174         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1175         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1176         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1177         `hometown` varchar(255) COMMENT 'Deprecated',
1178         `gender` varchar(32) COMMENT 'Deprecated',
1179         `marital` varchar(255) COMMENT 'Deprecated',
1180         `with` text COMMENT 'Deprecated',
1181         `howlong` datetime COMMENT 'Deprecated',
1182         `sexual` varchar(255) COMMENT 'Deprecated',
1183         `politic` varchar(255) COMMENT 'Deprecated',
1184         `religion` varchar(255) COMMENT 'Deprecated',
1185         `pub_keywords` text COMMENT '',
1186         `prv_keywords` text COMMENT '',
1187         `likes` text COMMENT 'Deprecated',
1188         `dislikes` text COMMENT 'Deprecated',
1189         `about` text COMMENT 'Profile description',
1190         `summary` varchar(255) COMMENT 'Deprecated',
1191         `music` text COMMENT 'Deprecated',
1192         `book` text COMMENT 'Deprecated',
1193         `tv` text COMMENT 'Deprecated',
1194         `film` text COMMENT 'Deprecated',
1195         `interest` text COMMENT 'Deprecated',
1196         `romance` text COMMENT 'Deprecated',
1197         `work` text COMMENT 'Deprecated',
1198         `education` text COMMENT 'Deprecated',
1199         `contact` text COMMENT 'Deprecated',
1200         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1201         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1202         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1203         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1204         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1205         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1206          PRIMARY KEY(`id`),
1207          INDEX `uid_is-default` (`uid`,`is-default`),
1208          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1209         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1210 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1211
1212 --
1213 -- TABLE profile_check
1214 --
1215 CREATE TABLE IF NOT EXISTS `profile_check` (
1216         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1217         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1218         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1219         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1220         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1221         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1222          PRIMARY KEY(`id`),
1223          INDEX `uid` (`uid`),
1224          INDEX `cid` (`cid`),
1225         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1226         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1227 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1228
1229 --
1230 -- TABLE profile_field
1231 --
1232 CREATE TABLE IF NOT EXISTS `profile_field` (
1233         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1234         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1235         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1236         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1237         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1238         `value` text COMMENT 'Value of the field',
1239         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1240         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1241          PRIMARY KEY(`id`),
1242          INDEX `uid` (`uid`),
1243          INDEX `order` (`order`),
1244          INDEX `psid` (`psid`),
1245         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1246         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1247 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1248
1249 --
1250 -- TABLE push_subscriber
1251 --
1252 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1253         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1254         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1255         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1256         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1257         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1258         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1259         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1260         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1261         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1262         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1263          PRIMARY KEY(`id`),
1264          INDEX `next_try` (`next_try`),
1265          INDEX `uid` (`uid`),
1266         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1267 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1268
1269 --
1270 -- TABLE register
1271 --
1272 CREATE TABLE IF NOT EXISTS `register` (
1273         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1274         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1275         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1276         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1277         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1278         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1279         `note` text 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='registrations requiring admin approval';
1284
1285 --
1286 -- TABLE search
1287 --
1288 CREATE TABLE IF NOT EXISTS `search` (
1289         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1290         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1291         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1292          PRIMARY KEY(`id`),
1293          INDEX `uid` (`uid`),
1294         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1295 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1296
1297 --
1298 -- TABLE session
1299 --
1300 CREATE TABLE IF NOT EXISTS `session` (
1301         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1302         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1303         `data` text COMMENT '',
1304         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1305          PRIMARY KEY(`id`),
1306          INDEX `sid` (`sid`(64)),
1307          INDEX `expire` (`expire`)
1308 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1309
1310 --
1311 -- TABLE storage
1312 --
1313 CREATE TABLE IF NOT EXISTS `storage` (
1314         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1315         `data` longblob NOT NULL COMMENT 'file data',
1316          PRIMARY KEY(`id`)
1317 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1318
1319 --
1320 -- TABLE thread
1321 --
1322 CREATE TABLE IF NOT EXISTS `thread` (
1323         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID',
1324         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
1325         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1326         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1327         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1328         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1329         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1330         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1331         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1332         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1333         `changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1334         `wall` boolean NOT NULL DEFAULT '0' COMMENT '',
1335         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1336         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1337         `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
1338         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1339         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1340         `ignored` boolean NOT NULL DEFAULT '0' COMMENT '',
1341         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
1342         `unseen` boolean NOT NULL DEFAULT '1' COMMENT '',
1343         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '',
1344         `origin` boolean NOT NULL DEFAULT '0' COMMENT '',
1345         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1346         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1347         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1348         `bookmark` boolean COMMENT '',
1349          PRIMARY KEY(`iid`),
1350          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
1351          INDEX `uid_network_received` (`uid`,`network`,`received`),
1352          INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
1353          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
1354          INDEX `contactid` (`contact-id`),
1355          INDEX `ownerid` (`owner-id`),
1356          INDEX `authorid` (`author-id`),
1357          INDEX `uid_received` (`uid`,`received`),
1358          INDEX `uid_commented` (`uid`,`commented`),
1359          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1360          INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`),
1361          INDEX `uri-id` (`uri-id`),
1362         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1363         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1364         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1365         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1366         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1367         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1368 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1369
1370 --
1371 -- TABLE tokens
1372 --
1373 CREATE TABLE IF NOT EXISTS `tokens` (
1374         `id` varchar(40) NOT NULL COMMENT '',
1375         `secret` text COMMENT '',
1376         `client_id` varchar(20) NOT NULL DEFAULT '',
1377         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1378         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1379         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1380          PRIMARY KEY(`id`),
1381          INDEX `client_id` (`client_id`),
1382          INDEX `uid` (`uid`),
1383         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1384         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1385 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1386
1387 --
1388 -- TABLE userd
1389 --
1390 CREATE TABLE IF NOT EXISTS `userd` (
1391         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1392         `username` varchar(255) NOT NULL COMMENT '',
1393          PRIMARY KEY(`id`),
1394          INDEX `username` (`username`(32))
1395 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1396
1397 --
1398 -- TABLE user-contact
1399 --
1400 CREATE TABLE IF NOT EXISTS `user-contact` (
1401         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1402         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1403         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1404         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1405         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1406          PRIMARY KEY(`uid`,`cid`),
1407          INDEX `cid` (`cid`),
1408         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1409         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1410 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1411
1412 --
1413 -- TABLE user-item
1414 --
1415 CREATE TABLE IF NOT EXISTS `user-item` (
1416         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item id',
1417         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1418         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
1419         `ignored` boolean COMMENT 'Ignore this thread if set',
1420         `pinned` boolean COMMENT 'The item is pinned on the profile page',
1421         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1422          PRIMARY KEY(`uid`,`iid`),
1423          INDEX `uid_pinned` (`uid`,`pinned`),
1424          INDEX `iid_uid` (`iid`,`uid`),
1425         FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1426         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1427 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
1428
1429 --
1430 -- TABLE verb
1431 --
1432 CREATE TABLE IF NOT EXISTS `verb` (
1433         `id` smallint unsigned NOT NULL auto_increment,
1434         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
1435          PRIMARY KEY(`id`)
1436 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
1437
1438 --
1439 -- TABLE worker-ipc
1440 --
1441 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1442         `key` int NOT NULL COMMENT '',
1443         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1444          PRIMARY KEY(`key`)
1445 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1446
1447 --
1448 -- TABLE workerqueue
1449 --
1450 CREATE TABLE IF NOT EXISTS `workerqueue` (
1451         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1452         `parameter` mediumtext COMMENT 'Task command',
1453         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1454         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1455         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1456         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1457         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1458         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1459         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1460          PRIMARY KEY(`id`),
1461          INDEX `done_parameter` (`done`,`parameter`(64)),
1462          INDEX `done_executed` (`done`,`executed`),
1463          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
1464          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1465          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1466          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1467          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1468 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1469
1470 --
1471 -- VIEW category-view
1472 --
1473 DROP VIEW IF EXISTS `category-view`;
1474 CREATE VIEW `category-view` AS SELECT 
1475         `post-category`.`uri-id` AS `uri-id`,
1476         `post-category`.`uid` AS `uid`,
1477         `item-uri`.`uri` AS `uri`,
1478         `item-uri`.`guid` AS `guid`,
1479         `post-category`.`type` AS `type`,
1480         `post-category`.`tid` AS `tid`,
1481         `tag`.`name` AS `name`,
1482         `tag`.`url` AS `url`
1483         FROM `post-category`
1484                         INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id`
1485                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
1486
1487 --
1488 -- VIEW tag-view
1489 --
1490 DROP VIEW IF EXISTS `tag-view`;
1491 CREATE VIEW `tag-view` AS SELECT 
1492         `post-tag`.`uri-id` AS `uri-id`,
1493         `item-uri`.`uri` AS `uri`,
1494         `item-uri`.`guid` AS `guid`,
1495         `post-tag`.`type` AS `type`,
1496         `post-tag`.`tid` AS `tid`,
1497         `post-tag`.`cid` AS `cid`,
1498         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
1499         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
1500         FROM `post-tag`
1501                         INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
1502                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
1503                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
1504
1505 --
1506 -- VIEW network-item-view
1507 --
1508 DROP VIEW IF EXISTS `network-item-view`;
1509 CREATE VIEW `network-item-view` AS SELECT 
1510         `item`.`parent-uri-id` AS `uri-id`,
1511         `item`.`parent-uri` AS `uri`,
1512         `item`.`parent` AS `parent`,
1513         `item`.`received` AS `received`,
1514         `item`.`commented` AS `commented`,
1515         `item`.`created` AS `created`,
1516         `item`.`uid` AS `uid`,
1517         `item`.`starred` AS `starred`,
1518         `item`.`mention` AS `mention`,
1519         `item`.`network` AS `network`,
1520         `item`.`unseen` AS `unseen`,
1521         `item`.`gravity` AS `gravity`,
1522         `item`.`contact-id` AS `contact-id`,
1523         `ownercontact`.`contact-type` AS `contact-type`
1524         FROM `item`
1525                         INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
1526                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
1527                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1528                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1529                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1530                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
1531                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1532                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1533                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1534                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1535                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1536
1537 --
1538 -- VIEW network-thread-view
1539 --
1540 DROP VIEW IF EXISTS `network-thread-view`;
1541 CREATE VIEW `network-thread-view` AS SELECT 
1542         `item`.`uri-id` AS `uri-id`,
1543         `item`.`uri` AS `uri`,
1544         `item`.`parent-uri-id` AS `parent-uri-id`,
1545         `thread`.`iid` AS `parent`,
1546         `thread`.`received` AS `received`,
1547         `thread`.`commented` AS `commented`,
1548         `thread`.`created` AS `created`,
1549         `thread`.`uid` AS `uid`,
1550         `thread`.`starred` AS `starred`,
1551         `thread`.`mention` AS `mention`,
1552         `thread`.`network` AS `network`,
1553         `thread`.`contact-id` AS `contact-id`,
1554         `ownercontact`.`contact-type` AS `contact-type`
1555         FROM `thread`
1556                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
1557                         STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
1558                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1559                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1560                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1561                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `thread`.`owner-id`
1562                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1563                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1564                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1565                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1566                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1567
1568 --
1569 -- VIEW owner-view
1570 --
1571 DROP VIEW IF EXISTS `owner-view`;
1572 CREATE VIEW `owner-view` AS SELECT 
1573         `contact`.`id` AS `id`,
1574         `contact`.`uid` AS `uid`,
1575         `contact`.`created` AS `created`,
1576         `contact`.`updated` AS `updated`,
1577         `contact`.`self` AS `self`,
1578         `contact`.`remote_self` AS `remote_self`,
1579         `contact`.`rel` AS `rel`,
1580         `contact`.`duplex` AS `duplex`,
1581         `contact`.`network` AS `network`,
1582         `contact`.`protocol` AS `protocol`,
1583         `contact`.`name` AS `name`,
1584         `contact`.`nick` AS `nick`,
1585         `contact`.`location` AS `location`,
1586         `contact`.`about` AS `about`,
1587         `contact`.`keywords` AS `keywords`,
1588         `contact`.`gender` AS `gender`,
1589         `contact`.`xmpp` AS `xmpp`,
1590         `contact`.`attag` AS `attag`,
1591         `contact`.`avatar` AS `avatar`,
1592         `contact`.`photo` AS `photo`,
1593         `contact`.`thumb` AS `thumb`,
1594         `contact`.`micro` AS `micro`,
1595         `contact`.`site-pubkey` AS `site-pubkey`,
1596         `contact`.`issued-id` AS `issued-id`,
1597         `contact`.`dfrn-id` AS `dfrn-id`,
1598         `contact`.`url` AS `url`,
1599         `contact`.`nurl` AS `nurl`,
1600         `contact`.`addr` AS `addr`,
1601         `contact`.`alias` AS `alias`,
1602         `contact`.`pubkey` AS `pubkey`,
1603         `contact`.`prvkey` AS `prvkey`,
1604         `contact`.`batch` AS `batch`,
1605         `contact`.`request` AS `request`,
1606         `contact`.`notify` AS `notify`,
1607         `contact`.`poll` AS `poll`,
1608         `contact`.`confirm` AS `confirm`,
1609         `contact`.`poco` AS `poco`,
1610         `contact`.`aes_allow` AS `aes_allow`,
1611         `contact`.`ret-aes` AS `ret-aes`,
1612         `contact`.`usehub` AS `usehub`,
1613         `contact`.`subhub` AS `subhub`,
1614         `contact`.`hub-verify` AS `hub-verify`,
1615         `contact`.`last-update` AS `last-update`,
1616         `contact`.`success_update` AS `success_update`,
1617         `contact`.`failure_update` AS `failure_update`,
1618         `contact`.`name-date` AS `name-date`,
1619         `contact`.`uri-date` AS `uri-date`,
1620         `contact`.`avatar-date` AS `avatar-date`,
1621         `contact`.`avatar-date` AS `picdate`,
1622         `contact`.`term-date` AS `term-date`,
1623         `contact`.`last-item` AS `last-item`,
1624         `contact`.`priority` AS `priority`,
1625         `user`.`blocked` AS `blocked`,
1626         `contact`.`block_reason` AS `block_reason`,
1627         `contact`.`readonly` AS `readonly`,
1628         `contact`.`writable` AS `writable`,
1629         `contact`.`forum` AS `forum`,
1630         `contact`.`prv` AS `prv`,
1631         `contact`.`contact-type` AS `contact-type`,
1632         `contact`.`manually-approve` AS `manually-approve`,
1633         `contact`.`hidden` AS `hidden`,
1634         `contact`.`archive` AS `archive`,
1635         `contact`.`pending` AS `pending`,
1636         `contact`.`deleted` AS `deleted`,
1637         `contact`.`unsearchable` AS `unsearchable`,
1638         `contact`.`sensitive` AS `sensitive`,
1639         `contact`.`baseurl` AS `baseurl`,
1640         `contact`.`reason` AS `reason`,
1641         `contact`.`closeness` AS `closeness`,
1642         `contact`.`info` AS `info`,
1643         `contact`.`profile-id` AS `profile-id`,
1644         `contact`.`bdyear` AS `bdyear`,
1645         `contact`.`bd` AS `bd`,
1646         `contact`.`notify_new_posts` AS `notify_new_posts`,
1647         `contact`.`fetch_further_information` AS `fetch_further_information`,
1648         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
1649         `user`.`parent-uid` AS `parent-uid`,
1650         `user`.`guid` AS `guid`,
1651         `user`.`nickname` AS `nickname`,
1652         `user`.`email` AS `email`,
1653         `user`.`openid` AS `openid`,
1654         `user`.`timezone` AS `timezone`,
1655         `user`.`language` AS `language`,
1656         `user`.`register_date` AS `register_date`,
1657         `user`.`login_date` AS `login_date`,
1658         `user`.`default-location` AS `default-location`,
1659         `user`.`allow_location` AS `allow_location`,
1660         `user`.`theme` AS `theme`,
1661         `user`.`pubkey` AS `upubkey`,
1662         `user`.`prvkey` AS `uprvkey`,
1663         `user`.`sprvkey` AS `sprvkey`,
1664         `user`.`spubkey` AS `spubkey`,
1665         `user`.`verified` AS `verified`,
1666         `user`.`blockwall` AS `blockwall`,
1667         `user`.`hidewall` AS `hidewall`,
1668         `user`.`blocktags` AS `blocktags`,
1669         `user`.`unkmail` AS `unkmail`,
1670         `user`.`cntunkmail` AS `cntunkmail`,
1671         `user`.`notify-flags` AS `notify-flags`,
1672         `user`.`page-flags` AS `page-flags`,
1673         `user`.`account-type` AS `account-type`,
1674         `user`.`prvnets` AS `prvnets`,
1675         `user`.`maxreq` AS `maxreq`,
1676         `user`.`expire` AS `expire`,
1677         `user`.`account_removed` AS `account_removed`,
1678         `user`.`account_expired` AS `account_expired`,
1679         `user`.`account_expires_on` AS `account_expires_on`,
1680         `user`.`expire_notification_sent` AS `expire_notification_sent`,
1681         `user`.`def_gid` AS `def_gid`,
1682         `user`.`allow_cid` AS `allow_cid`,
1683         `user`.`allow_gid` AS `allow_gid`,
1684         `user`.`deny_cid` AS `deny_cid`,
1685         `user`.`deny_gid` AS `deny_gid`,
1686         `user`.`openidserver` AS `openidserver`,
1687         `profile`.`publish` AS `publish`,
1688         `profile`.`net-publish` AS `net-publish`,
1689         `profile`.`hide-friends` AS `hide-friends`,
1690         `profile`.`prv_keywords` AS `prv_keywords`,
1691         `profile`.`pub_keywords` AS `pub_keywords`,
1692         `profile`.`address` AS `address`,
1693         `profile`.`locality` AS `locality`,
1694         `profile`.`region` AS `region`,
1695         `profile`.`postal-code` AS `postal-code`,
1696         `profile`.`country-name` AS `country-name`,
1697         `profile`.`homepage` AS `homepage`,
1698         `profile`.`dob` AS `dob`
1699         FROM `user`
1700                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
1701                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
1702
1703 --
1704 -- VIEW pending-view
1705 --
1706 DROP VIEW IF EXISTS `pending-view`;
1707 CREATE VIEW `pending-view` AS SELECT 
1708         `register`.`id` AS `id`,
1709         `register`.`hash` AS `hash`,
1710         `register`.`created` AS `created`,
1711         `register`.`uid` AS `uid`,
1712         `register`.`password` AS `password`,
1713         `register`.`language` AS `language`,
1714         `register`.`note` AS `note`,
1715         `contact`.`self` AS `self`,
1716         `contact`.`name` AS `name`,
1717         `contact`.`url` AS `url`,
1718         `contact`.`micro` AS `micro`,
1719         `user`.`email` AS `email`,
1720         `contact`.`nick` AS `nick`
1721         FROM `register`
1722                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
1723                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
1724
1725 --
1726 -- VIEW tag-search-view
1727 --
1728 DROP VIEW IF EXISTS `tag-search-view`;
1729 CREATE VIEW `tag-search-view` AS SELECT 
1730         `post-tag`.`uri-id` AS `uri-id`,
1731         `item`.`id` AS `iid`,
1732         `item`.`uri` AS `uri`,
1733         `item`.`guid` AS `guid`,
1734         `item`.`uid` AS `uid`,
1735         `item`.`private` AS `private`,
1736         `item`.`wall` AS `wall`,
1737         `item`.`origin` AS `origin`,
1738         `item`.`gravity` AS `gravity`,
1739         `item`.`received` AS `received`,
1740         `tag`.`name` AS `name`
1741         FROM `post-tag`
1742                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
1743                         INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
1744                         WHERE `post-tag`.`type` = 1;
1745
1746 --
1747 -- VIEW workerqueue-view
1748 --
1749 DROP VIEW IF EXISTS `workerqueue-view`;
1750 CREATE VIEW `workerqueue-view` AS SELECT 
1751         `process`.`pid` AS `pid`,
1752         `workerqueue`.`priority` AS `priority`
1753         FROM `process`
1754                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
1755                         WHERE NOT `workerqueue`.`done`;
1756
1757