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