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