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