]> git.mxchange.org Git - friendica.git/blob - database.sql
Post update function to set the "external-id"
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2021.03-dev (Red Hot Poker)
3 -- DB_UPDATE_VERSION 1400
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         `protocol` tinyint unsigned COMMENT 'The protocol of the server',
24         `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
25         `relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
26         `relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
27         `detection-method` tinyint unsigned COMMENT 'Method that had been used to detect that server',
28         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
29         `last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
30         `last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last successful connection request',
31         `last_failure` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Last failed connection request',
32         `failed` boolean COMMENT 'Connection failed',
33         `next_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Next connection request',
34          PRIMARY KEY(`id`),
35          UNIQUE INDEX `nurl` (`nurl`(190)),
36          INDEX `next_contact` (`next_contact`)
37 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers';
38
39 --
40 -- TABLE user
41 --
42 CREATE TABLE IF NOT EXISTS `user` (
43         `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
44         `parent-uid` mediumint unsigned COMMENT 'The parent user that has full control about this user',
45         `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user',
46         `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by',
47         `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password',
48         `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?',
49         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name',
50         `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address',
51         `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
52         `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone',
53         `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
54         `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
55         `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
56         `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
57         `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
58         `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
59         `pubkey` text COMMENT 'RSA public key 4096 bit',
60         `prvkey` text COMMENT 'RSA private key 4096 bit',
61         `spubkey` text COMMENT '',
62         `sprvkey` text COMMENT '',
63         `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email',
64         `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked',
65         `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user',
66         `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers',
67         `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user',
68         `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user',
69         `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '',
70         `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options',
71         `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type',
72         `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
73         `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '',
74         `pwdreset` varchar(255) COMMENT 'Password reset request token',
75         `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request',
76         `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '',
77         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
78         `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed',
79         `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '',
80         `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted',
81         `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration',
82         `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
83         `allow_cid` mediumtext COMMENT 'default permission for this user',
84         `allow_gid` mediumtext COMMENT 'default permission for this user',
85         `deny_cid` mediumtext COMMENT 'default permission for this user',
86         `deny_gid` mediumtext COMMENT 'default permission for this user',
87         `openidserver` text COMMENT '',
88          PRIMARY KEY(`uid`),
89          INDEX `nickname` (`nickname`(32)),
90          INDEX `parent-uid` (`parent-uid`),
91         FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
92 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
93
94 --
95 -- TABLE contact
96 --
97 CREATE TABLE IF NOT EXISTS `contact` (
98         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
99         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
100         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
101         `updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last contact update',
102         `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
103         `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
104         `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
105         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
106         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
107         `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
108         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
109         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
110         `location` varchar(255) DEFAULT '' COMMENT '',
111         `about` text COMMENT '',
112         `keywords` text COMMENT 'public keywords (interests) of the contact',
113         `gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
114         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
115         `attag` varchar(255) NOT NULL DEFAULT '' COMMENT '',
116         `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '',
117         `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
118         `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
119         `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
120         `site-pubkey` text COMMENT '',
121         `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
122         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
123         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
124         `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
125         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
126         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
127         `pubkey` text COMMENT 'RSA public key 4096 bit',
128         `prvkey` text COMMENT 'RSA private key 4096 bit',
129         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
130         `request` varchar(255) COMMENT '',
131         `notify` varchar(255) COMMENT '',
132         `poll` varchar(255) COMMENT '',
133         `confirm` varchar(255) COMMENT '',
134         `subscribe` varchar(255) COMMENT '',
135         `poco` varchar(255) COMMENT '',
136         `aes_allow` boolean NOT NULL DEFAULT '0' COMMENT '',
137         `ret-aes` boolean NOT NULL DEFAULT '0' COMMENT '',
138         `usehub` boolean NOT NULL DEFAULT '0' COMMENT '',
139         `subhub` boolean NOT NULL DEFAULT '0' COMMENT '',
140         `hub-verify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
141         `last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last try to update the contact info',
142         `success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful contact update',
143         `failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed update',
144         `failed` boolean COMMENT 'Connection failed',
145         `name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
146         `uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
147         `avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
148         `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
149         `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post',
150         `last-discovery` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last follower discovery',
151         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
152         `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status',
153         `block_reason` text COMMENT 'Node-wide block reason',
154         `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly',
155         `writable` boolean NOT NULL DEFAULT '0' COMMENT '',
156         `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum',
157         `prv` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a private group',
158         `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT '',
159         `manually-approve` boolean COMMENT '',
160         `hidden` boolean NOT NULL DEFAULT '0' COMMENT '',
161         `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
162         `pending` boolean NOT NULL DEFAULT '1' COMMENT '',
163         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'Contact has been deleted',
164         `rating` tinyint NOT NULL DEFAULT 0 COMMENT '',
165         `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
166         `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
167         `baseurl` varchar(255) DEFAULT '' COMMENT 'baseurl of the contact',
168         `gsid` int unsigned COMMENT 'Global Server ID',
169         `reason` text COMMENT '',
170         `closeness` tinyint unsigned NOT NULL DEFAULT 99 COMMENT '',
171         `info` mediumtext COMMENT '',
172         `profile-id` int unsigned COMMENT 'Deprecated',
173         `bdyear` varchar(4) NOT NULL DEFAULT '' COMMENT '',
174         `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
175         `notify_new_posts` boolean NOT NULL DEFAULT '0' COMMENT '',
176         `fetch_further_information` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
177         `ffi_keyword_denylist` text COMMENT '',
178          PRIMARY KEY(`id`),
179          INDEX `uid_name` (`uid`,`name`(190)),
180          INDEX `self_uid` (`self`,`uid`),
181          INDEX `alias_uid` (`alias`(128),`uid`),
182          INDEX `pending_uid` (`pending`,`uid`),
183          INDEX `blocked_uid` (`blocked`,`uid`),
184          INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
185          INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
186          INDEX `addr_uid` (`addr`(128),`uid`),
187          INDEX `nurl_uid` (`nurl`(128),`uid`),
188          INDEX `nick_uid` (`nick`(128),`uid`),
189          INDEX `attag_uid` (`attag`(96),`uid`),
190          INDEX `dfrn-id` (`dfrn-id`(64)),
191          INDEX `issued-id` (`issued-id`(64)),
192          INDEX `network_uid_lastupdate` (`network`,`uid`,`last-update`),
193          INDEX `uid_network_self_lastupdate` (`uid`,`network`,`self`,`last-update`),
194          INDEX `uid_lastitem` (`uid`,`last-item`),
195          INDEX `gsid` (`gsid`),
196         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
197         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
198 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';
199
200 --
201 -- TABLE item-uri
202 --
203 CREATE TABLE IF NOT EXISTS `item-uri` (
204         `id` int unsigned NOT NULL auto_increment,
205         `uri` varbinary(255) NOT NULL COMMENT 'URI of an item',
206         `guid` varbinary(255) COMMENT 'A unique identifier for an item',
207          PRIMARY KEY(`id`),
208          UNIQUE INDEX `uri` (`uri`),
209          INDEX `guid` (`guid`)
210 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items';
211
212 --
213 -- TABLE tag
214 --
215 CREATE TABLE IF NOT EXISTS `tag` (
216         `id` int unsigned NOT NULL auto_increment COMMENT '',
217         `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
218         `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
219          PRIMARY KEY(`id`),
220          UNIQUE INDEX `type_name_url` (`name`,`url`),
221          INDEX `url` (`url`)
222 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
223
224 --
225 -- TABLE clients
226 --
227 CREATE TABLE IF NOT EXISTS `clients` (
228         `client_id` varchar(20) NOT NULL COMMENT '',
229         `pw` varchar(20) NOT NULL DEFAULT '' COMMENT '',
230         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
231         `name` text COMMENT '',
232         `icon` text COMMENT '',
233         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
234          PRIMARY KEY(`client_id`),
235          INDEX `uid` (`uid`),
236         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
237 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
238
239 --
240 -- TABLE permissionset
241 --
242 CREATE TABLE IF NOT EXISTS `permissionset` (
243         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
244         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
245         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
246         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
247         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
248         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
249          PRIMARY KEY(`id`),
250          INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`uid`,`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)),
251         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
252 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
253
254 --
255 -- TABLE verb
256 --
257 CREATE TABLE IF NOT EXISTS `verb` (
258         `id` smallint unsigned NOT NULL auto_increment,
259         `name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
260          PRIMARY KEY(`id`)
261 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
262
263 --
264 -- TABLE 2fa_app_specific_password
265 --
266 CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
267         `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
268         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
269         `description` varchar(255) COMMENT 'Description of the usage of the password',
270         `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
271         `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
272         `last_used` datetime COMMENT 'Datetime the password was last used',
273          PRIMARY KEY(`id`),
274          INDEX `uid_description` (`uid`,`description`(190)),
275         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
276 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
277
278 --
279 -- TABLE 2fa_recovery_codes
280 --
281 CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` (
282         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
283         `code` varchar(50) NOT NULL COMMENT 'Recovery code string',
284         `generated` datetime NOT NULL COMMENT 'Datetime the code was generated',
285         `used` datetime COMMENT 'Datetime the code was used',
286          PRIMARY KEY(`uid`,`code`),
287         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
288 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes';
289
290 --
291 -- TABLE 2fa_trusted_browser
292 --
293 CREATE TABLE IF NOT EXISTS `2fa_trusted_browser` (
294         `cookie_hash` varchar(80) NOT NULL COMMENT 'Trusted cookie hash',
295         `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
296         `user_agent` text COMMENT 'User agent string',
297         `created` datetime NOT NULL COMMENT 'Datetime the trusted browser was recorded',
298         `last_used` datetime COMMENT 'Datetime the trusted browser was last used',
299          PRIMARY KEY(`cookie_hash`),
300          INDEX `uid` (`uid`),
301         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
302 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication trusted browsers';
303
304 --
305 -- TABLE addon
306 --
307 CREATE TABLE IF NOT EXISTS `addon` (
308         `id` int unsigned NOT NULL auto_increment COMMENT '',
309         `name` varchar(50) NOT NULL DEFAULT '' COMMENT 'addon base (file)name',
310         `version` varchar(50) NOT NULL DEFAULT '' COMMENT 'currently unused',
311         `installed` boolean NOT NULL DEFAULT '0' COMMENT 'currently always 1',
312         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'currently unused',
313         `timestamp` int unsigned NOT NULL DEFAULT 0 COMMENT 'file timestamp to check for reloads',
314         `plugin_admin` boolean NOT NULL DEFAULT '0' COMMENT '1 = has admin config, 0 = has no admin config',
315          PRIMARY KEY(`id`),
316          UNIQUE INDEX `name` (`name`)
317 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registered addons';
318
319 --
320 -- TABLE apcontact
321 --
322 CREATE TABLE IF NOT EXISTS `apcontact` (
323         `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
324         `uuid` varchar(255) COMMENT '',
325         `type` varchar(20) NOT NULL COMMENT '',
326         `following` varchar(255) COMMENT '',
327         `followers` varchar(255) COMMENT '',
328         `inbox` varchar(255) NOT NULL COMMENT '',
329         `outbox` varchar(255) COMMENT '',
330         `sharedinbox` varchar(255) COMMENT '',
331         `manually-approve` boolean COMMENT '',
332         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
333         `name` varchar(255) COMMENT '',
334         `about` text COMMENT '',
335         `photo` varchar(255) COMMENT '',
336         `addr` varchar(255) COMMENT '',
337         `alias` varchar(255) COMMENT '',
338         `pubkey` text COMMENT '',
339         `subscribe` varchar(255) COMMENT '',
340         `baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
341         `gsid` int unsigned COMMENT 'Global Server ID',
342         `generator` varchar(255) COMMENT 'Name of the contact\'s system',
343         `following_count` int unsigned DEFAULT 0 COMMENT 'Number of following contacts',
344         `followers_count` int unsigned DEFAULT 0 COMMENT 'Number of followers',
345         `statuses_count` int unsigned DEFAULT 0 COMMENT 'Number of posts',
346         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
347          PRIMARY KEY(`url`),
348          INDEX `addr` (`addr`(32)),
349          INDEX `alias` (`alias`(190)),
350          INDEX `followers` (`followers`(190)),
351          INDEX `baseurl` (`baseurl`(190)),
352          INDEX `sharedinbox` (`sharedinbox`(190)),
353          INDEX `gsid` (`gsid`),
354         FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
355 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
356
357 --
358 -- TABLE attach
359 --
360 CREATE TABLE IF NOT EXISTS `attach` (
361         `id` int unsigned NOT NULL auto_increment COMMENT 'generated index',
362         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
363         `hash` varchar(64) NOT NULL DEFAULT '' COMMENT 'hash',
364         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'filename of original',
365         `filetype` varchar(64) NOT NULL DEFAULT '' COMMENT 'mimetype',
366         `filesize` int unsigned NOT NULL DEFAULT 0 COMMENT 'size in bytes',
367         `data` longblob NOT NULL COMMENT 'file data',
368         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
369         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
370         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>',
371         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
372         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
373         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
374         `backend-class` tinytext COMMENT 'Storage backend class',
375         `backend-ref` text COMMENT 'Storage backend data reference',
376          PRIMARY KEY(`id`),
377          INDEX `uid` (`uid`),
378         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
379 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='file attachments';
380
381 --
382 -- TABLE auth_codes
383 --
384 CREATE TABLE IF NOT EXISTS `auth_codes` (
385         `id` varchar(40) NOT NULL COMMENT '',
386         `client_id` varchar(20) NOT NULL DEFAULT '' COMMENT '',
387         `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '',
388         `expires` int NOT NULL DEFAULT 0 COMMENT '',
389         `scope` varchar(250) NOT NULL DEFAULT '' COMMENT '',
390          PRIMARY KEY(`id`),
391          INDEX `client_id` (`client_id`),
392         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE
393 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
394
395 --
396 -- TABLE cache
397 --
398 CREATE TABLE IF NOT EXISTS `cache` (
399         `k` varbinary(255) NOT NULL COMMENT 'cache key',
400         `v` mediumtext COMMENT 'cached serialized value',
401         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
402         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
403          PRIMARY KEY(`k`),
404          INDEX `k_expires` (`k`,`expires`)
405 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
406
407 --
408 -- TABLE challenge
409 --
410 CREATE TABLE IF NOT EXISTS `challenge` (
411         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
412         `challenge` varchar(255) NOT NULL DEFAULT '' COMMENT '',
413         `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
414         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
415         `type` varchar(255) NOT NULL DEFAULT '' COMMENT '',
416         `last_update` varchar(255) NOT NULL DEFAULT '' COMMENT '',
417          PRIMARY KEY(`id`)
418 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
419
420 --
421 -- TABLE config
422 --
423 CREATE TABLE IF NOT EXISTS `config` (
424         `id` int unsigned NOT NULL auto_increment COMMENT '',
425         `cat` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
426         `k` varbinary(50) NOT NULL DEFAULT '' COMMENT '',
427         `v` mediumtext COMMENT '',
428          PRIMARY KEY(`id`),
429          UNIQUE INDEX `cat_k` (`cat`,`k`)
430 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='main configuration storage';
431
432 --
433 -- TABLE contact-relation
434 --
435 CREATE TABLE IF NOT EXISTS `contact-relation` (
436         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact the related contact had interacted with',
437         `relation-cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'related contact who had interacted with the contact',
438         `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction',
439         `follow-updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last update of the contact relationship',
440         `follows` boolean NOT NULL DEFAULT '0' COMMENT '',
441          PRIMARY KEY(`cid`,`relation-cid`),
442          INDEX `relation-cid` (`relation-cid`),
443         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
444         FOREIGN KEY (`relation-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
445 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Contact relations';
446
447 --
448 -- TABLE conv
449 --
450 CREATE TABLE IF NOT EXISTS `conv` (
451         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
452         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this conversation',
453         `recips` text COMMENT 'sender_handle;recipient_handle',
454         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
455         `creator` varchar(255) NOT NULL DEFAULT '' COMMENT 'handle of creator',
456         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation timestamp',
457         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'edited timestamp',
458         `subject` text COMMENT 'subject of initial message',
459          PRIMARY KEY(`id`),
460          INDEX `uid` (`uid`),
461         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
462 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
463
464 --
465 -- TABLE conversation
466 --
467 CREATE TABLE IF NOT EXISTS `conversation` (
468         `item-uri` varbinary(255) NOT NULL COMMENT 'Original URI of the item - unrelated to the table with the same name',
469         `reply-to-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'URI to which this item is a reply',
470         `conversation-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation URI',
471         `conversation-href` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation link',
472         `protocol` tinyint unsigned NOT NULL DEFAULT 255 COMMENT 'The protocol of the item',
473         `direction` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'How the message arrived here: 1=push, 2=pull',
474         `source` mediumtext COMMENT 'Original source',
475         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Receiving date',
476          PRIMARY KEY(`item-uri`),
477          INDEX `conversation-uri` (`conversation-uri`),
478          INDEX `received` (`received`)
479 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Raw data and structure information for messages';
480
481 --
482 -- TABLE delayed-post
483 --
484 CREATE TABLE IF NOT EXISTS `delayed-post` (
485         `id` int unsigned NOT NULL auto_increment,
486         `uri` varchar(255) COMMENT 'URI of the post that will be distributed later',
487         `uid` mediumint unsigned COMMENT 'Owner User id',
488         `delayed` datetime COMMENT 'delay time',
489          PRIMARY KEY(`id`),
490          UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
491         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
492 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be distributed at a later time';
493
494 --
495 -- TABLE diaspora-interaction
496 --
497 CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
498         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
499         `interaction` mediumtext COMMENT 'The Diaspora interaction',
500          PRIMARY KEY(`uri-id`),
501         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
502 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
503
504 --
505 -- TABLE event
506 --
507 CREATE TABLE IF NOT EXISTS `event` (
508         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
509         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
510         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
511         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact_id (ID of the contact in contact table)',
512         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
513         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
514         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
515         `start` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event start time',
516         `finish` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'event end time',
517         `summary` text COMMENT 'short description or title of the event',
518         `desc` text COMMENT 'event description',
519         `location` text COMMENT 'event location',
520         `type` varchar(20) NOT NULL DEFAULT '' COMMENT 'event or birthday',
521         `nofinish` boolean NOT NULL DEFAULT '0' COMMENT 'if event does have no end this is 1',
522         `adjust` boolean NOT NULL DEFAULT '1' COMMENT 'adjust to timezone of the recipient (0 or 1)',
523         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '0 or 1',
524         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
525         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
526         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
527         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
528          PRIMARY KEY(`id`),
529          INDEX `uid_start` (`uid`,`start`),
530          INDEX `cid` (`cid`),
531         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
532         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
533 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events';
534
535 --
536 -- TABLE fcontact
537 --
538 CREATE TABLE IF NOT EXISTS `fcontact` (
539         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
540         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id',
541         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
542         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
543         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
544         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
545         `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
546         `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
547         `batch` varchar(255) NOT NULL DEFAULT '' COMMENT '',
548         `notify` varchar(255) NOT NULL DEFAULT '' COMMENT '',
549         `poll` varchar(255) NOT NULL DEFAULT '' COMMENT '',
550         `confirm` varchar(255) NOT NULL DEFAULT '' COMMENT '',
551         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
552         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
553         `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
554         `pubkey` text COMMENT '',
555         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
556          PRIMARY KEY(`id`),
557          INDEX `addr` (`addr`(32)),
558          UNIQUE INDEX `url` (`url`(190))
559 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
560
561 --
562 -- TABLE fsuggest
563 --
564 CREATE TABLE IF NOT EXISTS `fsuggest` (
565         `id` int unsigned NOT NULL auto_increment COMMENT '',
566         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
567         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
568         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
569         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
570         `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
571         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
572         `note` text COMMENT '',
573         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
574          PRIMARY KEY(`id`),
575          INDEX `cid` (`cid`),
576          INDEX `uid` (`uid`),
577         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
578         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
579 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff';
580
581 --
582 -- TABLE group
583 --
584 CREATE TABLE IF NOT EXISTS `group` (
585         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
586         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
587         `visible` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the member list is not private',
588         `deleted` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the group has been deleted',
589         `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'human readable name of group',
590          PRIMARY KEY(`id`),
591          INDEX `uid` (`uid`),
592         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
593 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, group info';
594
595 --
596 -- TABLE group_member
597 --
598 CREATE TABLE IF NOT EXISTS `group_member` (
599         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
600         `gid` int unsigned NOT NULL DEFAULT 0 COMMENT 'groups.id of the associated group',
601         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id of the member assigned to the associated group',
602          PRIMARY KEY(`id`),
603          INDEX `contactid` (`contact-id`),
604          UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`),
605         FOREIGN KEY (`gid`) REFERENCES `group` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
606         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
607 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, member info';
608
609 --
610 -- TABLE gserver-tag
611 --
612 CREATE TABLE IF NOT EXISTS `gserver-tag` (
613         `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
614         `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
615          PRIMARY KEY(`gserver-id`,`tag`),
616          INDEX `tag` (`tag`),
617         FOREIGN KEY (`gserver-id`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
618 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Tags that the server has subscribed';
619
620 --
621 -- TABLE hook
622 --
623 CREATE TABLE IF NOT EXISTS `hook` (
624         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
625         `hook` varbinary(100) NOT NULL DEFAULT '' COMMENT 'name of hook',
626         `file` varbinary(200) NOT NULL DEFAULT '' COMMENT 'relative filename of hook handler',
627         `function` varbinary(200) NOT NULL DEFAULT '' COMMENT 'function name of hook handler',
628         `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',
629          PRIMARY KEY(`id`),
630          UNIQUE INDEX `hook_file_function` (`hook`,`file`,`function`)
631 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='addon hook registry';
632
633 --
634 -- TABLE host
635 --
636 CREATE TABLE IF NOT EXISTS `host` (
637         `id` tinyint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
638         `name` varchar(128) NOT NULL DEFAULT '' COMMENT 'The hostname',
639          PRIMARY KEY(`id`),
640          UNIQUE INDEX `name` (`name`)
641 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Hostname';
642
643 --
644 -- TABLE inbox-status
645 --
646 CREATE TABLE IF NOT EXISTS `inbox-status` (
647         `url` varbinary(255) NOT NULL COMMENT 'URL of the inbox',
648         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date of this entry',
649         `success` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last successful delivery',
650         `failure` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last failed delivery',
651         `previous` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Previous delivery date',
652         `archive` boolean NOT NULL DEFAULT '0' COMMENT 'Is the inbox archived?',
653         `shared` boolean NOT NULL DEFAULT '0' COMMENT 'Is it a shared inbox?',
654          PRIMARY KEY(`url`)
655 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Status of ActivityPub inboxes';
656
657 --
658 -- TABLE intro
659 --
660 CREATE TABLE IF NOT EXISTS `intro` (
661         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
662         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
663         `fid` int unsigned COMMENT '',
664         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
665         `knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
666         `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
667         `note` text COMMENT '',
668         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
669         `datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
670         `blocked` boolean NOT NULL DEFAULT '1' COMMENT '',
671         `ignore` boolean NOT NULL DEFAULT '0' COMMENT '',
672          PRIMARY KEY(`id`),
673          INDEX `contact-id` (`contact-id`),
674          INDEX `uid` (`uid`),
675         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
676         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
677 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
678
679 --
680 -- TABLE item
681 --
682 CREATE TABLE IF NOT EXISTS `item` (
683         `id` int unsigned NOT NULL auto_increment,
684         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this item',
685         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
686         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri',
687         `parent` int unsigned 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',
688         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT 'uri of the top-level parent to this item',
689         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the top-level parent uri',
690         `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',
691         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
692         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
693         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
694         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last comment/reply to this item',
695         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
696         `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',
697         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
698         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
699         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
700         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
701         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
702         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
703         `extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
704         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
705         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
706         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
707         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
708         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
709         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
710         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
711         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
712         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
713         `psid` int unsigned COMMENT 'ID of the permission set of this post',
714         `starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
715         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
716         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
717         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
718         `event-id` int unsigned COMMENT 'Used to link to the event.id',
719         `mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
720         `bookmark` boolean COMMENT 'Deprecated',
721         `type` varchar(20) COMMENT 'Deprecated',
722         `moderated` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
723         `resource-id` varchar(32) COMMENT 'Deprecated',
724         `uri-hash` varchar(80) COMMENT 'Deprecated',
725         `iaid` int unsigned COMMENT 'Deprecated',
726         `icid` int unsigned COMMENT 'Deprecated',
727         `attach` mediumtext COMMENT 'Deprecated',
728         `allow_cid` mediumtext COMMENT 'Deprecated',
729         `allow_gid` mediumtext COMMENT 'Deprecated',
730         `deny_cid` mediumtext COMMENT 'Deprecated',
731         `deny_gid` mediumtext COMMENT 'Deprecated',
732         `postopts` text COMMENT 'Deprecated',
733         `inform` mediumtext COMMENT 'Deprecated',
734         `file` mediumtext COMMENT 'Deprecated',
735         `location` varchar(255) COMMENT 'Deprecated',
736         `coord` varchar(255) COMMENT 'Deprecated',
737         `tag` mediumtext COMMENT 'Deprecated',
738         `plink` varchar(255) COMMENT 'Deprecated',
739         `title` varchar(255) COMMENT 'Deprecated',
740         `content-warning` varchar(255) COMMENT 'Deprecated',
741         `body` mediumtext COMMENT 'Deprecated',
742         `app` varchar(255) COMMENT 'Deprecated',
743         `verb` varchar(100) COMMENT 'Deprecated',
744         `object-type` varchar(100) COMMENT 'Deprecated',
745         `object` text COMMENT 'Deprecated',
746         `target-type` varchar(100) COMMENT 'Deprecated',
747         `target` text COMMENT 'Deprecated',
748         `author-name` varchar(255) COMMENT 'Deprecated',
749         `author-link` varchar(255) COMMENT 'Deprecated',
750         `author-avatar` varchar(255) COMMENT 'Deprecated',
751         `owner-name` varchar(255) COMMENT 'Deprecated',
752         `owner-link` varchar(255) COMMENT 'Deprecated',
753         `owner-avatar` varchar(255) COMMENT 'Deprecated',
754         `rendered-hash` varchar(32) COMMENT 'Deprecated',
755         `rendered-html` mediumtext COMMENT 'Deprecated',
756          PRIMARY KEY(`id`),
757          INDEX `guid` (`guid`(191)),
758          INDEX `uri` (`uri`(191)),
759          INDEX `parent` (`parent`),
760          INDEX `parent-uri` (`parent-uri`(191)),
761          INDEX `extid` (`extid`(191)),
762          INDEX `uid_id` (`uid`,`id`),
763          INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
764          INDEX `uid_received` (`uid`,`received`),
765          INDEX `uid_commented` (`uid`,`commented`),
766          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
767          INDEX `uid_network_received` (`uid`,`network`,`received`),
768          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
769          INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
770          INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
771          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
772          INDEX `authorid_received` (`author-id`,`received`),
773          INDEX `ownerid` (`owner-id`),
774          INDEX `contact-id` (`contact-id`),
775          INDEX `uid_uri` (`uid`,`uri`(190)),
776          INDEX `resource-id` (`resource-id`),
777          INDEX `deleted_changed` (`deleted`,`changed`),
778          INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
779          INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
780          INDEX `mention_uid_id` (`mention`,`uid`,`id`),
781          INDEX `uid_eventid` (`uid`,`event-id`),
782          INDEX `vid` (`vid`),
783          INDEX `psid_wall` (`psid`,`wall`),
784          INDEX `uri-id` (`uri-id`),
785          INDEX `parent-uri-id` (`parent-uri-id`),
786          INDEX `thr-parent-id` (`thr-parent-id`),
787          INDEX `causer-id` (`causer-id`),
788         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
789         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
790         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
791         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
792         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
793         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
794         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
795         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
796         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
797         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
798 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
799
800 --
801 -- TABLE locks
802 --
803 CREATE TABLE IF NOT EXISTS `locks` (
804         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
805         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
806         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
807         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
808         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
809          PRIMARY KEY(`id`),
810          INDEX `name_expires` (`name`,`expires`)
811 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
812
813 --
814 -- TABLE mail
815 --
816 CREATE TABLE IF NOT EXISTS `mail` (
817         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
818         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
819         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
820         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
821         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
822         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
823         `contact-id` varchar(255) COMMENT 'contact.id',
824         `convid` int unsigned COMMENT 'conv.id',
825         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
826         `body` mediumtext COMMENT '',
827         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
828         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
829         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
830         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
831         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
832         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
833         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
834          PRIMARY KEY(`id`),
835          INDEX `uid_seen` (`uid`,`seen`),
836          INDEX `convid` (`convid`),
837          INDEX `uri` (`uri`(64)),
838          INDEX `parent-uri` (`parent-uri`(64)),
839          INDEX `contactid` (`contact-id`(32)),
840         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
841 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
842
843 --
844 -- TABLE mailacct
845 --
846 CREATE TABLE IF NOT EXISTS `mailacct` (
847         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
848         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
849         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
850         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
851         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
852         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
853         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
854         `pass` text COMMENT '',
855         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
856         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
857         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
858         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
859         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
860          PRIMARY KEY(`id`),
861          INDEX `uid` (`uid`),
862         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
863 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
864
865 --
866 -- TABLE manage
867 --
868 CREATE TABLE IF NOT EXISTS `manage` (
869         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
870         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
871         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
872          PRIMARY KEY(`id`),
873          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
874          INDEX `mid` (`mid`),
875         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
876         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
877 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
878
879 --
880 -- TABLE notify
881 --
882 CREATE TABLE IF NOT EXISTS `notify` (
883         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
884         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
885         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
886         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
887         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
888         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
889         `msg` mediumtext COMMENT '',
890         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
891         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
892         `iid` int unsigned COMMENT 'item.id',
893         `parent` int unsigned COMMENT '',
894         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
895         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
896         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
897         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
898         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
899         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
900         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
901          PRIMARY KEY(`id`),
902          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
903          INDEX `uid_date` (`uid`,`date`),
904          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
905          INDEX `uri-id` (`uri-id`),
906          INDEX `parent-uri-id` (`parent-uri-id`),
907         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
908         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
909         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
910 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
911
912 --
913 -- TABLE notify-threads
914 --
915 CREATE TABLE IF NOT EXISTS `notify-threads` (
916         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
917         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
918         `master-parent-item` int unsigned COMMENT '',
919         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
920         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
921         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
922          PRIMARY KEY(`id`),
923          INDEX `master-parent-item` (`master-parent-item`),
924          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
925          INDEX `receiver-uid` (`receiver-uid`),
926          INDEX `notify-id` (`notify-id`),
927         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
928         FOREIGN KEY (`master-parent-item`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
929         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
930         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
931 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
932
933 --
934 -- TABLE oembed
935 --
936 CREATE TABLE IF NOT EXISTS `oembed` (
937         `url` varbinary(255) NOT NULL COMMENT 'page url',
938         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
939         `content` mediumtext COMMENT 'OEmbed data of the page',
940         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
941          PRIMARY KEY(`url`,`maxwidth`),
942          INDEX `created` (`created`)
943 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
944
945 --
946 -- TABLE openwebauth-token
947 --
948 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
949         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
950         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
951         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
952         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
953         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
954         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
955          PRIMARY KEY(`id`),
956          INDEX `uid` (`uid`),
957         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
958 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
959
960 --
961 -- TABLE parsed_url
962 --
963 CREATE TABLE IF NOT EXISTS `parsed_url` (
964         `url` varbinary(255) NOT NULL COMMENT 'page url',
965         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
966         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
967         `content` mediumtext COMMENT 'page data',
968         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
969          PRIMARY KEY(`url`,`guessing`,`oembed`),
970          INDEX `created` (`created`)
971 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
972
973 --
974 -- TABLE pconfig
975 --
976 CREATE TABLE IF NOT EXISTS `pconfig` (
977         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
978         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
979         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
980         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
981         `v` mediumtext COMMENT 'Value',
982          PRIMARY KEY(`id`),
983          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
984         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
985 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
986
987 --
988 -- TABLE photo
989 --
990 CREATE TABLE IF NOT EXISTS `photo` (
991         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
992         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
993         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
994         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
995         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
996         `hash` char(32) COMMENT 'hash value of the photo',
997         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
998         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
999         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1000         `desc` text COMMENT '',
1001         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
1002         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1003         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
1004         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1005         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
1006         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1007         `data` mediumblob NOT NULL COMMENT '',
1008         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1009         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
1010         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
1011         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
1012         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
1013         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
1014         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
1015         `backend-class` tinytext COMMENT 'Storage backend class',
1016         `backend-ref` text COMMENT 'Storage backend data reference',
1017         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1018          PRIMARY KEY(`id`),
1019          INDEX `contactid` (`contact-id`),
1020          INDEX `uid_contactid` (`uid`,`contact-id`),
1021          INDEX `uid_profile` (`uid`,`profile`),
1022          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
1023          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
1024          INDEX `resource-id` (`resource-id`),
1025         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1026         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1027 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1028
1029 --
1030 -- TABLE post
1031 --
1032 CREATE TABLE IF NOT EXISTS `post` (
1033         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1034         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1035         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1036         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1037         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1038         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1039         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1040         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1041         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1042         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1043         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1044         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1045         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
1046         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1047         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1048         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1049         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1050         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1051          PRIMARY KEY(`uri-id`),
1052          INDEX `parent-uri-id` (`parent-uri-id`),
1053          INDEX `thr-parent-id` (`thr-parent-id`),
1054          INDEX `external-id` (`external-id`),
1055          INDEX `owner-id` (`owner-id`),
1056          INDEX `author-id` (`author-id`),
1057          INDEX `causer-id` (`causer-id`),
1058          INDEX `vid` (`vid`),
1059          INDEX `received` (`received`),
1060         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1061         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1062         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1063         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1064         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1065         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1066         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1067         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1068 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
1069
1070 --
1071 -- TABLE post-category
1072 --
1073 CREATE TABLE IF NOT EXISTS `post-category` (
1074         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1075         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1076         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1077         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1078          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1079          INDEX `uri-id` (`tid`),
1080          INDEX `uid` (`uid`),
1081         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1082         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1083         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1084 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1085
1086 --
1087 -- TABLE post-content
1088 --
1089 CREATE TABLE IF NOT EXISTS `post-content` (
1090         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1091         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1092         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1093         `body` mediumtext COMMENT 'item body content',
1094         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1095         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1096         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1097         `language` text COMMENT 'Language information about this post',
1098         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1099         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1100         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1101         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1102         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1103         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1104         `target` text COMMENT 'JSON encoded target structure if used',
1105         `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',
1106         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1107          PRIMARY KEY(`uri-id`),
1108          INDEX `plink` (`plink`(191)),
1109          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1110         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1111 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1112
1113 --
1114 -- TABLE post-delivery-data
1115 --
1116 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1117         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1118         `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',
1119         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1120         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1121         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1122         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1123         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1124         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1125         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1126         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1127         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1128          PRIMARY KEY(`uri-id`),
1129         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1130 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1131
1132 --
1133 -- TABLE post-media
1134 --
1135 CREATE TABLE IF NOT EXISTS `post-media` (
1136         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1137         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1138         `url` varbinary(511) NOT NULL COMMENT 'Media URL',
1139         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1140         `mimetype` varchar(60) COMMENT '',
1141         `height` smallint unsigned COMMENT 'Height of the media',
1142         `width` smallint unsigned COMMENT 'Width of the media',
1143         `size` int unsigned COMMENT 'Media size',
1144         `preview` varbinary(255) COMMENT 'Preview URL',
1145         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1146         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1147         `description` text COMMENT '',
1148          PRIMARY KEY(`id`),
1149          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1150         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1151 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1152
1153 --
1154 -- TABLE post-tag
1155 --
1156 CREATE TABLE IF NOT EXISTS `post-tag` (
1157         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1158         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1159         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1160         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1161          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1162          INDEX `tid` (`tid`),
1163          INDEX `cid` (`cid`),
1164         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1165         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1166         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1167 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1168
1169 --
1170 -- TABLE post-thread
1171 --
1172 CREATE TABLE IF NOT EXISTS `post-thread` (
1173         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1174         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1175         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1176         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1177         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1178         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1179         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1180         `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',
1181         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1182          PRIMARY KEY(`uri-id`),
1183          INDEX `owner-id` (`owner-id`),
1184          INDEX `author-id` (`author-id`),
1185          INDEX `causer-id` (`causer-id`),
1186          INDEX `received` (`received`),
1187          INDEX `commented` (`commented`),
1188          INDEX `changed` (`changed`),
1189         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1190         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1191         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1192         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1193 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1194
1195 --
1196 -- TABLE post-user
1197 --
1198 CREATE TABLE IF NOT EXISTS `post-user` (
1199         `id` int unsigned NOT NULL auto_increment,
1200         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1201         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1202         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1203         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1204         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1205         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1206         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1207         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1208         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1209         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1210         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1211         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1212         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
1213         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1214         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1215         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1216         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1217         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1218         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1219         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1220         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1221         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1222         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1223         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1224         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1225         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1226         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1227         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1228          PRIMARY KEY(`id`),
1229          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1230          INDEX `uri-id` (`uri-id`),
1231          INDEX `contact-id` (`contact-id`),
1232          INDEX `psid` (`psid`),
1233          INDEX `uid_hidden` (`uid`,`hidden`),
1234          INDEX `event-id` (`event-id`),
1235          INDEX `uid_wall` (`uid`,`wall`),
1236          INDEX `parent-uri-id` (`parent-uri-id`),
1237          INDEX `thr-parent-id` (`thr-parent-id`),
1238          INDEX `external-id` (`external-id`),
1239          INDEX `owner-id` (`owner-id`),
1240          INDEX `author-id` (`author-id`),
1241          INDEX `causer-id` (`causer-id`),
1242          INDEX `vid` (`vid`),
1243          INDEX `uid_received` (`uid`,`received`),
1244          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1245          INDEX `uid_network_received` (`uid`,`network`,`received`),
1246          INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
1247          INDEX `authorid_received` (`author-id`,`received`),
1248          INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
1249          INDEX `uid_eventid` (`uid`,`event-id`),
1250          INDEX `psid_wall` (`psid`,`wall`),
1251         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1252         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1253         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1254         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1255         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1256         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1257         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1258         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1259         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1260         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1261         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1262         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1263 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1264
1265 --
1266 -- TABLE post-thread-user
1267 --
1268 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1269         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1270         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1271         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1272         `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1273         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1274         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1275         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1276         `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',
1277         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1278         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1279         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'The thread is pinned on the profile page',
1280         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1281         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1282         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1283         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1284         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1285         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1286         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1287         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1288         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1289         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1290         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1291         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1292          PRIMARY KEY(`uid`,`uri-id`),
1293          INDEX `uid_wall` (`uid`,`wall`),
1294          INDEX `uid_pinned` (`uid`,`pinned`),
1295          INDEX `uri-id` (`uri-id`),
1296          INDEX `contact-id` (`contact-id`),
1297          INDEX `psid` (`psid`),
1298          INDEX `post-user-id` (`post-user-id`),
1299          INDEX `owner-id` (`owner-id`),
1300          INDEX `causer-id` (`causer-id`),
1301          INDEX `uid_received` (`uid`,`received`),
1302          INDEX `uid_commented` (`uid`,`commented`),
1303          INDEX `uid_changed` (`uid`,`changed`),
1304          INDEX `uid_contact-id` (`uid`,`contact-id`,`received`),
1305          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1306          INDEX `uid_network_received` (`uid`,`network`,`received`),
1307          INDEX `uid_network_commented` (`uid`,`network`,`commented`),
1308          INDEX `uid_contact-id_received` (`uid`,`contact-id`,`received`),
1309          INDEX `author-id_received` (`author-id`,`received`),
1310          INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
1311          INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
1312          INDEX `mention_uid` (`mention`,`uid`),
1313          INDEX `psid_wall` (`psid`,`wall`),
1314          INDEX `received` (`received`),
1315          INDEX `commented` (`commented`),
1316          INDEX `changed` (`changed`),
1317         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1318         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1319         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1320         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1321         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1322         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1323         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1324         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1325 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1326
1327 --
1328 -- TABLE post-user-notification
1329 --
1330 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1331         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1332         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1333         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1334          PRIMARY KEY(`uid`,`uri-id`),
1335          INDEX `uri-id` (`uri-id`),
1336         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1337         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1338 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1339
1340 --
1341 -- TABLE process
1342 --
1343 CREATE TABLE IF NOT EXISTS `process` (
1344         `pid` int unsigned NOT NULL COMMENT '',
1345         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1346         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1347          PRIMARY KEY(`pid`),
1348          INDEX `command` (`command`)
1349 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1350
1351 --
1352 -- TABLE profile
1353 --
1354 CREATE TABLE IF NOT EXISTS `profile` (
1355         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1356         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1357         `profile-name` varchar(255) COMMENT 'Deprecated',
1358         `is-default` boolean COMMENT 'Deprecated',
1359         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1360         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1361         `pdesc` varchar(255) COMMENT 'Deprecated',
1362         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1363         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1364         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1365         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1366         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1367         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1368         `hometown` varchar(255) COMMENT 'Deprecated',
1369         `gender` varchar(32) COMMENT 'Deprecated',
1370         `marital` varchar(255) COMMENT 'Deprecated',
1371         `with` text COMMENT 'Deprecated',
1372         `howlong` datetime COMMENT 'Deprecated',
1373         `sexual` varchar(255) COMMENT 'Deprecated',
1374         `politic` varchar(255) COMMENT 'Deprecated',
1375         `religion` varchar(255) COMMENT 'Deprecated',
1376         `pub_keywords` text COMMENT '',
1377         `prv_keywords` text COMMENT '',
1378         `likes` text COMMENT 'Deprecated',
1379         `dislikes` text COMMENT 'Deprecated',
1380         `about` text COMMENT 'Profile description',
1381         `summary` varchar(255) COMMENT 'Deprecated',
1382         `music` text COMMENT 'Deprecated',
1383         `book` text COMMENT 'Deprecated',
1384         `tv` text COMMENT 'Deprecated',
1385         `film` text COMMENT 'Deprecated',
1386         `interest` text COMMENT 'Deprecated',
1387         `romance` text COMMENT 'Deprecated',
1388         `work` text COMMENT 'Deprecated',
1389         `education` text COMMENT 'Deprecated',
1390         `contact` text COMMENT 'Deprecated',
1391         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1392         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1393         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1394         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1395         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1396         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1397          PRIMARY KEY(`id`),
1398          INDEX `uid_is-default` (`uid`,`is-default`),
1399          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1400         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1401 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1402
1403 --
1404 -- TABLE profile_check
1405 --
1406 CREATE TABLE IF NOT EXISTS `profile_check` (
1407         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1408         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1409         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1410         `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1411         `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1412         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1413          PRIMARY KEY(`id`),
1414          INDEX `uid` (`uid`),
1415          INDEX `cid` (`cid`),
1416         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1417         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1418 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use';
1419
1420 --
1421 -- TABLE profile_field
1422 --
1423 CREATE TABLE IF NOT EXISTS `profile_field` (
1424         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1425         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1426         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1427         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1428         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1429         `value` text COMMENT 'Value of the field',
1430         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1431         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1432          PRIMARY KEY(`id`),
1433          INDEX `uid` (`uid`),
1434          INDEX `order` (`order`),
1435          INDEX `psid` (`psid`),
1436         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1437         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1438 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1439
1440 --
1441 -- TABLE push_subscriber
1442 --
1443 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1444         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1445         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1446         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1447         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1448         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1449         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1450         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1451         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1452         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1453         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1454          PRIMARY KEY(`id`),
1455          INDEX `next_try` (`next_try`),
1456          INDEX `uid` (`uid`),
1457         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1458 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1459
1460 --
1461 -- TABLE register
1462 --
1463 CREATE TABLE IF NOT EXISTS `register` (
1464         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1465         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1466         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1467         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1468         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1469         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1470         `note` text COMMENT '',
1471          PRIMARY KEY(`id`),
1472          INDEX `uid` (`uid`),
1473         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1474 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1475
1476 --
1477 -- TABLE search
1478 --
1479 CREATE TABLE IF NOT EXISTS `search` (
1480         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1481         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1482         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1483          PRIMARY KEY(`id`),
1484          INDEX `uid` (`uid`),
1485         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1486 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1487
1488 --
1489 -- TABLE session
1490 --
1491 CREATE TABLE IF NOT EXISTS `session` (
1492         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1493         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1494         `data` text COMMENT '',
1495         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1496          PRIMARY KEY(`id`),
1497          INDEX `sid` (`sid`(64)),
1498          INDEX `expire` (`expire`)
1499 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1500
1501 --
1502 -- TABLE storage
1503 --
1504 CREATE TABLE IF NOT EXISTS `storage` (
1505         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1506         `data` longblob NOT NULL COMMENT 'file data',
1507          PRIMARY KEY(`id`)
1508 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1509
1510 --
1511 -- TABLE tokens
1512 --
1513 CREATE TABLE IF NOT EXISTS `tokens` (
1514         `id` varchar(40) NOT NULL COMMENT '',
1515         `secret` text COMMENT '',
1516         `client_id` varchar(20) NOT NULL DEFAULT '',
1517         `expires` int NOT NULL DEFAULT 0 COMMENT '',
1518         `scope` varchar(200) NOT NULL DEFAULT '' COMMENT '',
1519         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1520          PRIMARY KEY(`id`),
1521          INDEX `client_id` (`client_id`),
1522          INDEX `uid` (`uid`),
1523         FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1524         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1525 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage';
1526
1527 --
1528 -- TABLE userd
1529 --
1530 CREATE TABLE IF NOT EXISTS `userd` (
1531         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1532         `username` varchar(255) NOT NULL COMMENT '',
1533          PRIMARY KEY(`id`),
1534          INDEX `username` (`username`(32))
1535 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1536
1537 --
1538 -- TABLE user-contact
1539 --
1540 CREATE TABLE IF NOT EXISTS `user-contact` (
1541         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1542         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1543         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1544         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1545         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1546          PRIMARY KEY(`uid`,`cid`),
1547          INDEX `cid` (`cid`),
1548         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1549         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1550 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1551
1552 --
1553 -- TABLE worker-ipc
1554 --
1555 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1556         `key` int NOT NULL COMMENT '',
1557         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1558          PRIMARY KEY(`key`)
1559 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1560
1561 --
1562 -- TABLE workerqueue
1563 --
1564 CREATE TABLE IF NOT EXISTS `workerqueue` (
1565         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
1566         `command` varchar(100) COMMENT 'Task command',
1567         `parameter` mediumtext COMMENT 'Task parameter',
1568         `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority',
1569         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
1570         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
1571         `executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
1572         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1573         `retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1574         `done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
1575          PRIMARY KEY(`id`),
1576          INDEX `command` (`command`),
1577          INDEX `done_command_parameter` (`done`,`command`,`parameter`(64)),
1578          INDEX `done_executed` (`done`,`executed`),
1579          INDEX `done_priority_retrial_created` (`done`,`priority`,`retrial`,`created`),
1580          INDEX `done_priority_next_try` (`done`,`priority`,`next_try`),
1581          INDEX `done_pid_next_try` (`done`,`pid`,`next_try`),
1582          INDEX `done_pid_retrial` (`done`,`pid`,`retrial`),
1583          INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`)
1584 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';
1585
1586 --
1587 -- VIEW post-view
1588 --
1589 DROP VIEW IF EXISTS `post-view`;
1590 CREATE VIEW `post-view` AS SELECT 
1591         `item`.`id` AS `id`,
1592         `item`.`id` AS `item-id`,
1593         `post-user`.`id` AS `post-user-id`,
1594         `post-user`.`uid` AS `uid`,
1595         `item`.`parent` AS `parent`,
1596         `parent-post`.`id` AS `parent-user-id`,
1597         `item-uri`.`uri` AS `uri`,
1598         `post-user`.`uri-id` AS `uri-id`,
1599         `parent-item-uri`.`uri` AS `parent-uri`,
1600         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1601         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1602         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1603         `item-uri`.`guid` AS `guid`,
1604         `post-user`.`wall` AS `wall`,
1605         `post-user`.`gravity` AS `gravity`,
1606         `external-item-uri`.`uri` AS `extid`,
1607         `post-user`.`external-id` AS `external-id`,
1608         `post-user`.`created` AS `created`,
1609         `post-user`.`edited` AS `edited`,
1610         `post-thread-user`.`commented` AS `commented`,
1611         `post-user`.`received` AS `received`,
1612         `post-thread-user`.`changed` AS `changed`,
1613         `post-user`.`post-type` AS `post-type`,
1614         `post-user`.`private` AS `private`,
1615         `post-thread-user`.`pubmail` AS `pubmail`,
1616         `post-user`.`visible` AS `visible`,
1617         `post-thread-user`.`starred` AS `starred`,
1618         `post-user`.`unseen` AS `unseen`,
1619         `post-user`.`deleted` AS `deleted`,
1620         `post-user`.`origin` AS `origin`,
1621         `post-thread-user`.`forum_mode` AS `forum_mode`,
1622         `post-thread-user`.`mention` AS `mention`,
1623         `post-user`.`global` AS `global`,
1624         `post-user`.`network` AS `network`,
1625         `post-user`.`vid` AS `vid`,
1626         `post-user`.`psid` AS `psid`,
1627         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1628         `post-content`.`title` AS `title`,
1629         `post-content`.`content-warning` AS `content-warning`,
1630         `post-content`.`raw-body` AS `raw-body`,
1631         `post-content`.`body` AS `body`,
1632         `post-content`.`rendered-hash` AS `rendered-hash`,
1633         `post-content`.`rendered-html` AS `rendered-html`,
1634         `post-content`.`language` AS `language`,
1635         `post-content`.`plink` AS `plink`,
1636         `post-content`.`location` AS `location`,
1637         `post-content`.`coord` AS `coord`,
1638         `post-content`.`app` AS `app`,
1639         `post-content`.`object-type` AS `object-type`,
1640         `post-content`.`object` AS `object`,
1641         `post-content`.`target-type` AS `target-type`,
1642         `post-content`.`target` AS `target`,
1643         `post-content`.`resource-id` AS `resource-id`,
1644         `post-user`.`contact-id` AS `contact-id`,
1645         `contact`.`url` AS `contact-link`,
1646         `contact`.`addr` AS `contact-addr`,
1647         `contact`.`name` AS `contact-name`,
1648         `contact`.`nick` AS `contact-nick`,
1649         `contact`.`thumb` AS `contact-avatar`,
1650         `contact`.`network` AS `contact-network`,
1651         `contact`.`blocked` AS `contact-blocked`,
1652         `contact`.`hidden` AS `contact-hidden`,
1653         `contact`.`readonly` AS `contact-readonly`,
1654         `contact`.`archive` AS `contact-archive`,
1655         `contact`.`pending` AS `contact-pending`,
1656         `contact`.`rel` AS `contact-rel`,
1657         `contact`.`uid` AS `contact-uid`,
1658         `contact`.`contact-type` AS `contact-contact-type`,
1659         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1660         `contact`.`self` AS `self`,
1661         `contact`.`id` AS `cid`,
1662         `contact`.`alias` AS `alias`,
1663         `contact`.`photo` AS `photo`,
1664         `contact`.`name-date` AS `name-date`,
1665         `contact`.`uri-date` AS `uri-date`,
1666         `contact`.`avatar-date` AS `avatar-date`,
1667         `contact`.`thumb` AS `thumb`,
1668         `contact`.`dfrn-id` AS `dfrn-id`,
1669         `post-user`.`author-id` AS `author-id`,
1670         `author`.`url` AS `author-link`,
1671         `author`.`addr` AS `author-addr`,
1672         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1673         `author`.`nick` AS `author-nick`,
1674         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1675         `author`.`network` AS `author-network`,
1676         `author`.`blocked` AS `author-blocked`,
1677         `author`.`hidden` AS `author-hidden`,
1678         `post-user`.`owner-id` AS `owner-id`,
1679         `owner`.`url` AS `owner-link`,
1680         `owner`.`addr` AS `owner-addr`,
1681         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1682         `owner`.`nick` AS `owner-nick`,
1683         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1684         `owner`.`network` AS `owner-network`,
1685         `owner`.`blocked` AS `owner-blocked`,
1686         `owner`.`hidden` AS `owner-hidden`,
1687         `post-user`.`causer-id` AS `causer-id`,
1688         `causer`.`url` AS `causer-link`,
1689         `causer`.`addr` AS `causer-addr`,
1690         `causer`.`name` AS `causer-name`,
1691         `causer`.`nick` AS `causer-nick`,
1692         `causer`.`thumb` AS `causer-avatar`,
1693         `causer`.`network` AS `causer-network`,
1694         `causer`.`blocked` AS `causer-blocked`,
1695         `causer`.`hidden` AS `causer-hidden`,
1696         `causer`.`contact-type` AS `causer-contact-type`,
1697         `post-delivery-data`.`postopts` AS `postopts`,
1698         `post-delivery-data`.`inform` AS `inform`,
1699         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1700         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1701         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1702         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1703         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1704         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1705         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1706         `post-user`.`event-id` AS `event-id`,
1707         `event`.`created` AS `event-created`,
1708         `event`.`edited` AS `event-edited`,
1709         `event`.`start` AS `event-start`,
1710         `event`.`finish` AS `event-finish`,
1711         `event`.`summary` AS `event-summary`,
1712         `event`.`desc` AS `event-desc`,
1713         `event`.`location` AS `event-location`,
1714         `event`.`type` AS `event-type`,
1715         `event`.`nofinish` AS `event-nofinish`,
1716         `event`.`adjust` AS `event-adjust`,
1717         `event`.`ignore` AS `event-ignore`,
1718         `diaspora-interaction`.`interaction` AS `signed_text`,
1719         `parent-item-uri`.`guid` AS `parent-guid`,
1720         `parent-post`.`network` AS `parent-network`,
1721         `parent-post`.`author-id` AS `parent-author-id`,
1722         `parent-post-author`.`url` AS `parent-author-link`,
1723         `parent-post-author`.`name` AS `parent-author-name`,
1724         `parent-post-author`.`network` AS `parent-author-network`
1725         FROM `post-user`
1726                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1727                         LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
1728                         INNER JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1729                         INNER JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1730                         INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1731                         INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1732                         INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1733                         INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1734                         INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1735                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1736                         INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1737                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1738                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1739                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1740                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1741                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1742                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1743                         INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1744
1745 --
1746 -- VIEW post-thread-view
1747 --
1748 DROP VIEW IF EXISTS `post-thread-view`;
1749 CREATE VIEW `post-thread-view` AS SELECT 
1750         `item`.`id` AS `id`,
1751         `item`.`id` AS `item-id`,
1752         `item`.`id` AS `iid`,
1753         `post-user`.`id` AS `post-user-id`,
1754         `post-thread-user`.`uid` AS `uid`,
1755         `item`.`parent` AS `parent`,
1756         `parent-post`.`id` AS `parent-user-id`,
1757         `item-uri`.`uri` AS `uri`,
1758         `post-thread-user`.`uri-id` AS `uri-id`,
1759         `parent-item-uri`.`uri` AS `parent-uri`,
1760         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1761         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1762         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1763         `item-uri`.`guid` AS `guid`,
1764         `post-thread-user`.`wall` AS `wall`,
1765         `post-user`.`gravity` AS `gravity`,
1766         `external-item-uri`.`uri` AS `extid`,
1767         `post-user`.`external-id` AS `external-id`,
1768         `post-thread-user`.`created` AS `created`,
1769         `post-user`.`edited` AS `edited`,
1770         `post-thread-user`.`commented` AS `commented`,
1771         `post-thread-user`.`received` AS `received`,
1772         `post-thread-user`.`changed` AS `changed`,
1773         `post-user`.`post-type` AS `post-type`,
1774         `post-user`.`private` AS `private`,
1775         `post-thread-user`.`pubmail` AS `pubmail`,
1776         `post-thread-user`.`ignored` AS `ignored`,
1777         `post-user`.`visible` AS `visible`,
1778         `post-thread-user`.`starred` AS `starred`,
1779         `post-thread-user`.`unseen` AS `unseen`,
1780         `post-user`.`deleted` AS `deleted`,
1781         `post-thread-user`.`origin` AS `origin`,
1782         `post-thread-user`.`forum_mode` AS `forum_mode`,
1783         `post-thread-user`.`mention` AS `mention`,
1784         `post-user`.`global` AS `global`,
1785         `post-thread-user`.`network` AS `network`,
1786         `post-user`.`vid` AS `vid`,
1787         `post-thread-user`.`psid` AS `psid`,
1788         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1789         `post-content`.`title` AS `title`,
1790         `post-content`.`content-warning` AS `content-warning`,
1791         `post-content`.`raw-body` AS `raw-body`,
1792         `post-content`.`body` AS `body`,
1793         `post-content`.`rendered-hash` AS `rendered-hash`,
1794         `post-content`.`rendered-html` AS `rendered-html`,
1795         `post-content`.`language` AS `language`,
1796         `post-content`.`plink` AS `plink`,
1797         `post-content`.`location` AS `location`,
1798         `post-content`.`coord` AS `coord`,
1799         `post-content`.`app` AS `app`,
1800         `post-content`.`object-type` AS `object-type`,
1801         `post-content`.`object` AS `object`,
1802         `post-content`.`target-type` AS `target-type`,
1803         `post-content`.`target` AS `target`,
1804         `post-content`.`resource-id` AS `resource-id`,
1805         `post-thread-user`.`contact-id` AS `contact-id`,
1806         `contact`.`url` AS `contact-link`,
1807         `contact`.`addr` AS `contact-addr`,
1808         `contact`.`name` AS `contact-name`,
1809         `contact`.`nick` AS `contact-nick`,
1810         `contact`.`thumb` AS `contact-avatar`,
1811         `contact`.`network` AS `contact-network`,
1812         `contact`.`blocked` AS `contact-blocked`,
1813         `contact`.`hidden` AS `contact-hidden`,
1814         `contact`.`readonly` AS `contact-readonly`,
1815         `contact`.`archive` AS `contact-archive`,
1816         `contact`.`pending` AS `contact-pending`,
1817         `contact`.`rel` AS `contact-rel`,
1818         `contact`.`uid` AS `contact-uid`,
1819         `contact`.`contact-type` AS `contact-contact-type`,
1820         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1821         `contact`.`self` AS `self`,
1822         `contact`.`id` AS `cid`,
1823         `contact`.`alias` AS `alias`,
1824         `contact`.`photo` AS `photo`,
1825         `contact`.`name-date` AS `name-date`,
1826         `contact`.`uri-date` AS `uri-date`,
1827         `contact`.`avatar-date` AS `avatar-date`,
1828         `contact`.`thumb` AS `thumb`,
1829         `contact`.`dfrn-id` AS `dfrn-id`,
1830         `post-thread-user`.`author-id` AS `author-id`,
1831         `author`.`url` AS `author-link`,
1832         `author`.`addr` AS `author-addr`,
1833         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1834         `author`.`nick` AS `author-nick`,
1835         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1836         `author`.`network` AS `author-network`,
1837         `author`.`blocked` AS `author-blocked`,
1838         `author`.`hidden` AS `author-hidden`,
1839         `post-thread-user`.`owner-id` AS `owner-id`,
1840         `owner`.`url` AS `owner-link`,
1841         `owner`.`addr` AS `owner-addr`,
1842         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1843         `owner`.`nick` AS `owner-nick`,
1844         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1845         `owner`.`network` AS `owner-network`,
1846         `owner`.`blocked` AS `owner-blocked`,
1847         `owner`.`hidden` AS `owner-hidden`,
1848         `post-thread-user`.`causer-id` AS `causer-id`,
1849         `causer`.`url` AS `causer-link`,
1850         `causer`.`addr` AS `causer-addr`,
1851         `causer`.`name` AS `causer-name`,
1852         `causer`.`nick` AS `causer-nick`,
1853         `causer`.`thumb` AS `causer-avatar`,
1854         `causer`.`network` AS `causer-network`,
1855         `causer`.`blocked` AS `causer-blocked`,
1856         `causer`.`hidden` AS `causer-hidden`,
1857         `causer`.`contact-type` AS `causer-contact-type`,
1858         `post-delivery-data`.`postopts` AS `postopts`,
1859         `post-delivery-data`.`inform` AS `inform`,
1860         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1861         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1862         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1863         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1864         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1865         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1866         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1867         `post-user`.`event-id` AS `event-id`,
1868         `event`.`created` AS `event-created`,
1869         `event`.`edited` AS `event-edited`,
1870         `event`.`start` AS `event-start`,
1871         `event`.`finish` AS `event-finish`,
1872         `event`.`summary` AS `event-summary`,
1873         `event`.`desc` AS `event-desc`,
1874         `event`.`location` AS `event-location`,
1875         `event`.`type` AS `event-type`,
1876         `event`.`nofinish` AS `event-nofinish`,
1877         `event`.`adjust` AS `event-adjust`,
1878         `event`.`ignore` AS `event-ignore`,
1879         `diaspora-interaction`.`interaction` AS `signed_text`,
1880         `parent-item-uri`.`guid` AS `parent-guid`,
1881         `parent-post`.`network` AS `parent-network`,
1882         `parent-post`.`author-id` AS `parent-author-id`,
1883         `parent-post-author`.`url` AS `parent-author-link`,
1884         `parent-post-author`.`name` AS `parent-author-name`,
1885         `parent-post-author`.`network` AS `parent-author-network`
1886         FROM `post-thread-user`
1887                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
1888                         LEFT JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
1889                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1890                         INNER JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
1891                         INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
1892                         INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
1893                         INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1894                         INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1895                         INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1896                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1897                         INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1898                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1899                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
1900                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
1901                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
1902                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
1903                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1904                         INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1905
1906 --
1907 -- VIEW category-view
1908 --
1909 DROP VIEW IF EXISTS `category-view`;
1910 CREATE VIEW `category-view` AS SELECT 
1911         `post-category`.`uri-id` AS `uri-id`,
1912         `post-category`.`uid` AS `uid`,
1913         `post-category`.`type` AS `type`,
1914         `post-category`.`tid` AS `tid`,
1915         `tag`.`name` AS `name`,
1916         `tag`.`url` AS `url`
1917         FROM `post-category`
1918                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
1919
1920 --
1921 -- VIEW tag-view
1922 --
1923 DROP VIEW IF EXISTS `tag-view`;
1924 CREATE VIEW `tag-view` AS SELECT 
1925         `post-tag`.`uri-id` AS `uri-id`,
1926         `post-tag`.`type` AS `type`,
1927         `post-tag`.`tid` AS `tid`,
1928         `post-tag`.`cid` AS `cid`,
1929         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
1930         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
1931         FROM `post-tag`
1932                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
1933                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
1934
1935 --
1936 -- VIEW network-item-view
1937 --
1938 DROP VIEW IF EXISTS `network-item-view`;
1939 CREATE VIEW `network-item-view` AS SELECT 
1940         `post-user`.`uri-id` AS `uri-id`,
1941         `item`.`parent` AS `parent`,
1942         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1943         `post-user`.`received` AS `received`,
1944         `post-thread-user`.`commented` AS `commented`,
1945         `post-user`.`created` AS `created`,
1946         `post-user`.`uid` AS `uid`,
1947         `post-thread-user`.`starred` AS `starred`,
1948         `post-thread-user`.`mention` AS `mention`,
1949         `post-user`.`network` AS `network`,
1950         `post-user`.`unseen` AS `unseen`,
1951         `post-user`.`gravity` AS `gravity`,
1952         `post-user`.`contact-id` AS `contact-id`,
1953         `ownercontact`.`contact-type` AS `contact-type`
1954         FROM `post-user`
1955                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1956                         LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
1957                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1958                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
1959                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
1960                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
1961                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
1962                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1963                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
1964                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1965                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1966
1967 --
1968 -- VIEW network-thread-view
1969 --
1970 DROP VIEW IF EXISTS `network-thread-view`;
1971 CREATE VIEW `network-thread-view` AS SELECT 
1972         `post-thread-user`.`uri-id` AS `uri-id`,
1973         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1974         `item`.`id` AS `parent`,
1975         `post-thread-user`.`received` AS `received`,
1976         `post-thread-user`.`commented` AS `commented`,
1977         `post-thread-user`.`created` AS `created`,
1978         `post-thread-user`.`uid` AS `uid`,
1979         `post-thread-user`.`starred` AS `starred`,
1980         `post-thread-user`.`mention` AS `mention`,
1981         `post-thread-user`.`network` AS `network`,
1982         `post-thread-user`.`contact-id` AS `contact-id`,
1983         `ownercontact`.`contact-type` AS `contact-type`
1984         FROM `post-thread-user`
1985                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
1986                         LEFT JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
1987                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1988                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
1989                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
1990                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
1991                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
1992                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
1993                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
1994                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
1995                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
1996
1997 --
1998 -- VIEW owner-view
1999 --
2000 DROP VIEW IF EXISTS `owner-view`;
2001 CREATE VIEW `owner-view` AS SELECT 
2002         `contact`.`id` AS `id`,
2003         `contact`.`uid` AS `uid`,
2004         `contact`.`created` AS `created`,
2005         `contact`.`updated` AS `updated`,
2006         `contact`.`self` AS `self`,
2007         `contact`.`remote_self` AS `remote_self`,
2008         `contact`.`rel` AS `rel`,
2009         `contact`.`duplex` AS `duplex`,
2010         `contact`.`network` AS `network`,
2011         `contact`.`protocol` AS `protocol`,
2012         `contact`.`name` AS `name`,
2013         `contact`.`nick` AS `nick`,
2014         `contact`.`location` AS `location`,
2015         `contact`.`about` AS `about`,
2016         `contact`.`keywords` AS `keywords`,
2017         `contact`.`gender` AS `gender`,
2018         `contact`.`xmpp` AS `xmpp`,
2019         `contact`.`attag` AS `attag`,
2020         `contact`.`avatar` AS `avatar`,
2021         `contact`.`photo` AS `photo`,
2022         `contact`.`thumb` AS `thumb`,
2023         `contact`.`micro` AS `micro`,
2024         `contact`.`site-pubkey` AS `site-pubkey`,
2025         `contact`.`issued-id` AS `issued-id`,
2026         `contact`.`dfrn-id` AS `dfrn-id`,
2027         `contact`.`url` AS `url`,
2028         `contact`.`nurl` AS `nurl`,
2029         `contact`.`addr` AS `addr`,
2030         `contact`.`alias` AS `alias`,
2031         `contact`.`pubkey` AS `pubkey`,
2032         `contact`.`prvkey` AS `prvkey`,
2033         `contact`.`batch` AS `batch`,
2034         `contact`.`request` AS `request`,
2035         `contact`.`notify` AS `notify`,
2036         `contact`.`poll` AS `poll`,
2037         `contact`.`confirm` AS `confirm`,
2038         `contact`.`poco` AS `poco`,
2039         `contact`.`aes_allow` AS `aes_allow`,
2040         `contact`.`ret-aes` AS `ret-aes`,
2041         `contact`.`usehub` AS `usehub`,
2042         `contact`.`subhub` AS `subhub`,
2043         `contact`.`hub-verify` AS `hub-verify`,
2044         `contact`.`last-update` AS `last-update`,
2045         `contact`.`success_update` AS `success_update`,
2046         `contact`.`failure_update` AS `failure_update`,
2047         `contact`.`name-date` AS `name-date`,
2048         `contact`.`uri-date` AS `uri-date`,
2049         `contact`.`avatar-date` AS `avatar-date`,
2050         `contact`.`avatar-date` AS `picdate`,
2051         `contact`.`term-date` AS `term-date`,
2052         `contact`.`last-item` AS `last-item`,
2053         `contact`.`priority` AS `priority`,
2054         `user`.`blocked` AS `blocked`,
2055         `contact`.`block_reason` AS `block_reason`,
2056         `contact`.`readonly` AS `readonly`,
2057         `contact`.`writable` AS `writable`,
2058         `contact`.`forum` AS `forum`,
2059         `contact`.`prv` AS `prv`,
2060         `contact`.`contact-type` AS `contact-type`,
2061         `contact`.`manually-approve` AS `manually-approve`,
2062         `contact`.`hidden` AS `hidden`,
2063         `contact`.`archive` AS `archive`,
2064         `contact`.`pending` AS `pending`,
2065         `contact`.`deleted` AS `deleted`,
2066         `contact`.`unsearchable` AS `unsearchable`,
2067         `contact`.`sensitive` AS `sensitive`,
2068         `contact`.`baseurl` AS `baseurl`,
2069         `contact`.`reason` AS `reason`,
2070         `contact`.`closeness` AS `closeness`,
2071         `contact`.`info` AS `info`,
2072         `contact`.`profile-id` AS `profile-id`,
2073         `contact`.`bdyear` AS `bdyear`,
2074         `contact`.`bd` AS `bd`,
2075         `contact`.`notify_new_posts` AS `notify_new_posts`,
2076         `contact`.`fetch_further_information` AS `fetch_further_information`,
2077         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2078         `user`.`parent-uid` AS `parent-uid`,
2079         `user`.`guid` AS `guid`,
2080         `user`.`nickname` AS `nickname`,
2081         `user`.`email` AS `email`,
2082         `user`.`openid` AS `openid`,
2083         `user`.`timezone` AS `timezone`,
2084         `user`.`language` AS `language`,
2085         `user`.`register_date` AS `register_date`,
2086         `user`.`login_date` AS `login_date`,
2087         `user`.`default-location` AS `default-location`,
2088         `user`.`allow_location` AS `allow_location`,
2089         `user`.`theme` AS `theme`,
2090         `user`.`pubkey` AS `upubkey`,
2091         `user`.`prvkey` AS `uprvkey`,
2092         `user`.`sprvkey` AS `sprvkey`,
2093         `user`.`spubkey` AS `spubkey`,
2094         `user`.`verified` AS `verified`,
2095         `user`.`blockwall` AS `blockwall`,
2096         `user`.`hidewall` AS `hidewall`,
2097         `user`.`blocktags` AS `blocktags`,
2098         `user`.`unkmail` AS `unkmail`,
2099         `user`.`cntunkmail` AS `cntunkmail`,
2100         `user`.`notify-flags` AS `notify-flags`,
2101         `user`.`page-flags` AS `page-flags`,
2102         `user`.`account-type` AS `account-type`,
2103         `user`.`prvnets` AS `prvnets`,
2104         `user`.`maxreq` AS `maxreq`,
2105         `user`.`expire` AS `expire`,
2106         `user`.`account_removed` AS `account_removed`,
2107         `user`.`account_expired` AS `account_expired`,
2108         `user`.`account_expires_on` AS `account_expires_on`,
2109         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2110         `user`.`def_gid` AS `def_gid`,
2111         `user`.`allow_cid` AS `allow_cid`,
2112         `user`.`allow_gid` AS `allow_gid`,
2113         `user`.`deny_cid` AS `deny_cid`,
2114         `user`.`deny_gid` AS `deny_gid`,
2115         `user`.`openidserver` AS `openidserver`,
2116         `profile`.`publish` AS `publish`,
2117         `profile`.`net-publish` AS `net-publish`,
2118         `profile`.`hide-friends` AS `hide-friends`,
2119         `profile`.`prv_keywords` AS `prv_keywords`,
2120         `profile`.`pub_keywords` AS `pub_keywords`,
2121         `profile`.`address` AS `address`,
2122         `profile`.`locality` AS `locality`,
2123         `profile`.`region` AS `region`,
2124         `profile`.`postal-code` AS `postal-code`,
2125         `profile`.`country-name` AS `country-name`,
2126         `profile`.`homepage` AS `homepage`,
2127         `profile`.`dob` AS `dob`
2128         FROM `user`
2129                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2130                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2131
2132 --
2133 -- VIEW pending-view
2134 --
2135 DROP VIEW IF EXISTS `pending-view`;
2136 CREATE VIEW `pending-view` AS SELECT 
2137         `register`.`id` AS `id`,
2138         `register`.`hash` AS `hash`,
2139         `register`.`created` AS `created`,
2140         `register`.`uid` AS `uid`,
2141         `register`.`password` AS `password`,
2142         `register`.`language` AS `language`,
2143         `register`.`note` AS `note`,
2144         `contact`.`self` AS `self`,
2145         `contact`.`name` AS `name`,
2146         `contact`.`url` AS `url`,
2147         `contact`.`micro` AS `micro`,
2148         `user`.`email` AS `email`,
2149         `contact`.`nick` AS `nick`
2150         FROM `register`
2151                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2152                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2153
2154 --
2155 -- VIEW tag-search-view
2156 --
2157 DROP VIEW IF EXISTS `tag-search-view`;
2158 CREATE VIEW `tag-search-view` AS SELECT 
2159         `post-tag`.`uri-id` AS `uri-id`,
2160         `post-user`.`uid` AS `uid`,
2161         `post-user`.`private` AS `private`,
2162         `post-user`.`wall` AS `wall`,
2163         `post-user`.`origin` AS `origin`,
2164         `post-user`.`gravity` AS `gravity`,
2165         `post-user`.`received` AS `received`,
2166         `tag`.`name` AS `name`
2167         FROM `post-tag`
2168                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2169                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2170                         WHERE `post-tag`.`type` = 1;
2171
2172 --
2173 -- VIEW workerqueue-view
2174 --
2175 DROP VIEW IF EXISTS `workerqueue-view`;
2176 CREATE VIEW `workerqueue-view` AS SELECT 
2177         `process`.`pid` AS `pid`,
2178         `workerqueue`.`priority` AS `priority`
2179         FROM `process`
2180                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2181                         WHERE NOT `workerqueue`.`done`;