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