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