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