]> git.mxchange.org Git - friendica.git/blob - database.sql
e1a8f7fe7c80e9b0b2b31fc0fbf03d580fd9de88
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2020.09-dev (Red Hot Poker)
3 -- DB_UPDATE_VERSION 1361
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 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
927
928 --
929 -- TABLE poll
930 --
931 CREATE TABLE IF NOT EXISTS `poll` (
932         `id` int unsigned NOT NULL auto_increment COMMENT '',
933         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
934         `q0` text COMMENT '',
935         `q1` text COMMENT '',
936         `q2` text COMMENT '',
937         `q3` text COMMENT '',
938         `q4` text COMMENT '',
939         `q5` text COMMENT '',
940         `q6` text COMMENT '',
941         `q7` text COMMENT '',
942         `q8` text COMMENT '',
943         `q9` text COMMENT '',
944          PRIMARY KEY(`id`),
945          INDEX `uid` (`uid`)
946 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently unused table for storing poll results';
947
948 --
949 -- TABLE poll_result
950 --
951 CREATE TABLE IF NOT EXISTS `poll_result` (
952         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
953         `poll_id` int unsigned NOT NULL DEFAULT 0,
954         `choice` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
955          PRIMARY KEY(`id`),
956          INDEX `poll_id` (`poll_id`)
957 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='data for polls - currently unused';
958
959 --
960 -- TABLE post-category
961 --
962 CREATE TABLE IF NOT EXISTS `post-category` (
963         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
964         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
965         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
966         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
967          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
968          INDEX `uri-id` (`tid`),
969         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
970         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
971 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
972
973 --
974 -- TABLE post-delivery-data
975 --
976 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
977         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
978         `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',
979         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
980         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
981         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
982         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
983         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
984         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
985         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
986         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
987         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
988          PRIMARY KEY(`uri-id`),
989         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
990 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
991
992 --
993 -- TABLE post-tag
994 --
995 CREATE TABLE IF NOT EXISTS `post-tag` (
996         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
997         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
998         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
999         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1000          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1001          INDEX `tid` (`tid`),
1002          INDEX `cid` (`cid`),
1003         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1004         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1005         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1006 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1007
1008 --
1009 -- TABLE process
1010 --
1011 CREATE TABLE IF NOT EXISTS `process` (
1012         `pid` int unsigned NOT NULL COMMENT '',
1013         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1014         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1015          PRIMARY KEY(`pid`),
1016          INDEX `command` (`command`)
1017 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1018
1019 --
1020 -- TABLE profile
1021 --
1022 CREATE TABLE IF NOT EXISTS `profile` (
1023         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1024         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1025         `profile-name` varchar(255) COMMENT 'Deprecated',
1026         `is-default` boolean COMMENT 'Deprecated',
1027         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1028         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1029         `pdesc` varchar(255) COMMENT 'Deprecated',
1030         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1031         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1032         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1033         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1034         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1035         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1036         `hometown` varchar(255) COMMENT 'Deprecated',
1037         `gender` varchar(32) COMMENT 'Deprecated',
1038         `marital` varchar(255) COMMENT 'Deprecated',
1039         `with` text COMMENT 'Deprecated',
1040         `howlong` datetime COMMENT 'Deprecated',
1041         `sexual` varchar(255) COMMENT 'Deprecated',
1042         `politic` varchar(255) COMMENT 'Deprecated',
1043         `religion` varchar(255) COMMENT 'Deprecated',
1044         `pub_keywords` text COMMENT '',
1045         `prv_keywords` text COMMENT '',
1046         `likes` text COMMENT 'Deprecated',
1047         `dislikes` text COMMENT 'Deprecated',
1048         `about` text COMMENT 'Profile description',
1049         `summary` varchar(255) COMMENT 'Deprecated',
1050         `music` text COMMENT 'Deprecated',
1051         `book` text COMMENT 'Deprecated',
1052         `tv` text COMMENT 'Deprecated',
1053         `film` text COMMENT 'Deprecated',
1054         `interest` text COMMENT 'Deprecated',
1055         `romance` text COMMENT 'Deprecated',
1056         `work` text COMMENT 'Deprecated',
1057         `education` text COMMENT 'Deprecated',
1058         `contact` text COMMENT 'Deprecated',
1059         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1060         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1061         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1062         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1063         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1064         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1065          PRIMARY KEY(`id`),
1066          INDEX `uid_is-default` (`uid`,`is-default`),
1067          FULLTEXT INDEX `pub_keywords` (`pub_keywords`)
1068 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1069
1070 --
1071 -- TABLE profile_check
1072 --
1073 CREATE TABLE IF NOT EXISTS `profile_check` (
1074         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1075         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1076         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1077         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1078         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1079         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1080          PRIMARY KEY(`id`)
1081 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1082
1083 --
1084 -- TABLE profile_field
1085 --
1086 CREATE TABLE IF NOT EXISTS `profile_field` (
1087         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1088         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1089         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1090         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1091         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1092         `value` text COMMENT 'Value of the field',
1093         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1094         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1095          PRIMARY KEY(`id`),
1096          INDEX `uid` (`uid`),
1097          INDEX `order` (`order`),
1098          INDEX `psid` (`psid`),
1099         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1100 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1101
1102 --
1103 -- TABLE push_subscriber
1104 --
1105 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1106         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1107         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1108         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1109         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1110         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1111         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1112         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1113         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1114         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1115         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1116          PRIMARY KEY(`id`),
1117          INDEX `next_try` (`next_try`)
1118 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1119
1120 --
1121 -- TABLE register
1122 --
1123 CREATE TABLE IF NOT EXISTS `register` (
1124         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1125         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1126         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1127         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1128         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1129         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1130         `note` text COMMENT '',
1131          PRIMARY KEY(`id`)
1132 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1133
1134 --
1135 -- TABLE search
1136 --
1137 CREATE TABLE IF NOT EXISTS `search` (
1138         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1139         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1140         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1141          PRIMARY KEY(`id`),
1142          INDEX `uid` (`uid`)
1143 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1144
1145 --
1146 -- TABLE session
1147 --
1148 CREATE TABLE IF NOT EXISTS `session` (
1149         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1150         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1151         `data` text COMMENT '',
1152         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1153          PRIMARY KEY(`id`),
1154          INDEX `sid` (`sid`(64)),
1155          INDEX `expire` (`expire`)
1156 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1157
1158 --
1159 -- TABLE storage
1160 --
1161 CREATE TABLE IF NOT EXISTS `storage` (
1162         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1163         `data` longblob NOT NULL COMMENT 'file data',
1164          PRIMARY KEY(`id`)
1165 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1166
1167 --
1168 -- TABLE thread
1169 --
1170 CREATE TABLE IF NOT EXISTS `thread` (
1171         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID',
1172         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
1173         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1174         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1175         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1176         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1177         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1178         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1179         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1180         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1181         `changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1182         `wall` boolean NOT NULL DEFAULT '0' COMMENT '',
1183         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1184         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1185         `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
1186         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1187         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1188         `ignored` boolean NOT NULL DEFAULT '0' COMMENT '',
1189         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
1190         `unseen` boolean NOT NULL DEFAULT '1' COMMENT '',
1191         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '',
1192         `origin` boolean NOT NULL DEFAULT '0' COMMENT '',
1193         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1194         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1195         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1196         `bookmark` boolean COMMENT '',
1197          PRIMARY KEY(`iid`),
1198          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
1199          INDEX `uid_network_received` (`uid`,`network`,`received`),
1200          INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
1201          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
1202          INDEX `contactid` (`contact-id`),
1203          INDEX `ownerid` (`owner-id`),
1204          INDEX `authorid` (`author-id`),
1205          INDEX `uid_received` (`uid`,`received`),
1206          INDEX `uid_commented` (`uid`,`commented`),
1207          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1208          INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`),
1209          INDEX `uri-id` (`uri-id`),
1210         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1211 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1212
1213 --
1214 -- TABLE tokens
1215 --
1216 CREATE TABLE IF NOT EXISTS `tokens` (
1217         `id` varchar(40) NOT NULL COMMENT '',
1218         `secret` text COMMENT '',
1219         `client_id` varchar(20) NOT NULL DEFAULT '',
1220         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1221         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1222         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1223          PRIMARY KEY(`id`),
1224          INDEX `client_id` (`client_id`),
1225         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE
1226 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1227
1228 --
1229 -- TABLE user
1230 --
1231 CREATE TABLE IF NOT EXISTS `user` (
1232         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1233         `parent-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'The parent user that has full control about this user',
1234         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
1235         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
1236         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
1237         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
1238         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
1239         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
1240         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1241         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
1242         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
1243         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
1244         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
1245         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
1246         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
1247         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
1248         `pubkey` text COMMENT 'RSA public key 4096 bit',
1249         `prvkey` text COMMENT 'RSA private key 4096 bit',
1250         `spubkey` text COMMENT '',
1251         `sprvkey` text COMMENT '',
1252         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
1253         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
1254         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
1255         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
1256         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
1257         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
1258         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
1259         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
1260         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
1261         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1262         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
1263         `pwdreset` varchar(255) COMMENT 'Password reset request token',
1264         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
1265         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
1266         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1267         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
1268         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
1269         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
1270         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
1271         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1272         `allow_cid` mediumtext COMMENT 'default permission for this user',
1273         `allow_gid` mediumtext COMMENT 'default permission for this user',
1274         `deny_cid` mediumtext COMMENT 'default permission for this user',
1275         `deny_gid` mediumtext COMMENT 'default permission for this user',
1276         `openidserver` text COMMENT '',
1277          PRIMARY KEY(`uid`),
1278          INDEX `nickname` (`nickname`(32))
1279 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
1280
1281 --
1282 -- TABLE userd
1283 --
1284 CREATE TABLE IF NOT EXISTS `userd` (
1285         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1286         `username` varchar(255) NOT NULL COMMENT '',
1287          PRIMARY KEY(`id`),
1288          INDEX `username` (`username`(32))
1289 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1290
1291 --
1292 -- TABLE user-contact
1293 --
1294 CREATE TABLE IF NOT EXISTS `user-contact` (
1295         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1296         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1297         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1298         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1299         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1300          PRIMARY KEY(`uid`,`cid`)
1301 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1302
1303 --
1304 -- TABLE user-item
1305 --
1306 CREATE TABLE IF NOT EXISTS `user-item` (
1307         `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item id',
1308         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1309         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
1310         `ignored` boolean COMMENT 'Ignore this thread if set',
1311         `pinned` boolean COMMENT 'The item is pinned on the profile page',
1312         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1313          PRIMARY KEY(`uid`,`iid`),
1314          INDEX `uid_pinned` (`uid`,`pinned`),
1315          INDEX `iid_uid` (`iid`,`uid`)
1316 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
1317
1318 --
1319 -- TABLE verb
1320 --
1321 CREATE TABLE IF NOT EXISTS `verb` (
1322         `id` smallint unsigned NOT NULL auto_increment,
1323         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
1324          PRIMARY KEY(`id`)
1325 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
1326
1327 --
1328 -- TABLE worker-ipc
1329 --
1330 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1331         `key` int NOT NULL COMMENT '',
1332         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1333          PRIMARY KEY(`key`)
1334 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1335
1336 --
1337 -- TABLE workerqueue
1338 --
1339 CREATE TABLE IF NOT EXISTS `workerqueue` (
1340         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1341         `parameter` mediumtext COMMENT 'Task command',
1342         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1343         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1344         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1345         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1346         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1347         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1348         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1349          PRIMARY KEY(`id`),
1350          INDEX `done_parameter` (`done`,`parameter`(64)),
1351          INDEX `done_executed` (`done`,`executed`),
1352          INDEX `done_priority_created` (`done`,`priority`,`created`),
1353          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1354          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1355          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1356          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1357 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1358
1359 --
1360 -- VIEW category-view
1361 --
1362 DROP VIEW IF EXISTS `category-view`;
1363 CREATE VIEW `category-view` AS SELECT 
1364         `post-category`.`uri-id` AS `uri-id`,
1365         `post-category`.`uid` AS `uid`,
1366         `item-uri`.`uri` AS `uri`,
1367         `item-uri`.`guid` AS `guid`,
1368         `post-category`.`type` AS `type`,
1369         `post-category`.`tid` AS `tid`,
1370         `tag`.`name` AS `name`,
1371         `tag`.`url` AS `url`
1372         FROM `post-category`
1373                         INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id`
1374                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
1375
1376 --
1377 -- VIEW tag-view
1378 --
1379 DROP VIEW IF EXISTS `tag-view`;
1380 CREATE VIEW `tag-view` AS SELECT 
1381         `post-tag`.`uri-id` AS `uri-id`,
1382         `item-uri`.`uri` AS `uri`,
1383         `item-uri`.`guid` AS `guid`,
1384         `post-tag`.`type` AS `type`,
1385         `post-tag`.`tid` AS `tid`,
1386         `post-tag`.`cid` AS `cid`,
1387         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
1388         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
1389         FROM `post-tag`
1390                         INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
1391                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
1392                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
1393
1394 --
1395 -- VIEW network-item-view
1396 --
1397 DROP VIEW IF EXISTS `network-item-view`;
1398 CREATE VIEW `network-item-view` AS SELECT 
1399         `item`.`parent-uri-id` AS `uri-id`,
1400         `item`.`parent-uri` AS `uri`,
1401         `item`.`parent` AS `parent`,
1402         `item`.`received` AS `received`,
1403         `item`.`commented` AS `commented`,
1404         `item`.`created` AS `created`,
1405         `item`.`uid` AS `uid`,
1406         `item`.`starred` AS `starred`,
1407         `item`.`mention` AS `mention`,
1408         `item`.`network` AS `network`,
1409         `item`.`unseen` AS `unseen`,
1410         `item`.`gravity` AS `gravity`,
1411         `item`.`contact-id` AS `contact-id`
1412         FROM `item`
1413                         INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
1414                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
1415                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1416                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1417                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1418                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1419                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1420                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1421                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1422
1423 --
1424 -- VIEW network-thread-view
1425 --
1426 DROP VIEW IF EXISTS `network-thread-view`;
1427 CREATE VIEW `network-thread-view` AS SELECT 
1428         `item`.`uri-id` AS `uri-id`,
1429         `item`.`uri` AS `uri`,
1430         `item`.`parent-uri-id` AS `parent-uri-id`,
1431         `thread`.`iid` AS `parent`,
1432         `thread`.`received` AS `received`,
1433         `thread`.`commented` AS `commented`,
1434         `thread`.`created` AS `created`,
1435         `thread`.`uid` AS `uid`,
1436         `thread`.`starred` AS `starred`,
1437         `thread`.`mention` AS `mention`,
1438         `thread`.`network` AS `network`,
1439         `thread`.`contact-id` AS `contact-id`
1440         FROM `thread`
1441                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
1442                         STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
1443                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
1444                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
1445                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
1446                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
1447                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
1448                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1449                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1450
1451 --
1452 -- VIEW owner-view
1453 --
1454 DROP VIEW IF EXISTS `owner-view`;
1455 CREATE VIEW `owner-view` AS SELECT 
1456         `contact`.`id` AS `id`,
1457         `contact`.`uid` AS `uid`,
1458         `contact`.`created` AS `created`,
1459         `contact`.`updated` AS `updated`,
1460         `contact`.`self` AS `self`,
1461         `contact`.`remote_self` AS `remote_self`,
1462         `contact`.`rel` AS `rel`,
1463         `contact`.`duplex` AS `duplex`,
1464         `contact`.`network` AS `network`,
1465         `contact`.`protocol` AS `protocol`,
1466         `contact`.`name` AS `name`,
1467         `contact`.`nick` AS `nick`,
1468         `contact`.`location` AS `location`,
1469         `contact`.`about` AS `about`,
1470         `contact`.`keywords` AS `keywords`,
1471         `contact`.`gender` AS `gender`,
1472         `contact`.`xmpp` AS `xmpp`,
1473         `contact`.`attag` AS `attag`,
1474         `contact`.`avatar` AS `avatar`,
1475         `contact`.`photo` AS `photo`,
1476         `contact`.`thumb` AS `thumb`,
1477         `contact`.`micro` AS `micro`,
1478         `contact`.`site-pubkey` AS `site-pubkey`,
1479         `contact`.`issued-id` AS `issued-id`,
1480         `contact`.`dfrn-id` AS `dfrn-id`,
1481         `contact`.`url` AS `url`,
1482         `contact`.`nurl` AS `nurl`,
1483         `contact`.`addr` AS `addr`,
1484         `contact`.`alias` AS `alias`,
1485         `contact`.`pubkey` AS `pubkey`,
1486         `contact`.`prvkey` AS `prvkey`,
1487         `contact`.`batch` AS `batch`,
1488         `contact`.`request` AS `request`,
1489         `contact`.`notify` AS `notify`,
1490         `contact`.`poll` AS `poll`,
1491         `contact`.`confirm` AS `confirm`,
1492         `contact`.`poco` AS `poco`,
1493         `contact`.`aes_allow` AS `aes_allow`,
1494         `contact`.`ret-aes` AS `ret-aes`,
1495         `contact`.`usehub` AS `usehub`,
1496         `contact`.`subhub` AS `subhub`,
1497         `contact`.`hub-verify` AS `hub-verify`,
1498         `contact`.`last-update` AS `last-update`,
1499         `contact`.`success_update` AS `success_update`,
1500         `contact`.`failure_update` AS `failure_update`,
1501         `contact`.`name-date` AS `name-date`,
1502         `contact`.`uri-date` AS `uri-date`,
1503         `contact`.`avatar-date` AS `avatar-date`,
1504         `contact`.`avatar-date` AS `picdate`,
1505         `contact`.`term-date` AS `term-date`,
1506         `contact`.`last-item` AS `last-item`,
1507         `contact`.`priority` AS `priority`,
1508         `contact`.`blocked` AS `blocked`,
1509         `contact`.`block_reason` AS `block_reason`,
1510         `contact`.`readonly` AS `readonly`,
1511         `contact`.`writable` AS `writable`,
1512         `contact`.`forum` AS `forum`,
1513         `contact`.`prv` AS `prv`,
1514         `contact`.`contact-type` AS `contact-type`,
1515         `contact`.`hidden` AS `hidden`,
1516         `contact`.`archive` AS `archive`,
1517         `contact`.`pending` AS `pending`,
1518         `contact`.`deleted` AS `deleted`,
1519         `contact`.`unsearchable` AS `unsearchable`,
1520         `contact`.`sensitive` AS `sensitive`,
1521         `contact`.`baseurl` AS `baseurl`,
1522         `contact`.`reason` AS `reason`,
1523         `contact`.`closeness` AS `closeness`,
1524         `contact`.`info` AS `info`,
1525         `contact`.`profile-id` AS `profile-id`,
1526         `contact`.`bdyear` AS `bdyear`,
1527         `contact`.`bd` AS `bd`,
1528         `contact`.`notify_new_posts` AS `notify_new_posts`,
1529         `contact`.`fetch_further_information` AS `fetch_further_information`,
1530         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
1531         `user`.`parent-uid` AS `parent-uid`,
1532         `user`.`guid` AS `guid`,
1533         `user`.`nickname` AS `nickname`,
1534         `user`.`email` AS `email`,
1535         `user`.`openid` AS `openid`,
1536         `user`.`timezone` AS `timezone`,
1537         `user`.`language` AS `language`,
1538         `user`.`register_date` AS `register_date`,
1539         `user`.`login_date` AS `login_date`,
1540         `user`.`default-location` AS `default-location`,
1541         `user`.`allow_location` AS `allow_location`,
1542         `user`.`theme` AS `theme`,
1543         `user`.`pubkey` AS `upubkey`,
1544         `user`.`prvkey` AS `uprvkey`,
1545         `user`.`sprvkey` AS `sprvkey`,
1546         `user`.`spubkey` AS `spubkey`,
1547         `user`.`verified` AS `verified`,
1548         `user`.`blockwall` AS `blockwall`,
1549         `user`.`hidewall` AS `hidewall`,
1550         `user`.`blocktags` AS `blocktags`,
1551         `user`.`unkmail` AS `unkmail`,
1552         `user`.`cntunkmail` AS `cntunkmail`,
1553         `user`.`notify-flags` AS `notify-flags`,
1554         `user`.`page-flags` AS `page-flags`,
1555         `user`.`account-type` AS `account-type`,
1556         `user`.`prvnets` AS `prvnets`,
1557         `user`.`maxreq` AS `maxreq`,
1558         `user`.`expire` AS `expire`,
1559         `user`.`account_removed` AS `account_removed`,
1560         `user`.`account_expired` AS `account_expired`,
1561         `user`.`account_expires_on` AS `account_expires_on`,
1562         `user`.`expire_notification_sent` AS `expire_notification_sent`,
1563         `user`.`def_gid` AS `def_gid`,
1564         `user`.`allow_cid` AS `allow_cid`,
1565         `user`.`allow_gid` AS `allow_gid`,
1566         `user`.`deny_cid` AS `deny_cid`,
1567         `user`.`deny_gid` AS `deny_gid`,
1568         `user`.`openidserver` AS `openidserver`,
1569         `profile`.`publish` AS `publish`,
1570         `profile`.`net-publish` AS `net-publish`,
1571         `profile`.`hide-friends` AS `hide-friends`,
1572         `profile`.`prv_keywords` AS `prv_keywords`,
1573         `profile`.`pub_keywords` AS `pub_keywords`,
1574         `profile`.`address` AS `address`,
1575         `profile`.`locality` AS `locality`,
1576         `profile`.`region` AS `region`,
1577         `profile`.`postal-code` AS `postal-code`,
1578         `profile`.`country-name` AS `country-name`,
1579         `profile`.`homepage` AS `homepage`,
1580         `profile`.`dob` AS `dob`
1581         FROM `user`
1582                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
1583                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
1584
1585 --
1586 -- VIEW pending-view
1587 --
1588 DROP VIEW IF EXISTS `pending-view`;
1589 CREATE VIEW `pending-view` AS SELECT 
1590         `register`.`id` AS `id`,
1591         `register`.`hash` AS `hash`,
1592         `register`.`created` AS `created`,
1593         `register`.`uid` AS `uid`,
1594         `register`.`password` AS `password`,
1595         `register`.`language` AS `language`,
1596         `register`.`note` AS `note`,
1597         `contact`.`self` AS `self`,
1598         `contact`.`name` AS `name`,
1599         `contact`.`url` AS `url`,
1600         `contact`.`micro` AS `micro`,
1601         `user`.`email` AS `email`,
1602         `contact`.`nick` AS `nick`
1603         FROM `register`
1604                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
1605                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
1606
1607 --
1608 -- VIEW tag-search-view
1609 --
1610 DROP VIEW IF EXISTS `tag-search-view`;
1611 CREATE VIEW `tag-search-view` AS SELECT 
1612         `post-tag`.`uri-id` AS `uri-id`,
1613         `item`.`id` AS `iid`,
1614         `item`.`uri` AS `uri`,
1615         `item`.`guid` AS `guid`,
1616         `item`.`uid` AS `uid`,
1617         `item`.`private` AS `private`,
1618         `item`.`wall` AS `wall`,
1619         `item`.`origin` AS `origin`,
1620         `item`.`gravity` AS `gravity`,
1621         `item`.`received` AS `received`,
1622         `tag`.`name` AS `name`
1623         FROM `post-tag`
1624                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
1625                         INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
1626                         WHERE `post-tag`.`type` = 1;
1627
1628 --
1629 -- VIEW workerqueue-view
1630 --
1631 DROP VIEW IF EXISTS `workerqueue-view`;
1632 CREATE VIEW `workerqueue-view` AS SELECT 
1633         `process`.`pid` AS `pid`,
1634         `workerqueue`.`priority` AS `priority`
1635         FROM `process`
1636                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
1637                         WHERE NOT `workerqueue`.`done`;
1638
1639