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