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