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