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