]> git.mxchange.org Git - friendica.git/blob - database.sql
Merge pull request #10860 from nupplaphil/feat/depository_profilefield
[friendica.git] / database.sql
1 -- ------------------------------------------
2 -- Friendica 2021.12-dev (Siberian Iris)
3 -- DB_UPDATE_VERSION 1440
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 `uid` (`uid`),
727         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
728         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
729         FOREIGN KEY (`suggest-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
730 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
731
732 --
733 -- TABLE locks
734 --
735 CREATE TABLE IF NOT EXISTS `locks` (
736         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
737         `name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
738         `locked` boolean NOT NULL DEFAULT '0' COMMENT '',
739         `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process ID',
740         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
741          PRIMARY KEY(`id`),
742          INDEX `name_expires` (`name`,`expires`)
743 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
744
745 --
746 -- TABLE mail
747 --
748 CREATE TABLE IF NOT EXISTS `mail` (
749         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
750         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
751         `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this private message',
752         `from-name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name of the sender',
753         `from-photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'contact photo link of the sender',
754         `from-url` varchar(255) NOT NULL DEFAULT '' COMMENT 'profile linke of the sender',
755         `contact-id` varchar(255) COMMENT 'contact.id',
756         `author-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the author of the mail',
757         `convid` int unsigned COMMENT 'conv.id',
758         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
759         `body` mediumtext COMMENT '',
760         `seen` boolean NOT NULL DEFAULT '0' COMMENT 'if message visited it is 1',
761         `reply` boolean NOT NULL DEFAULT '0' COMMENT '',
762         `replied` boolean NOT NULL DEFAULT '0' COMMENT '',
763         `unknown` boolean NOT NULL DEFAULT '0' COMMENT 'if sender not in the contact table this is 1',
764         `uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
765         `uri-id` int unsigned COMMENT 'Item-uri id of the related mail',
766         `parent-uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
767         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related mail',
768         `thr-parent` varchar(255) COMMENT '',
769         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
770         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time of the private message',
771          PRIMARY KEY(`id`),
772          INDEX `uid_seen` (`uid`,`seen`),
773          INDEX `convid` (`convid`),
774          INDEX `uri` (`uri`(64)),
775          INDEX `parent-uri` (`parent-uri`(64)),
776          INDEX `contactid` (`contact-id`(32)),
777          INDEX `author-id` (`author-id`),
778          INDEX `uri-id` (`uri-id`),
779          INDEX `parent-uri-id` (`parent-uri-id`),
780          INDEX `thr-parent-id` (`thr-parent-id`),
781         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
782         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
783         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
784         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
785         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
786 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages';
787
788 --
789 -- TABLE mailacct
790 --
791 CREATE TABLE IF NOT EXISTS `mailacct` (
792         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
793         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
794         `server` varchar(255) NOT NULL DEFAULT '' COMMENT '',
795         `port` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
796         `ssltype` varchar(16) NOT NULL DEFAULT '' COMMENT '',
797         `mailbox` varchar(255) NOT NULL DEFAULT '' COMMENT '',
798         `user` varchar(255) NOT NULL DEFAULT '' COMMENT '',
799         `pass` text COMMENT '',
800         `reply_to` varchar(255) NOT NULL DEFAULT '' COMMENT '',
801         `action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
802         `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '',
803         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
804         `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
805          PRIMARY KEY(`id`),
806          INDEX `uid` (`uid`),
807         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
808 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails';
809
810 --
811 -- TABLE manage
812 --
813 CREATE TABLE IF NOT EXISTS `manage` (
814         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
815         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
816         `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
817          PRIMARY KEY(`id`),
818          UNIQUE INDEX `uid_mid` (`uid`,`mid`),
819          INDEX `mid` (`mid`),
820         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
821         FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
822 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other';
823
824 --
825 -- TABLE notification
826 --
827 CREATE TABLE IF NOT EXISTS `notification` (
828         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
829         `uid` mediumint unsigned COMMENT 'Owner User id',
830         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
831         `type` tinyint unsigned COMMENT '',
832         `actor-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the actor that caused the notification',
833         `target-uri-id` int unsigned COMMENT 'Item-uri id of the related post',
834         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
835         `created` datetime COMMENT '',
836         `seen` boolean DEFAULT '0' COMMENT '',
837          PRIMARY KEY(`id`),
838          UNIQUE INDEX `uid_vid_type_actor-id_target-uri-id` (`uid`,`vid`,`type`,`actor-id`,`target-uri-id`),
839          INDEX `vid` (`vid`),
840          INDEX `actor-id` (`actor-id`),
841          INDEX `target-uri-id` (`target-uri-id`),
842          INDEX `parent-uri-id` (`parent-uri-id`),
843          INDEX `seen_uid` (`seen`,`uid`),
844         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
845         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
846         FOREIGN KEY (`actor-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
847         FOREIGN KEY (`target-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
848         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
849 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
850
851 --
852 -- TABLE notify
853 --
854 CREATE TABLE IF NOT EXISTS `notify` (
855         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
856         `type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
857         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
858         `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
859         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
860         `date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
861         `msg` mediumtext COMMENT '',
862         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
863         `link` varchar(255) NOT NULL DEFAULT '' COMMENT '',
864         `iid` int unsigned COMMENT '',
865         `parent` int unsigned COMMENT '',
866         `uri-id` int unsigned COMMENT 'Item-uri id of the related post',
867         `parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
868         `seen` boolean NOT NULL DEFAULT '0' COMMENT '',
869         `verb` varchar(100) NOT NULL DEFAULT '' COMMENT '',
870         `otype` varchar(10) NOT NULL DEFAULT '' COMMENT '',
871         `name_cache` tinytext COMMENT 'Cached bbcode parsing of name',
872         `msg_cache` mediumtext COMMENT 'Cached bbcode parsing of msg',
873          PRIMARY KEY(`id`),
874          INDEX `seen_uid_date` (`seen`,`uid`,`date`),
875          INDEX `uid_date` (`uid`,`date`),
876          INDEX `uid_type_link` (`uid`,`type`,`link`(190)),
877          INDEX `uri-id` (`uri-id`),
878          INDEX `parent-uri-id` (`parent-uri-id`),
879         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
880         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
881         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
882 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
883
884 --
885 -- TABLE notify-threads
886 --
887 CREATE TABLE IF NOT EXISTS `notify-threads` (
888         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
889         `notify-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
890         `master-parent-item` int unsigned COMMENT 'Deprecated',
891         `master-parent-uri-id` int unsigned COMMENT 'Item-uri id of the parent of the related post',
892         `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '',
893         `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
894          PRIMARY KEY(`id`),
895          INDEX `master-parent-uri-id` (`master-parent-uri-id`),
896          INDEX `receiver-uid` (`receiver-uid`),
897          INDEX `notify-id` (`notify-id`),
898         FOREIGN KEY (`notify-id`) REFERENCES `notify` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
899         FOREIGN KEY (`master-parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
900         FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
901 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
902
903 --
904 -- TABLE oembed
905 --
906 CREATE TABLE IF NOT EXISTS `oembed` (
907         `url` varbinary(255) NOT NULL COMMENT 'page url',
908         `maxwidth` mediumint unsigned NOT NULL COMMENT 'Maximum width passed to Oembed',
909         `content` mediumtext COMMENT 'OEmbed data of the page',
910         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
911          PRIMARY KEY(`url`,`maxwidth`),
912          INDEX `created` (`created`)
913 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for OEmbed queries';
914
915 --
916 -- TABLE openwebauth-token
917 --
918 CREATE TABLE IF NOT EXISTS `openwebauth-token` (
919         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
920         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id - currently unused',
921         `type` varchar(32) NOT NULL DEFAULT '' COMMENT 'Verify type',
922         `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token',
923         `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '',
924         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
925          PRIMARY KEY(`id`),
926          INDEX `uid` (`uid`),
927         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
928 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
929
930 --
931 -- TABLE parsed_url
932 --
933 CREATE TABLE IF NOT EXISTS `parsed_url` (
934         `url_hash` binary(64) NOT NULL COMMENT 'page url hash',
935         `guessing` boolean NOT NULL DEFAULT '0' COMMENT 'is the \'guessing\' mode active?',
936         `oembed` boolean NOT NULL DEFAULT '0' COMMENT 'is the data the result of oembed?',
937         `url` text NOT NULL COMMENT 'page url',
938         `content` mediumtext COMMENT 'page data',
939         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation',
940         `expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of expiration',
941          PRIMARY KEY(`url_hash`,`guessing`,`oembed`),
942          INDEX `created` (`created`),
943          INDEX `expires` (`expires`)
944 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='cache for \'parse_url\' queries';
945
946 --
947 -- TABLE pconfig
948 --
949 CREATE TABLE IF NOT EXISTS `pconfig` (
950         `id` int unsigned NOT NULL auto_increment COMMENT 'Primary key',
951         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
952         `cat` varchar(50) NOT NULL DEFAULT '' COMMENT 'Category',
953         `k` varchar(100) NOT NULL DEFAULT '' COMMENT 'Key',
954         `v` mediumtext COMMENT 'Value',
955          PRIMARY KEY(`id`),
956          UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`),
957         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
958 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
959
960 --
961 -- TABLE photo
962 --
963 CREATE TABLE IF NOT EXISTS `photo` (
964         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
965         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
966         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
967         `guid` char(16) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this photo',
968         `resource-id` char(32) NOT NULL DEFAULT '' COMMENT '',
969         `hash` char(32) COMMENT 'hash value of the photo',
970         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation date',
971         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edited date',
972         `title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
973         `desc` text COMMENT '',
974         `album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
975         `photo-type` tinyint unsigned COMMENT 'User avatar, user banner, contact avatar, contact banner or default',
976         `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
977         `type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
978         `height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
979         `width` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
980         `datasize` int unsigned NOT NULL DEFAULT 0 COMMENT '',
981         `data` mediumblob NOT NULL COMMENT '',
982         `scale` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
983         `profile` boolean NOT NULL DEFAULT '0' COMMENT '',
984         `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
985         `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
986         `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
987         `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
988         `accessible` boolean NOT NULL DEFAULT '0' COMMENT 'Make photo publicly accessible, ignoring permissions',
989         `backend-class` tinytext COMMENT 'Storage backend class',
990         `backend-ref` text COMMENT 'Storage backend data reference',
991         `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
992          PRIMARY KEY(`id`),
993          INDEX `contactid` (`contact-id`),
994          INDEX `uid_contactid` (`uid`,`contact-id`),
995          INDEX `uid_profile` (`uid`,`profile`),
996          INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
997          INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
998          INDEX `resource-id` (`resource-id`),
999          INDEX `uid_photo-type` (`uid`,`photo-type`),
1000         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1001         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1002 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
1003
1004 --
1005 -- TABLE post
1006 --
1007 CREATE TABLE IF NOT EXISTS `post` (
1008         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1009         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1010         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1011         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1012         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1013         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1014         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1015         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1016         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1017         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1018         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1019         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1020         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1021         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1022         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1023         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1024         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1025         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1026          PRIMARY KEY(`uri-id`),
1027          INDEX `parent-uri-id` (`parent-uri-id`),
1028          INDEX `thr-parent-id` (`thr-parent-id`),
1029          INDEX `external-id` (`external-id`),
1030          INDEX `owner-id` (`owner-id`),
1031          INDEX `author-id` (`author-id`),
1032          INDEX `causer-id` (`causer-id`),
1033          INDEX `vid` (`vid`),
1034         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1035         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1036         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1037         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1038         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1039         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1040         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1041         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1042 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
1043
1044 --
1045 -- TABLE post-category
1046 --
1047 CREATE TABLE IF NOT EXISTS `post-category` (
1048         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1049         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1050         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1051         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1052          PRIMARY KEY(`uri-id`,`uid`,`type`,`tid`),
1053          INDEX `uri-id` (`tid`),
1054          INDEX `uid` (`uid`),
1055         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1056         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1057         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1058 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
1059
1060 --
1061 -- TABLE post-content
1062 --
1063 CREATE TABLE IF NOT EXISTS `post-content` (
1064         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1065         `title` varchar(255) NOT NULL DEFAULT '' COMMENT 'item title',
1066         `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1067         `body` mediumtext COMMENT 'item body content',
1068         `raw-body` mediumtext COMMENT 'Body without embedded media links',
1069         `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
1070         `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
1071         `language` text COMMENT 'Language information about this post',
1072         `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
1073         `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1074         `rendered-html` mediumtext COMMENT 'item.body converted to html',
1075         `object-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams object type',
1076         `object` text COMMENT 'JSON encoded object structure unless it is an implied object (normal post)',
1077         `target-type` varchar(100) NOT NULL DEFAULT '' COMMENT 'ActivityStreams target type if applicable (URI)',
1078         `target` text COMMENT 'JSON encoded target structure if used',
1079         `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',
1080         `plink` varchar(255) NOT NULL DEFAULT '' COMMENT 'permalink or URL to a displayable copy of the message at its source',
1081          PRIMARY KEY(`uri-id`),
1082          INDEX `plink` (`plink`(191)),
1083          INDEX `resource-id` (`resource-id`),
1084          FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
1085         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1086 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
1087
1088 --
1089 -- TABLE post-delivery-data
1090 --
1091 CREATE TABLE IF NOT EXISTS `post-delivery-data` (
1092         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1093         `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',
1094         `inform` mediumtext COMMENT 'Additional receivers of the linked item',
1095         `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
1096         `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
1097         `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
1098         `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
1099         `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
1100         `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
1101         `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
1102         `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
1103          PRIMARY KEY(`uri-id`),
1104         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1105 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
1106
1107 --
1108 -- TABLE post-link
1109 --
1110 CREATE TABLE IF NOT EXISTS `post-link` (
1111         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1112         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1113         `url` varbinary(511) NOT NULL COMMENT 'External URL',
1114         `mimetype` varchar(60) COMMENT '',
1115          PRIMARY KEY(`id`),
1116          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1117         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1118 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Post related external links';
1119
1120 --
1121 -- TABLE post-media
1122 --
1123 CREATE TABLE IF NOT EXISTS `post-media` (
1124         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1125         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1126         `url` varbinary(511) NOT NULL COMMENT 'Media URL',
1127         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Media type',
1128         `mimetype` varchar(60) COMMENT '',
1129         `height` smallint unsigned COMMENT 'Height of the media',
1130         `width` smallint unsigned COMMENT 'Width of the media',
1131         `size` int unsigned COMMENT 'Media size',
1132         `preview` varbinary(255) COMMENT 'Preview URL',
1133         `preview-height` smallint unsigned COMMENT 'Height of the preview picture',
1134         `preview-width` smallint unsigned COMMENT 'Width of the preview picture',
1135         `description` text COMMENT '',
1136         `name` varchar(255) COMMENT 'Name of the media',
1137         `author-url` varbinary(255) COMMENT 'URL of the author of the media',
1138         `author-name` varchar(255) COMMENT 'Name of the author of the media',
1139         `author-image` varbinary(255) COMMENT 'Image of the author of the media',
1140         `publisher-url` varbinary(255) COMMENT 'URL of the publisher of the media',
1141         `publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
1142         `publisher-image` varbinary(255) COMMENT 'Image of the publisher of the media',
1143          PRIMARY KEY(`id`),
1144          UNIQUE INDEX `uri-id-url` (`uri-id`,`url`),
1145         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1146 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Attached media';
1147
1148 --
1149 -- TABLE post-tag
1150 --
1151 CREATE TABLE IF NOT EXISTS `post-tag` (
1152         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1153         `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1154         `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1155         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
1156          PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
1157          INDEX `tid` (`tid`),
1158          INDEX `cid` (`cid`),
1159         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1160         FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1161         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1162 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
1163
1164 --
1165 -- TABLE post-thread
1166 --
1167 CREATE TABLE IF NOT EXISTS `post-thread` (
1168         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1169         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1170         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1171         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1172         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1173         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1174         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1175         `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',
1176         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1177          PRIMARY KEY(`uri-id`),
1178          INDEX `owner-id` (`owner-id`),
1179          INDEX `author-id` (`author-id`),
1180          INDEX `causer-id` (`causer-id`),
1181          INDEX `received` (`received`),
1182          INDEX `commented` (`commented`),
1183         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1184         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1185         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1186         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1187 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1188
1189 --
1190 -- TABLE post-user
1191 --
1192 CREATE TABLE IF NOT EXISTS `post-user` (
1193         `id` int unsigned NOT NULL auto_increment,
1194         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1195         `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
1196         `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
1197         `external-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the external uri',
1198         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
1199         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
1200         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
1201         `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1202         `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
1203         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
1204         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
1205         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1206         `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
1207         `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
1208         `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
1209         `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
1210         `global` boolean NOT NULL DEFAULT '0' COMMENT '',
1211         `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
1212         `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
1213         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1214         `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
1215         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1216         `event-id` int unsigned COMMENT 'Used to link to the event.id',
1217         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1218         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1219         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1220         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1221         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1222         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1223          PRIMARY KEY(`id`),
1224          UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
1225          INDEX `uri-id` (`uri-id`),
1226          INDEX `parent-uri-id` (`parent-uri-id`),
1227          INDEX `thr-parent-id` (`thr-parent-id`),
1228          INDEX `external-id` (`external-id`),
1229          INDEX `owner-id` (`owner-id`),
1230          INDEX `author-id` (`author-id`),
1231          INDEX `causer-id` (`causer-id`),
1232          INDEX `vid` (`vid`),
1233          INDEX `contact-id` (`contact-id`),
1234          INDEX `event-id` (`event-id`),
1235          INDEX `psid` (`psid`),
1236          INDEX `author-id_uid` (`author-id`,`uid`),
1237          INDEX `author-id_received` (`author-id`,`received`),
1238          INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
1239          INDEX `uid_contactid` (`uid`,`contact-id`),
1240          INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
1241          INDEX `uid_unseen` (`uid`,`unseen`),
1242          INDEX `uid_hidden_uri-id` (`uid`,`hidden`,`uri-id`),
1243         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1244         FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1245         FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1246         FOREIGN KEY (`external-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1247         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1248         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1249         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1250         FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1251         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1252         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1253         FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1254         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1255 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
1256
1257 --
1258 -- TABLE post-thread-user
1259 --
1260 CREATE TABLE IF NOT EXISTS `post-thread-user` (
1261         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1262         `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
1263         `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item author',
1264         `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
1265         `network` char(4) NOT NULL DEFAULT '' COMMENT '',
1266         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1267         `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1268         `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',
1269         `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1270         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
1271         `pinned` boolean NOT NULL DEFAULT '0' COMMENT 'The thread is pinned on the profile page',
1272         `starred` boolean NOT NULL DEFAULT '0' COMMENT '',
1273         `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'Ignore updates for this thread',
1274         `wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
1275         `mention` boolean NOT NULL DEFAULT '0' COMMENT '',
1276         `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
1277         `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1278         `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
1279         `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
1280         `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
1281         `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
1282         `psid` int unsigned COMMENT 'ID of the permission set of this post',
1283         `post-user-id` int unsigned COMMENT 'Id of the post-user table',
1284          PRIMARY KEY(`uid`,`uri-id`),
1285          INDEX `uri-id` (`uri-id`),
1286          INDEX `owner-id` (`owner-id`),
1287          INDEX `author-id` (`author-id`),
1288          INDEX `causer-id` (`causer-id`),
1289          INDEX `uid` (`uid`),
1290          INDEX `contact-id` (`contact-id`),
1291          INDEX `psid` (`psid`),
1292          INDEX `post-user-id` (`post-user-id`),
1293          INDEX `commented` (`commented`),
1294          INDEX `uid_received` (`uid`,`received`),
1295          INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1296          INDEX `uid_pinned` (`uid`,`pinned`),
1297          INDEX `uid_commented` (`uid`,`commented`),
1298          INDEX `uid_starred` (`uid`,`starred`),
1299          INDEX `uid_mention` (`uid`,`mention`),
1300         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1301         FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1302         FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1303         FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1304         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1305         FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1306         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
1307         FOREIGN KEY (`post-user-id`) REFERENCES `post-user` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1308 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data per user';
1309
1310 --
1311 -- TABLE post-user-notification
1312 --
1313 CREATE TABLE IF NOT EXISTS `post-user-notification` (
1314         `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
1315         `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
1316         `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
1317          PRIMARY KEY(`uid`,`uri-id`),
1318          INDEX `uri-id` (`uri-id`),
1319         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1320         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1321 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
1322
1323 --
1324 -- TABLE process
1325 --
1326 CREATE TABLE IF NOT EXISTS `process` (
1327         `pid` int unsigned NOT NULL COMMENT '',
1328         `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '',
1329         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1330          PRIMARY KEY(`pid`),
1331          INDEX `command` (`command`)
1332 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently running system processes';
1333
1334 --
1335 -- TABLE profile
1336 --
1337 CREATE TABLE IF NOT EXISTS `profile` (
1338         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1339         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
1340         `profile-name` varchar(255) COMMENT 'Deprecated',
1341         `is-default` boolean COMMENT 'Deprecated',
1342         `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
1343         `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1344         `pdesc` varchar(255) COMMENT 'Deprecated',
1345         `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
1346         `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1347         `locality` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1348         `region` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1349         `postal-code` varchar(32) NOT NULL DEFAULT '' COMMENT '',
1350         `country-name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1351         `hometown` varchar(255) COMMENT 'Deprecated',
1352         `gender` varchar(32) COMMENT 'Deprecated',
1353         `marital` varchar(255) COMMENT 'Deprecated',
1354         `with` text COMMENT 'Deprecated',
1355         `howlong` datetime COMMENT 'Deprecated',
1356         `sexual` varchar(255) COMMENT 'Deprecated',
1357         `politic` varchar(255) COMMENT 'Deprecated',
1358         `religion` varchar(255) COMMENT 'Deprecated',
1359         `pub_keywords` text COMMENT '',
1360         `prv_keywords` text COMMENT '',
1361         `likes` text COMMENT 'Deprecated',
1362         `dislikes` text COMMENT 'Deprecated',
1363         `about` text COMMENT 'Profile description',
1364         `summary` varchar(255) COMMENT 'Deprecated',
1365         `music` text COMMENT 'Deprecated',
1366         `book` text COMMENT 'Deprecated',
1367         `tv` text COMMENT 'Deprecated',
1368         `film` text COMMENT 'Deprecated',
1369         `interest` text COMMENT 'Deprecated',
1370         `romance` text COMMENT 'Deprecated',
1371         `work` text COMMENT 'Deprecated',
1372         `education` text COMMENT 'Deprecated',
1373         `contact` text COMMENT 'Deprecated',
1374         `homepage` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1375         `xmpp` varchar(255) NOT NULL DEFAULT '' COMMENT 'XMPP address',
1376         `matrix` varchar(255) NOT NULL DEFAULT '' COMMENT 'Matrix address',
1377         `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1378         `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1379         `publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish default profile in local directory',
1380         `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory',
1381          PRIMARY KEY(`id`),
1382          INDEX `uid_is-default` (`uid`,`is-default`),
1383          FULLTEXT INDEX `pub_keywords` (`pub_keywords`),
1384         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1385 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data';
1386
1387 --
1388 -- TABLE profile_field
1389 --
1390 CREATE TABLE IF NOT EXISTS `profile_field` (
1391         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1392         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner user id',
1393         `order` mediumint unsigned NOT NULL DEFAULT 1 COMMENT 'Field ordering per user',
1394         `psid` int unsigned COMMENT 'ID of the permission set of this profile field - 0 = public',
1395         `label` varchar(255) NOT NULL DEFAULT '' COMMENT 'Label of the field',
1396         `value` text COMMENT 'Value of the field',
1397         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'creation time',
1398         `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'last edit time',
1399          PRIMARY KEY(`id`),
1400          INDEX `uid` (`uid`),
1401          INDEX `order` (`order`),
1402          INDEX `psid` (`psid`),
1403         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1404         FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
1405 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields';
1406
1407 --
1408 -- TABLE push_subscriber
1409 --
1410 CREATE TABLE IF NOT EXISTS `push_subscriber` (
1411         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1412         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1413         `callback_url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1414         `topic` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1415         `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1416         `push` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
1417         `last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last successful trial',
1418         `next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
1419         `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal',
1420         `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1421          PRIMARY KEY(`id`),
1422          INDEX `next_try` (`next_try`),
1423          INDEX `uid` (`uid`),
1424         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1425 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers';
1426
1427 --
1428 -- TABLE register
1429 --
1430 CREATE TABLE IF NOT EXISTS `register` (
1431         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1432         `hash` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1433         `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
1434         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1435         `password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1436         `language` varchar(16) NOT NULL DEFAULT '' COMMENT '',
1437         `note` text COMMENT '',
1438          PRIMARY KEY(`id`),
1439          INDEX `uid` (`uid`),
1440         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1441 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval';
1442
1443 --
1444 -- TABLE search
1445 --
1446 CREATE TABLE IF NOT EXISTS `search` (
1447         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1448         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1449         `term` varchar(255) NOT NULL DEFAULT '' COMMENT '',
1450          PRIMARY KEY(`id`),
1451          INDEX `uid_term` (`uid`,`term`(64)),
1452          INDEX `term` (`term`(64)),
1453         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1454 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
1455
1456 --
1457 -- TABLE session
1458 --
1459 CREATE TABLE IF NOT EXISTS `session` (
1460         `id` bigint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1461         `sid` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
1462         `data` text COMMENT '',
1463         `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '',
1464          PRIMARY KEY(`id`),
1465          INDEX `sid` (`sid`(64)),
1466          INDEX `expire` (`expire`)
1467 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='web session storage';
1468
1469 --
1470 -- TABLE storage
1471 --
1472 CREATE TABLE IF NOT EXISTS `storage` (
1473         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1474         `data` longblob NOT NULL COMMENT 'file data',
1475          PRIMARY KEY(`id`)
1476 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
1477
1478 --
1479 -- TABLE subscription
1480 --
1481 CREATE TABLE IF NOT EXISTS `subscription` (
1482         `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented image data id',
1483         `application-id` int unsigned NOT NULL COMMENT '',
1484         `uid` mediumint unsigned NOT NULL COMMENT 'Owner User id',
1485         `endpoint` varchar(511) COMMENT 'Endpoint URL',
1486         `pubkey` varchar(127) COMMENT 'User agent public key',
1487         `secret` varchar(32) COMMENT 'Auth secret',
1488         `follow` boolean COMMENT '',
1489         `favourite` boolean COMMENT '',
1490         `reblog` boolean COMMENT '',
1491         `mention` boolean COMMENT '',
1492         `poll` boolean COMMENT '',
1493         `follow_request` boolean COMMENT '',
1494         `status` boolean COMMENT '',
1495          PRIMARY KEY(`id`),
1496          UNIQUE INDEX `application-id_uid` (`application-id`,`uid`),
1497          INDEX `uid_application-id` (`uid`,`application-id`),
1498         FOREIGN KEY (`application-id`) REFERENCES `application` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1499         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
1500 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Push Subscription for the API';
1501
1502 --
1503 -- TABLE userd
1504 --
1505 CREATE TABLE IF NOT EXISTS `userd` (
1506         `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
1507         `username` varchar(255) NOT NULL COMMENT '',
1508          PRIMARY KEY(`id`),
1509          INDEX `username` (`username`(32))
1510 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Deleted usernames';
1511
1512 --
1513 -- TABLE user-contact
1514 --
1515 CREATE TABLE IF NOT EXISTS `user-contact` (
1516         `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the linked public contact',
1517         `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
1518         `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
1519         `blocked` boolean COMMENT 'Contact is completely blocked for this user',
1520         `ignored` boolean COMMENT 'Posts from this contact are ignored',
1521         `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
1522         `pending` boolean COMMENT '',
1523         `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
1524         `info` mediumtext COMMENT '',
1525         `notify_new_posts` boolean COMMENT '',
1526         `remote_self` boolean COMMENT '',
1527         `fetch_further_information` tinyint unsigned COMMENT '',
1528         `ffi_keyword_denylist` text COMMENT '',
1529         `subhub` boolean COMMENT '',
1530         `hub-verify` varchar(255) COMMENT '',
1531         `protocol` char(4) COMMENT 'Protocol of the contact',
1532         `rating` tinyint COMMENT 'Automatically detected feed poll frequency',
1533         `priority` tinyint unsigned COMMENT 'Feed poll priority',
1534          PRIMARY KEY(`uid`,`cid`),
1535          INDEX `cid` (`cid`),
1536          UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
1537         FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
1538         FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
1539         FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
1540 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data';
1541
1542 --
1543 -- TABLE worker-ipc
1544 --
1545 CREATE TABLE IF NOT EXISTS `worker-ipc` (
1546         `key` int NOT NULL COMMENT '',
1547         `jobs` boolean COMMENT 'Flag for outstanding jobs',
1548          PRIMARY KEY(`key`)
1549 ) ENGINE=MEMORY DEFAULT COLLATE utf8mb4_general_ci COMMENT='Inter process communication between the frontend and the worker';
1550
1551 --
1552 -- VIEW application-view
1553 --
1554 DROP VIEW IF EXISTS `application-view`;
1555 CREATE VIEW `application-view` AS SELECT 
1556         `application`.`id` AS `id`,
1557         `application-token`.`uid` AS `uid`,
1558         `application`.`name` AS `name`,
1559         `application`.`redirect_uri` AS `redirect_uri`,
1560         `application`.`website` AS `website`,
1561         `application`.`client_id` AS `client_id`,
1562         `application`.`client_secret` AS `client_secret`,
1563         `application-token`.`code` AS `code`,
1564         `application-token`.`access_token` AS `access_token`,
1565         `application-token`.`created_at` AS `created_at`,
1566         `application-token`.`scopes` AS `scopes`,
1567         `application-token`.`read` AS `read`,
1568         `application-token`.`write` AS `write`,
1569         `application-token`.`follow` AS `follow`,
1570         `application-token`.`push` AS `push`
1571         FROM `application-token`
1572                         INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
1573
1574 --
1575 -- VIEW post-user-view
1576 --
1577 DROP VIEW IF EXISTS `post-user-view`;
1578 CREATE VIEW `post-user-view` AS SELECT 
1579         `post-user`.`id` AS `id`,
1580         `post-user`.`id` AS `post-user-id`,
1581         `post-user`.`uid` AS `uid`,
1582         `parent-post`.`id` AS `parent`,
1583         `item-uri`.`uri` AS `uri`,
1584         `post-user`.`uri-id` AS `uri-id`,
1585         `parent-item-uri`.`uri` AS `parent-uri`,
1586         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1587         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1588         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1589         `item-uri`.`guid` AS `guid`,
1590         `post-user`.`wall` AS `wall`,
1591         `post-user`.`gravity` AS `gravity`,
1592         `external-item-uri`.`uri` AS `extid`,
1593         `post-user`.`external-id` AS `external-id`,
1594         `post-user`.`created` AS `created`,
1595         `post-user`.`edited` AS `edited`,
1596         `post-thread-user`.`commented` AS `commented`,
1597         `post-user`.`received` AS `received`,
1598         `post-thread-user`.`changed` AS `changed`,
1599         `post-user`.`post-type` AS `post-type`,
1600         `post-user`.`post-reason` AS `post-reason`,
1601         `post-user`.`private` AS `private`,
1602         `post-thread-user`.`pubmail` AS `pubmail`,
1603         `post-user`.`visible` AS `visible`,
1604         `post-thread-user`.`starred` AS `starred`,
1605         `post-thread-user`.`pinned` AS `pinned`,
1606         `post-user`.`unseen` AS `unseen`,
1607         `post-user`.`deleted` AS `deleted`,
1608         `post-user`.`origin` AS `origin`,
1609         `post-thread-user`.`origin` AS `parent-origin`,
1610         `post-thread-user`.`forum_mode` AS `forum_mode`,
1611         `post-thread-user`.`mention` AS `mention`,
1612         `post-user`.`global` AS `global`,
1613         `post-user`.`network` AS `network`,
1614         `post-user`.`vid` AS `vid`,
1615         `post-user`.`psid` AS `psid`,
1616         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1617         `post-content`.`title` AS `title`,
1618         `post-content`.`content-warning` AS `content-warning`,
1619         `post-content`.`raw-body` AS `raw-body`,
1620         `post-content`.`body` AS `body`,
1621         `post-content`.`rendered-hash` AS `rendered-hash`,
1622         `post-content`.`rendered-html` AS `rendered-html`,
1623         `post-content`.`language` AS `language`,
1624         `post-content`.`plink` AS `plink`,
1625         `post-content`.`location` AS `location`,
1626         `post-content`.`coord` AS `coord`,
1627         `post-content`.`app` AS `app`,
1628         `post-content`.`object-type` AS `object-type`,
1629         `post-content`.`object` AS `object`,
1630         `post-content`.`target-type` AS `target-type`,
1631         `post-content`.`target` AS `target`,
1632         `post-content`.`resource-id` AS `resource-id`,
1633         `post-user`.`contact-id` AS `contact-id`,
1634         `contact`.`url` AS `contact-link`,
1635         `contact`.`addr` AS `contact-addr`,
1636         `contact`.`name` AS `contact-name`,
1637         `contact`.`nick` AS `contact-nick`,
1638         `contact`.`thumb` AS `contact-avatar`,
1639         `contact`.`network` AS `contact-network`,
1640         `contact`.`blocked` AS `contact-blocked`,
1641         `contact`.`hidden` AS `contact-hidden`,
1642         `contact`.`readonly` AS `contact-readonly`,
1643         `contact`.`archive` AS `contact-archive`,
1644         `contact`.`pending` AS `contact-pending`,
1645         `contact`.`rel` AS `contact-rel`,
1646         `contact`.`uid` AS `contact-uid`,
1647         `contact`.`contact-type` AS `contact-contact-type`,
1648         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1649         `contact`.`self` AS `self`,
1650         `contact`.`id` AS `cid`,
1651         `contact`.`alias` AS `alias`,
1652         `contact`.`photo` AS `photo`,
1653         `contact`.`name-date` AS `name-date`,
1654         `contact`.`uri-date` AS `uri-date`,
1655         `contact`.`avatar-date` AS `avatar-date`,
1656         `contact`.`thumb` AS `thumb`,
1657         `post-user`.`author-id` AS `author-id`,
1658         `author`.`url` AS `author-link`,
1659         `author`.`addr` AS `author-addr`,
1660         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1661         `author`.`nick` AS `author-nick`,
1662         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1663         `author`.`network` AS `author-network`,
1664         `author`.`blocked` AS `author-blocked`,
1665         `author`.`hidden` AS `author-hidden`,
1666         `post-user`.`owner-id` AS `owner-id`,
1667         `owner`.`url` AS `owner-link`,
1668         `owner`.`addr` AS `owner-addr`,
1669         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1670         `owner`.`nick` AS `owner-nick`,
1671         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1672         `owner`.`network` AS `owner-network`,
1673         `owner`.`blocked` AS `owner-blocked`,
1674         `owner`.`hidden` AS `owner-hidden`,
1675         `owner`.`contact-type` AS `owner-contact-type`,
1676         `post-user`.`causer-id` AS `causer-id`,
1677         `causer`.`url` AS `causer-link`,
1678         `causer`.`addr` AS `causer-addr`,
1679         `causer`.`name` AS `causer-name`,
1680         `causer`.`nick` AS `causer-nick`,
1681         `causer`.`thumb` AS `causer-avatar`,
1682         `causer`.`network` AS `causer-network`,
1683         `causer`.`blocked` AS `causer-blocked`,
1684         `causer`.`hidden` AS `causer-hidden`,
1685         `causer`.`contact-type` AS `causer-contact-type`,
1686         `post-delivery-data`.`postopts` AS `postopts`,
1687         `post-delivery-data`.`inform` AS `inform`,
1688         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1689         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1690         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1691         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1692         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1693         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1694         IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1695         `post-user`.`event-id` AS `event-id`,
1696         `event`.`created` AS `event-created`,
1697         `event`.`edited` AS `event-edited`,
1698         `event`.`start` AS `event-start`,
1699         `event`.`finish` AS `event-finish`,
1700         `event`.`summary` AS `event-summary`,
1701         `event`.`desc` AS `event-desc`,
1702         `event`.`location` AS `event-location`,
1703         `event`.`type` AS `event-type`,
1704         `event`.`nofinish` AS `event-nofinish`,
1705         `event`.`ignore` AS `event-ignore`,
1706         `diaspora-interaction`.`interaction` AS `signed_text`,
1707         `parent-item-uri`.`guid` AS `parent-guid`,
1708         `parent-post`.`network` AS `parent-network`,
1709         `parent-post`.`author-id` AS `parent-author-id`,
1710         `parent-post-author`.`url` AS `parent-author-link`,
1711         `parent-post-author`.`name` AS `parent-author-name`,
1712         `parent-post-author`.`network` AS `parent-author-network`,
1713         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1714         `parent-post-author`.`hidden` AS `parent-author-hidden`
1715         FROM `post-user`
1716                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
1717                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
1718                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
1719                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
1720                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
1721                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
1722                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1723                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1724                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1725                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1726                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1727                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
1728                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
1729                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
1730                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
1731                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
1732                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1733
1734 --
1735 -- VIEW post-thread-user-view
1736 --
1737 DROP VIEW IF EXISTS `post-thread-user-view`;
1738 CREATE VIEW `post-thread-user-view` AS SELECT 
1739         `post-user`.`id` AS `id`,
1740         `post-user`.`id` AS `post-user-id`,
1741         `post-thread-user`.`uid` AS `uid`,
1742         `parent-post`.`id` AS `parent`,
1743         `item-uri`.`uri` AS `uri`,
1744         `post-thread-user`.`uri-id` AS `uri-id`,
1745         `parent-item-uri`.`uri` AS `parent-uri`,
1746         `post-user`.`parent-uri-id` AS `parent-uri-id`,
1747         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1748         `post-user`.`thr-parent-id` AS `thr-parent-id`,
1749         `item-uri`.`guid` AS `guid`,
1750         `post-thread-user`.`wall` AS `wall`,
1751         `post-user`.`gravity` AS `gravity`,
1752         `external-item-uri`.`uri` AS `extid`,
1753         `post-user`.`external-id` AS `external-id`,
1754         `post-thread-user`.`created` AS `created`,
1755         `post-user`.`edited` AS `edited`,
1756         `post-thread-user`.`commented` AS `commented`,
1757         `post-thread-user`.`received` AS `received`,
1758         `post-thread-user`.`changed` AS `changed`,
1759         `post-user`.`post-type` AS `post-type`,
1760         `post-user`.`post-reason` AS `post-reason`,
1761         `post-user`.`private` AS `private`,
1762         `post-thread-user`.`pubmail` AS `pubmail`,
1763         `post-thread-user`.`ignored` AS `ignored`,
1764         `post-user`.`visible` AS `visible`,
1765         `post-thread-user`.`starred` AS `starred`,
1766         `post-thread-user`.`pinned` AS `pinned`,
1767         `post-thread-user`.`unseen` AS `unseen`,
1768         `post-user`.`deleted` AS `deleted`,
1769         `post-thread-user`.`origin` AS `origin`,
1770         `post-thread-user`.`forum_mode` AS `forum_mode`,
1771         `post-thread-user`.`mention` AS `mention`,
1772         `post-user`.`global` AS `global`,
1773         `post-thread-user`.`network` AS `network`,
1774         `post-user`.`vid` AS `vid`,
1775         `post-thread-user`.`psid` AS `psid`,
1776         IF (`post-user`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1777         `post-content`.`title` AS `title`,
1778         `post-content`.`content-warning` AS `content-warning`,
1779         `post-content`.`raw-body` AS `raw-body`,
1780         `post-content`.`body` AS `body`,
1781         `post-content`.`rendered-hash` AS `rendered-hash`,
1782         `post-content`.`rendered-html` AS `rendered-html`,
1783         `post-content`.`language` AS `language`,
1784         `post-content`.`plink` AS `plink`,
1785         `post-content`.`location` AS `location`,
1786         `post-content`.`coord` AS `coord`,
1787         `post-content`.`app` AS `app`,
1788         `post-content`.`object-type` AS `object-type`,
1789         `post-content`.`object` AS `object`,
1790         `post-content`.`target-type` AS `target-type`,
1791         `post-content`.`target` AS `target`,
1792         `post-content`.`resource-id` AS `resource-id`,
1793         `post-thread-user`.`contact-id` AS `contact-id`,
1794         `contact`.`url` AS `contact-link`,
1795         `contact`.`addr` AS `contact-addr`,
1796         `contact`.`name` AS `contact-name`,
1797         `contact`.`nick` AS `contact-nick`,
1798         `contact`.`thumb` AS `contact-avatar`,
1799         `contact`.`network` AS `contact-network`,
1800         `contact`.`blocked` AS `contact-blocked`,
1801         `contact`.`hidden` AS `contact-hidden`,
1802         `contact`.`readonly` AS `contact-readonly`,
1803         `contact`.`archive` AS `contact-archive`,
1804         `contact`.`pending` AS `contact-pending`,
1805         `contact`.`rel` AS `contact-rel`,
1806         `contact`.`uid` AS `contact-uid`,
1807         `contact`.`contact-type` AS `contact-contact-type`,
1808         IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
1809         `contact`.`self` AS `self`,
1810         `contact`.`id` AS `cid`,
1811         `contact`.`alias` AS `alias`,
1812         `contact`.`photo` AS `photo`,
1813         `contact`.`name-date` AS `name-date`,
1814         `contact`.`uri-date` AS `uri-date`,
1815         `contact`.`avatar-date` AS `avatar-date`,
1816         `contact`.`thumb` AS `thumb`,
1817         `post-thread-user`.`author-id` AS `author-id`,
1818         `author`.`url` AS `author-link`,
1819         `author`.`addr` AS `author-addr`,
1820         IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
1821         `author`.`nick` AS `author-nick`,
1822         IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
1823         `author`.`network` AS `author-network`,
1824         `author`.`blocked` AS `author-blocked`,
1825         `author`.`hidden` AS `author-hidden`,
1826         `post-thread-user`.`owner-id` AS `owner-id`,
1827         `owner`.`url` AS `owner-link`,
1828         `owner`.`addr` AS `owner-addr`,
1829         IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
1830         `owner`.`nick` AS `owner-nick`,
1831         IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
1832         `owner`.`network` AS `owner-network`,
1833         `owner`.`blocked` AS `owner-blocked`,
1834         `owner`.`hidden` AS `owner-hidden`,
1835         `owner`.`contact-type` AS `owner-contact-type`,
1836         `post-thread-user`.`causer-id` AS `causer-id`,
1837         `causer`.`url` AS `causer-link`,
1838         `causer`.`addr` AS `causer-addr`,
1839         `causer`.`name` AS `causer-name`,
1840         `causer`.`nick` AS `causer-nick`,
1841         `causer`.`thumb` AS `causer-avatar`,
1842         `causer`.`network` AS `causer-network`,
1843         `causer`.`blocked` AS `causer-blocked`,
1844         `causer`.`hidden` AS `causer-hidden`,
1845         `causer`.`contact-type` AS `causer-contact-type`,
1846         `post-delivery-data`.`postopts` AS `postopts`,
1847         `post-delivery-data`.`inform` AS `inform`,
1848         `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
1849         `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
1850         `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
1851         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
1852         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
1853         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
1854         IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
1855         `post-user`.`event-id` AS `event-id`,
1856         `event`.`created` AS `event-created`,
1857         `event`.`edited` AS `event-edited`,
1858         `event`.`start` AS `event-start`,
1859         `event`.`finish` AS `event-finish`,
1860         `event`.`summary` AS `event-summary`,
1861         `event`.`desc` AS `event-desc`,
1862         `event`.`location` AS `event-location`,
1863         `event`.`type` AS `event-type`,
1864         `event`.`nofinish` AS `event-nofinish`,
1865         `event`.`ignore` AS `event-ignore`,
1866         `diaspora-interaction`.`interaction` AS `signed_text`,
1867         `parent-item-uri`.`guid` AS `parent-guid`,
1868         `parent-post`.`network` AS `parent-network`,
1869         `parent-post`.`author-id` AS `parent-author-id`,
1870         `parent-post-author`.`url` AS `parent-author-link`,
1871         `parent-post-author`.`name` AS `parent-author-name`,
1872         `parent-post-author`.`network` AS `parent-author-network`,
1873         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1874         `parent-post-author`.`hidden` AS `parent-author-hidden`
1875         FROM `post-thread-user`
1876                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
1877                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
1878                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
1879                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
1880                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
1881                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread-user`.`uri-id`
1882                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
1883                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
1884                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post-user`.`external-id`
1885                         LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
1886                         LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
1887                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
1888                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
1889                         LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
1890                         LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
1891                         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`
1892                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
1893
1894 --
1895 -- VIEW post-view
1896 --
1897 DROP VIEW IF EXISTS `post-view`;
1898 CREATE VIEW `post-view` AS SELECT 
1899         `item-uri`.`uri` AS `uri`,
1900         `post`.`uri-id` AS `uri-id`,
1901         `parent-item-uri`.`uri` AS `parent-uri`,
1902         `post`.`parent-uri-id` AS `parent-uri-id`,
1903         `thr-parent-item-uri`.`uri` AS `thr-parent`,
1904         `post`.`thr-parent-id` AS `thr-parent-id`,
1905         `item-uri`.`guid` AS `guid`,
1906         `post`.`gravity` AS `gravity`,
1907         `external-item-uri`.`uri` AS `extid`,
1908         `post`.`external-id` AS `external-id`,
1909         `post`.`created` AS `created`,
1910         `post`.`edited` AS `edited`,
1911         `post-thread`.`commented` AS `commented`,
1912         `post`.`received` AS `received`,
1913         `post-thread`.`changed` AS `changed`,
1914         `post`.`post-type` AS `post-type`,
1915         `post`.`private` AS `private`,
1916         `post`.`visible` AS `visible`,
1917         `post`.`deleted` AS `deleted`,
1918         `post`.`global` AS `global`,
1919         `post`.`network` AS `network`,
1920         `post`.`vid` AS `vid`,
1921         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
1922         `post-content`.`title` AS `title`,
1923         `post-content`.`content-warning` AS `content-warning`,
1924         `post-content`.`raw-body` AS `raw-body`,
1925         `post-content`.`body` AS `body`,
1926         `post-content`.`rendered-hash` AS `rendered-hash`,
1927         `post-content`.`rendered-html` AS `rendered-html`,
1928         `post-content`.`language` AS `language`,
1929         `post-content`.`plink` AS `plink`,
1930         `post-content`.`location` AS `location`,
1931         `post-content`.`coord` AS `coord`,
1932         `post-content`.`app` AS `app`,
1933         `post-content`.`object-type` AS `object-type`,
1934         `post-content`.`object` AS `object`,
1935         `post-content`.`target-type` AS `target-type`,
1936         `post-content`.`target` AS `target`,
1937         `post-content`.`resource-id` AS `resource-id`,
1938         `post`.`author-id` AS `contact-id`,
1939         `author`.`url` AS `contact-link`,
1940         `author`.`addr` AS `contact-addr`,
1941         `author`.`name` AS `contact-name`,
1942         `author`.`nick` AS `contact-nick`,
1943         `author`.`thumb` AS `contact-avatar`,
1944         `author`.`network` AS `contact-network`,
1945         `author`.`blocked` AS `contact-blocked`,
1946         `author`.`hidden` AS `contact-hidden`,
1947         `author`.`readonly` AS `contact-readonly`,
1948         `author`.`archive` AS `contact-archive`,
1949         `author`.`pending` AS `contact-pending`,
1950         `author`.`rel` AS `contact-rel`,
1951         `author`.`uid` AS `contact-uid`,
1952         `author`.`contact-type` AS `contact-contact-type`,
1953         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
1954         false AS `self`,
1955         `author`.`id` AS `cid`,
1956         `author`.`alias` AS `alias`,
1957         `author`.`photo` AS `photo`,
1958         `author`.`name-date` AS `name-date`,
1959         `author`.`uri-date` AS `uri-date`,
1960         `author`.`avatar-date` AS `avatar-date`,
1961         `author`.`thumb` AS `thumb`,
1962         `post`.`author-id` AS `author-id`,
1963         `author`.`url` AS `author-link`,
1964         `author`.`addr` AS `author-addr`,
1965         `author`.`name` AS `author-name`,
1966         `author`.`nick` AS `author-nick`,
1967         `author`.`thumb` AS `author-avatar`,
1968         `author`.`network` AS `author-network`,
1969         `author`.`blocked` AS `author-blocked`,
1970         `author`.`hidden` AS `author-hidden`,
1971         `post`.`owner-id` AS `owner-id`,
1972         `owner`.`url` AS `owner-link`,
1973         `owner`.`addr` AS `owner-addr`,
1974         `owner`.`name` AS `owner-name`,
1975         `owner`.`nick` AS `owner-nick`,
1976         `owner`.`thumb` AS `owner-avatar`,
1977         `owner`.`network` AS `owner-network`,
1978         `owner`.`blocked` AS `owner-blocked`,
1979         `owner`.`hidden` AS `owner-hidden`,
1980         `owner`.`contact-type` AS `owner-contact-type`,
1981         `post`.`causer-id` AS `causer-id`,
1982         `causer`.`url` AS `causer-link`,
1983         `causer`.`addr` AS `causer-addr`,
1984         `causer`.`name` AS `causer-name`,
1985         `causer`.`nick` AS `causer-nick`,
1986         `causer`.`thumb` AS `causer-avatar`,
1987         `causer`.`network` AS `causer-network`,
1988         `causer`.`blocked` AS `causer-blocked`,
1989         `causer`.`hidden` AS `causer-hidden`,
1990         `causer`.`contact-type` AS `causer-contact-type`,
1991         `diaspora-interaction`.`interaction` AS `signed_text`,
1992         `parent-item-uri`.`guid` AS `parent-guid`,
1993         `parent-post`.`network` AS `parent-network`,
1994         `parent-post`.`author-id` AS `parent-author-id`,
1995         `parent-post-author`.`url` AS `parent-author-link`,
1996         `parent-post-author`.`name` AS `parent-author-name`,
1997         `parent-post-author`.`network` AS `parent-author-network`,
1998         `parent-post-author`.`blocked` AS `parent-author-blocked`,
1999         `parent-post-author`.`hidden` AS `parent-author-hidden`
2000         FROM `post`
2001                         STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
2002                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
2003                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
2004                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
2005                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
2006                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2007                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2008                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2009                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2010                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
2011                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
2012                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2013                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2014
2015 --
2016 -- VIEW post-thread-view
2017 --
2018 DROP VIEW IF EXISTS `post-thread-view`;
2019 CREATE VIEW `post-thread-view` AS SELECT 
2020         `item-uri`.`uri` AS `uri`,
2021         `post-thread`.`uri-id` AS `uri-id`,
2022         `parent-item-uri`.`uri` AS `parent-uri`,
2023         `post`.`parent-uri-id` AS `parent-uri-id`,
2024         `thr-parent-item-uri`.`uri` AS `thr-parent`,
2025         `post`.`thr-parent-id` AS `thr-parent-id`,
2026         `item-uri`.`guid` AS `guid`,
2027         `post`.`gravity` AS `gravity`,
2028         `external-item-uri`.`uri` AS `extid`,
2029         `post`.`external-id` AS `external-id`,
2030         `post-thread`.`created` AS `created`,
2031         `post`.`edited` AS `edited`,
2032         `post-thread`.`commented` AS `commented`,
2033         `post-thread`.`received` AS `received`,
2034         `post-thread`.`changed` AS `changed`,
2035         `post`.`post-type` AS `post-type`,
2036         `post`.`private` AS `private`,
2037         `post`.`visible` AS `visible`,
2038         `post`.`deleted` AS `deleted`,
2039         `post`.`global` AS `global`,
2040         `post-thread`.`network` AS `network`,
2041         `post`.`vid` AS `vid`,
2042         IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
2043         `post-content`.`title` AS `title`,
2044         `post-content`.`content-warning` AS `content-warning`,
2045         `post-content`.`raw-body` AS `raw-body`,
2046         `post-content`.`body` AS `body`,
2047         `post-content`.`rendered-hash` AS `rendered-hash`,
2048         `post-content`.`rendered-html` AS `rendered-html`,
2049         `post-content`.`language` AS `language`,
2050         `post-content`.`plink` AS `plink`,
2051         `post-content`.`location` AS `location`,
2052         `post-content`.`coord` AS `coord`,
2053         `post-content`.`app` AS `app`,
2054         `post-content`.`object-type` AS `object-type`,
2055         `post-content`.`object` AS `object`,
2056         `post-content`.`target-type` AS `target-type`,
2057         `post-content`.`target` AS `target`,
2058         `post-content`.`resource-id` AS `resource-id`,
2059         `post-thread`.`author-id` AS `contact-id`,
2060         `author`.`url` AS `contact-link`,
2061         `author`.`addr` AS `contact-addr`,
2062         `author`.`name` AS `contact-name`,
2063         `author`.`nick` AS `contact-nick`,
2064         `author`.`thumb` AS `contact-avatar`,
2065         `author`.`network` AS `contact-network`,
2066         `author`.`blocked` AS `contact-blocked`,
2067         `author`.`hidden` AS `contact-hidden`,
2068         `author`.`readonly` AS `contact-readonly`,
2069         `author`.`archive` AS `contact-archive`,
2070         `author`.`pending` AS `contact-pending`,
2071         `author`.`rel` AS `contact-rel`,
2072         `author`.`uid` AS `contact-uid`,
2073         `author`.`contact-type` AS `contact-contact-type`,
2074         IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `author`.`writable`) AS `writable`,
2075         false AS `self`,
2076         `author`.`id` AS `cid`,
2077         `author`.`alias` AS `alias`,
2078         `author`.`photo` AS `photo`,
2079         `author`.`name-date` AS `name-date`,
2080         `author`.`uri-date` AS `uri-date`,
2081         `author`.`avatar-date` AS `avatar-date`,
2082         `author`.`thumb` AS `thumb`,
2083         `post-thread`.`author-id` AS `author-id`,
2084         `author`.`url` AS `author-link`,
2085         `author`.`addr` AS `author-addr`,
2086         `author`.`name` AS `author-name`,
2087         `author`.`nick` AS `author-nick`,
2088         `author`.`thumb` AS `author-avatar`,
2089         `author`.`network` AS `author-network`,
2090         `author`.`blocked` AS `author-blocked`,
2091         `author`.`hidden` AS `author-hidden`,
2092         `post-thread`.`owner-id` AS `owner-id`,
2093         `owner`.`url` AS `owner-link`,
2094         `owner`.`addr` AS `owner-addr`,
2095         `owner`.`name` AS `owner-name`,
2096         `owner`.`nick` AS `owner-nick`,
2097         `owner`.`thumb` AS `owner-avatar`,
2098         `owner`.`network` AS `owner-network`,
2099         `owner`.`blocked` AS `owner-blocked`,
2100         `owner`.`hidden` AS `owner-hidden`,
2101         `owner`.`contact-type` AS `owner-contact-type`,
2102         `post-thread`.`causer-id` AS `causer-id`,
2103         `causer`.`url` AS `causer-link`,
2104         `causer`.`addr` AS `causer-addr`,
2105         `causer`.`name` AS `causer-name`,
2106         `causer`.`nick` AS `causer-nick`,
2107         `causer`.`thumb` AS `causer-avatar`,
2108         `causer`.`network` AS `causer-network`,
2109         `causer`.`blocked` AS `causer-blocked`,
2110         `causer`.`hidden` AS `causer-hidden`,
2111         `causer`.`contact-type` AS `causer-contact-type`,
2112         `diaspora-interaction`.`interaction` AS `signed_text`,
2113         `parent-item-uri`.`guid` AS `parent-guid`,
2114         `parent-post`.`network` AS `parent-network`,
2115         `parent-post`.`author-id` AS `parent-author-id`,
2116         `parent-post-author`.`url` AS `parent-author-link`,
2117         `parent-post-author`.`name` AS `parent-author-name`,
2118         `parent-post-author`.`network` AS `parent-author-network`,
2119         `parent-post-author`.`blocked` AS `parent-author-blocked`,
2120         `parent-post-author`.`hidden` AS `parent-author-hidden`
2121         FROM `post-thread`
2122                         INNER JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
2123                         STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
2124                         STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
2125                         LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
2126                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-thread`.`uri-id`
2127                         LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
2128                         LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
2129                         LEFT JOIN `item-uri` AS `external-item-uri` ON `external-item-uri`.`id` = `post`.`external-id`
2130                         LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
2131                         LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
2132                         LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
2133                         LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
2134                         LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
2135
2136 --
2137 -- VIEW category-view
2138 --
2139 DROP VIEW IF EXISTS `category-view`;
2140 CREATE VIEW `category-view` AS SELECT 
2141         `post-category`.`uri-id` AS `uri-id`,
2142         `post-category`.`uid` AS `uid`,
2143         `post-category`.`type` AS `type`,
2144         `post-category`.`tid` AS `tid`,
2145         `tag`.`name` AS `name`,
2146         `tag`.`url` AS `url`
2147         FROM `post-category`
2148                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`;
2149
2150 --
2151 -- VIEW tag-view
2152 --
2153 DROP VIEW IF EXISTS `tag-view`;
2154 CREATE VIEW `tag-view` AS SELECT 
2155         `post-tag`.`uri-id` AS `uri-id`,
2156         `post-tag`.`type` AS `type`,
2157         `post-tag`.`tid` AS `tid`,
2158         `post-tag`.`cid` AS `cid`,
2159         CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
2160         CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
2161         FROM `post-tag`
2162                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
2163                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
2164
2165 --
2166 -- VIEW network-item-view
2167 --
2168 DROP VIEW IF EXISTS `network-item-view`;
2169 CREATE VIEW `network-item-view` AS SELECT 
2170         `post-user`.`uri-id` AS `uri-id`,
2171         `parent-post`.`id` AS `parent`,
2172         `post-user`.`received` AS `received`,
2173         `post-thread-user`.`commented` AS `commented`,
2174         `post-user`.`created` AS `created`,
2175         `post-user`.`uid` AS `uid`,
2176         `post-thread-user`.`starred` AS `starred`,
2177         `post-thread-user`.`mention` AS `mention`,
2178         `post-user`.`network` AS `network`,
2179         `post-user`.`unseen` AS `unseen`,
2180         `post-user`.`gravity` AS `gravity`,
2181         `post-user`.`contact-id` AS `contact-id`,
2182         `ownercontact`.`contact-type` AS `contact-type`
2183         FROM `post-user`
2184                         STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`                  
2185                         INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2186                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2187                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2188                         INNER JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2189                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2190                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2191                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2192                         AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
2193                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2194                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2195
2196 --
2197 -- VIEW network-thread-view
2198 --
2199 DROP VIEW IF EXISTS `network-thread-view`;
2200 CREATE VIEW `network-thread-view` AS SELECT 
2201         `post-thread-user`.`uri-id` AS `uri-id`,
2202         `parent-post`.`id` AS `parent`,
2203         `post-thread-user`.`received` AS `received`,
2204         `post-thread-user`.`commented` AS `commented`,
2205         `post-thread-user`.`created` AS `created`,
2206         `post-thread-user`.`uid` AS `uid`,
2207         `post-thread-user`.`starred` AS `starred`,
2208         `post-thread-user`.`mention` AS `mention`,
2209         `post-thread-user`.`network` AS `network`,
2210         `post-thread-user`.`contact-id` AS `contact-id`,
2211         `ownercontact`.`contact-type` AS `contact-type`
2212         FROM `post-thread-user`
2213                         INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
2214                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
2215                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
2216                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
2217                         LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
2218                         LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
2219                         WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
2220                         AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
2221                         AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
2222                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
2223                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
2224
2225 --
2226 -- VIEW owner-view
2227 --
2228 DROP VIEW IF EXISTS `owner-view`;
2229 CREATE VIEW `owner-view` AS SELECT 
2230         `contact`.`id` AS `id`,
2231         `contact`.`uid` AS `uid`,
2232         `contact`.`created` AS `created`,
2233         `contact`.`updated` AS `updated`,
2234         `contact`.`self` AS `self`,
2235         `contact`.`remote_self` AS `remote_self`,
2236         `contact`.`rel` AS `rel`,
2237         `contact`.`network` AS `network`,
2238         `contact`.`protocol` AS `protocol`,
2239         `contact`.`name` AS `name`,
2240         `contact`.`nick` AS `nick`,
2241         `contact`.`location` AS `location`,
2242         `contact`.`about` AS `about`,
2243         `contact`.`keywords` AS `keywords`,
2244         `contact`.`xmpp` AS `xmpp`,
2245         `contact`.`matrix` AS `matrix`,
2246         `contact`.`attag` AS `attag`,
2247         `contact`.`avatar` AS `avatar`,
2248         `contact`.`photo` AS `photo`,
2249         `contact`.`thumb` AS `thumb`,
2250         `contact`.`micro` AS `micro`,
2251         `contact`.`header` AS `header`,
2252         `contact`.`url` AS `url`,
2253         `contact`.`nurl` AS `nurl`,
2254         `contact`.`uri-id` AS `uri-id`,
2255         `contact`.`addr` AS `addr`,
2256         `contact`.`alias` AS `alias`,
2257         `contact`.`pubkey` AS `pubkey`,
2258         `contact`.`prvkey` AS `prvkey`,
2259         `contact`.`batch` AS `batch`,
2260         `contact`.`request` AS `request`,
2261         `contact`.`notify` AS `notify`,
2262         `contact`.`poll` AS `poll`,
2263         `contact`.`confirm` AS `confirm`,
2264         `contact`.`poco` AS `poco`,
2265         `contact`.`subhub` AS `subhub`,
2266         `contact`.`hub-verify` AS `hub-verify`,
2267         `contact`.`last-update` AS `last-update`,
2268         `contact`.`success_update` AS `success_update`,
2269         `contact`.`failure_update` AS `failure_update`,
2270         `contact`.`name-date` AS `name-date`,
2271         `contact`.`uri-date` AS `uri-date`,
2272         `contact`.`avatar-date` AS `avatar-date`,
2273         `contact`.`avatar-date` AS `picdate`,
2274         `contact`.`term-date` AS `term-date`,
2275         `contact`.`last-item` AS `last-item`,
2276         `contact`.`priority` AS `priority`,
2277         `user`.`blocked` AS `blocked`,
2278         `contact`.`block_reason` AS `block_reason`,
2279         `contact`.`readonly` AS `readonly`,
2280         `contact`.`writable` AS `writable`,
2281         `contact`.`forum` AS `forum`,
2282         `contact`.`prv` AS `prv`,
2283         `contact`.`contact-type` AS `contact-type`,
2284         `contact`.`manually-approve` AS `manually-approve`,
2285         `contact`.`hidden` AS `hidden`,
2286         `contact`.`archive` AS `archive`,
2287         `contact`.`pending` AS `pending`,
2288         `contact`.`deleted` AS `deleted`,
2289         `contact`.`unsearchable` AS `unsearchable`,
2290         `contact`.`sensitive` AS `sensitive`,
2291         `contact`.`baseurl` AS `baseurl`,
2292         `contact`.`reason` AS `reason`,
2293         `contact`.`info` AS `info`,
2294         `contact`.`bdyear` AS `bdyear`,
2295         `contact`.`bd` AS `bd`,
2296         `contact`.`notify_new_posts` AS `notify_new_posts`,
2297         `contact`.`fetch_further_information` AS `fetch_further_information`,
2298         `contact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2299         `user`.`parent-uid` AS `parent-uid`,
2300         `user`.`guid` AS `guid`,
2301         `user`.`nickname` AS `nickname`,
2302         `user`.`email` AS `email`,
2303         `user`.`openid` AS `openid`,
2304         `user`.`timezone` AS `timezone`,
2305         `user`.`language` AS `language`,
2306         `user`.`register_date` AS `register_date`,
2307         `user`.`login_date` AS `login_date`,
2308         `user`.`default-location` AS `default-location`,
2309         `user`.`allow_location` AS `allow_location`,
2310         `user`.`theme` AS `theme`,
2311         `user`.`pubkey` AS `upubkey`,
2312         `user`.`prvkey` AS `uprvkey`,
2313         `user`.`sprvkey` AS `sprvkey`,
2314         `user`.`spubkey` AS `spubkey`,
2315         `user`.`verified` AS `verified`,
2316         `user`.`blockwall` AS `blockwall`,
2317         `user`.`hidewall` AS `hidewall`,
2318         `user`.`blocktags` AS `blocktags`,
2319         `user`.`unkmail` AS `unkmail`,
2320         `user`.`cntunkmail` AS `cntunkmail`,
2321         `user`.`notify-flags` AS `notify-flags`,
2322         `user`.`page-flags` AS `page-flags`,
2323         `user`.`account-type` AS `account-type`,
2324         `user`.`prvnets` AS `prvnets`,
2325         `user`.`maxreq` AS `maxreq`,
2326         `user`.`expire` AS `expire`,
2327         `user`.`account_removed` AS `account_removed`,
2328         `user`.`account_expired` AS `account_expired`,
2329         `user`.`account_expires_on` AS `account_expires_on`,
2330         `user`.`expire_notification_sent` AS `expire_notification_sent`,
2331         `user`.`def_gid` AS `def_gid`,
2332         `user`.`allow_cid` AS `allow_cid`,
2333         `user`.`allow_gid` AS `allow_gid`,
2334         `user`.`deny_cid` AS `deny_cid`,
2335         `user`.`deny_gid` AS `deny_gid`,
2336         `user`.`openidserver` AS `openidserver`,
2337         `profile`.`publish` AS `publish`,
2338         `profile`.`net-publish` AS `net-publish`,
2339         `profile`.`hide-friends` AS `hide-friends`,
2340         `profile`.`prv_keywords` AS `prv_keywords`,
2341         `profile`.`pub_keywords` AS `pub_keywords`,
2342         `profile`.`address` AS `address`,
2343         `profile`.`locality` AS `locality`,
2344         `profile`.`region` AS `region`,
2345         `profile`.`postal-code` AS `postal-code`,
2346         `profile`.`country-name` AS `country-name`,
2347         `profile`.`homepage` AS `homepage`,
2348         `profile`.`dob` AS `dob`
2349         FROM `user`
2350                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
2351                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
2352
2353 --
2354 -- VIEW account-view
2355 --
2356 DROP VIEW IF EXISTS `account-view`;
2357 CREATE VIEW `account-view` AS SELECT 
2358         `contact`.`id` AS `id`,
2359         `contact`.`url` AS `url`,
2360         `contact`.`nurl` AS `nurl`,
2361         `contact`.`uri-id` AS `uri-id`,
2362         `item-uri`.`guid` AS `guid`,
2363         `contact`.`addr` AS `addr`,
2364         `contact`.`alias` AS `alias`,
2365         `contact`.`name` AS `name`,
2366         `contact`.`nick` AS `nick`,
2367         `contact`.`about` AS `about`,
2368         `contact`.`keywords` AS `keywords`,
2369         `contact`.`xmpp` AS `xmpp`,
2370         `contact`.`matrix` AS `matrix`,
2371         `contact`.`avatar` AS `avatar`,
2372         `contact`.`photo` AS `photo`,
2373         `contact`.`thumb` AS `thumb`,
2374         `contact`.`micro` AS `micro`,
2375         `contact`.`header` AS `header`,
2376         `contact`.`created` AS `created`,
2377         `contact`.`updated` AS `updated`,
2378         `contact`.`network` AS `network`,
2379         `contact`.`protocol` AS `protocol`,
2380         `contact`.`location` AS `location`,
2381         `contact`.`attag` AS `attag`,
2382         `contact`.`pubkey` AS `pubkey`,
2383         `contact`.`prvkey` AS `prvkey`,
2384         `contact`.`subscribe` AS `subscribe`,
2385         `contact`.`last-update` AS `last-update`,
2386         `contact`.`success_update` AS `success_update`,
2387         `contact`.`failure_update` AS `failure_update`,
2388         `contact`.`failed` AS `failed`,
2389         `contact`.`last-item` AS `last-item`,
2390         `contact`.`last-discovery` AS `last-discovery`,
2391         `contact`.`contact-type` AS `contact-type`,
2392         `contact`.`manually-approve` AS `manually-approve`,
2393         `contact`.`unsearchable` AS `unsearchable`,
2394         `contact`.`sensitive` AS `sensitive`,
2395         `contact`.`baseurl` AS `baseurl`,
2396         `contact`.`gsid` AS `gsid`,
2397         `contact`.`info` AS `info`,
2398         `contact`.`bdyear` AS `bdyear`,
2399         `contact`.`bd` AS `bd`,
2400         `contact`.`poco` AS `poco`,
2401         `contact`.`name-date` AS `name-date`,
2402         `contact`.`uri-date` AS `uri-date`,
2403         `contact`.`avatar-date` AS `avatar-date`,
2404         `contact`.`term-date` AS `term-date`,
2405         `contact`.`hidden` AS `global-ignored`,
2406         `contact`.`blocked` AS `global-blocked`,
2407         `contact`.`hidden` AS `hidden`,
2408         `contact`.`archive` AS `archive`,
2409         `contact`.`deleted` AS `deleted`,
2410         `contact`.`blocked` AS `blocked`,
2411         `contact`.`request` AS `dfrn-request`,
2412         `contact`.`notify` AS `dfrn-notify`,
2413         `contact`.`poll` AS `dfrn-poll`,
2414         `contact`.`confirm` AS `dfrn-confirm`,
2415         `fcontact`.`guid` AS `diaspora-guid`,
2416         `fcontact`.`batch` AS `diaspora-batch`,
2417         `fcontact`.`notify` AS `diaspora-notify`,
2418         `fcontact`.`poll` AS `diaspora-poll`,
2419         `fcontact`.`alias` AS `diaspora-alias`,
2420         `apcontact`.`uuid` AS `ap-uuid`,
2421         `apcontact`.`type` AS `ap-type`,
2422         `apcontact`.`following` AS `ap-following`,
2423         `apcontact`.`followers` AS `ap-followers`,
2424         `apcontact`.`inbox` AS `ap-inbox`,
2425         `apcontact`.`outbox` AS `ap-outbox`,
2426         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2427         `apcontact`.`generator` AS `ap-generator`,
2428         `apcontact`.`following_count` AS `ap-following_count`,
2429         `apcontact`.`followers_count` AS `ap-followers_count`,
2430         `apcontact`.`statuses_count` AS `ap-statuses_count`
2431         FROM `contact`
2432                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
2433                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
2434                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
2435                         WHERE `contact`.`uid` = 0;
2436
2437 --
2438 -- VIEW account-user-view
2439 --
2440 DROP VIEW IF EXISTS `account-user-view`;
2441 CREATE VIEW `account-user-view` AS SELECT 
2442         `ucontact`.`id` AS `id`,
2443         `contact`.`id` AS `pid`,
2444         `ucontact`.`uid` AS `uid`,
2445         `contact`.`url` AS `url`,
2446         `contact`.`nurl` AS `nurl`,
2447         `contact`.`uri-id` AS `uri-id`,
2448         `item-uri`.`guid` AS `guid`,
2449         `contact`.`addr` AS `addr`,
2450         `contact`.`alias` AS `alias`,
2451         `contact`.`name` AS `name`,
2452         `contact`.`nick` AS `nick`,
2453         `contact`.`about` AS `about`,
2454         `contact`.`keywords` AS `keywords`,
2455         `contact`.`xmpp` AS `xmpp`,
2456         `contact`.`matrix` AS `matrix`,
2457         `contact`.`avatar` AS `avatar`,
2458         `contact`.`photo` AS `photo`,
2459         `contact`.`thumb` AS `thumb`,
2460         `contact`.`micro` AS `micro`,
2461         `contact`.`header` AS `header`,
2462         `contact`.`created` AS `created`,
2463         `contact`.`updated` AS `updated`,
2464         `ucontact`.`self` AS `self`,
2465         `ucontact`.`remote_self` AS `remote_self`,
2466         `ucontact`.`rel` AS `rel`,
2467         `contact`.`network` AS `network`,
2468         `ucontact`.`protocol` AS `protocol`,
2469         `contact`.`location` AS `location`,
2470         `ucontact`.`attag` AS `attag`,
2471         `contact`.`pubkey` AS `pubkey`,
2472         `contact`.`prvkey` AS `prvkey`,
2473         `contact`.`subscribe` AS `subscribe`,
2474         `contact`.`last-update` AS `last-update`,
2475         `contact`.`success_update` AS `success_update`,
2476         `contact`.`failure_update` AS `failure_update`,
2477         `contact`.`failed` AS `failed`,
2478         `contact`.`last-item` AS `last-item`,
2479         `contact`.`last-discovery` AS `last-discovery`,
2480         `contact`.`contact-type` AS `contact-type`,
2481         `contact`.`manually-approve` AS `manually-approve`,
2482         `contact`.`unsearchable` AS `unsearchable`,
2483         `contact`.`sensitive` AS `sensitive`,
2484         `contact`.`baseurl` AS `baseurl`,
2485         `contact`.`gsid` AS `gsid`,
2486         `ucontact`.`info` AS `info`,
2487         `contact`.`bdyear` AS `bdyear`,
2488         `contact`.`bd` AS `bd`,
2489         `contact`.`poco` AS `poco`,
2490         `contact`.`name-date` AS `name-date`,
2491         `contact`.`uri-date` AS `uri-date`,
2492         `contact`.`avatar-date` AS `avatar-date`,
2493         `contact`.`term-date` AS `term-date`,
2494         `contact`.`hidden` AS `global-ignored`,
2495         `contact`.`blocked` AS `global-blocked`,
2496         `ucontact`.`hidden` AS `hidden`,
2497         `ucontact`.`archive` AS `archive`,
2498         `ucontact`.`pending` AS `pending`,
2499         `ucontact`.`deleted` AS `deleted`,
2500         `ucontact`.`notify_new_posts` AS `notify_new_posts`,
2501         `ucontact`.`fetch_further_information` AS `fetch_further_information`,
2502         `ucontact`.`ffi_keyword_denylist` AS `ffi_keyword_denylist`,
2503         `ucontact`.`rating` AS `rating`,
2504         `ucontact`.`readonly` AS `readonly`,
2505         `ucontact`.`blocked` AS `blocked`,
2506         `ucontact`.`block_reason` AS `block_reason`,
2507         `ucontact`.`subhub` AS `subhub`,
2508         `ucontact`.`hub-verify` AS `hub-verify`,
2509         `ucontact`.`reason` AS `reason`,
2510         `contact`.`request` AS `dfrn-request`,
2511         `contact`.`notify` AS `dfrn-notify`,
2512         `contact`.`poll` AS `dfrn-poll`,
2513         `contact`.`confirm` AS `dfrn-confirm`,
2514         `fcontact`.`guid` AS `diaspora-guid`,
2515         `fcontact`.`batch` AS `diaspora-batch`,
2516         `fcontact`.`notify` AS `diaspora-notify`,
2517         `fcontact`.`poll` AS `diaspora-poll`,
2518         `fcontact`.`alias` AS `diaspora-alias`,
2519         `apcontact`.`uuid` AS `ap-uuid`,
2520         `apcontact`.`type` AS `ap-type`,
2521         `apcontact`.`following` AS `ap-following`,
2522         `apcontact`.`followers` AS `ap-followers`,
2523         `apcontact`.`inbox` AS `ap-inbox`,
2524         `apcontact`.`outbox` AS `ap-outbox`,
2525         `apcontact`.`sharedinbox` AS `ap-sharedinbox`,
2526         `apcontact`.`generator` AS `ap-generator`,
2527         `apcontact`.`following_count` AS `ap-following_count`,
2528         `apcontact`.`followers_count` AS `ap-followers_count`,
2529         `apcontact`.`statuses_count` AS `ap-statuses_count`
2530         FROM `contact` AS `ucontact`
2531                         INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
2532                         LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
2533                         LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
2534                         LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr';
2535
2536 --
2537 -- VIEW pending-view
2538 --
2539 DROP VIEW IF EXISTS `pending-view`;
2540 CREATE VIEW `pending-view` AS SELECT 
2541         `register`.`id` AS `id`,
2542         `register`.`hash` AS `hash`,
2543         `register`.`created` AS `created`,
2544         `register`.`uid` AS `uid`,
2545         `register`.`password` AS `password`,
2546         `register`.`language` AS `language`,
2547         `register`.`note` AS `note`,
2548         `contact`.`self` AS `self`,
2549         `contact`.`name` AS `name`,
2550         `contact`.`url` AS `url`,
2551         `contact`.`micro` AS `micro`,
2552         `user`.`email` AS `email`,
2553         `contact`.`nick` AS `nick`
2554         FROM `register`
2555                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
2556                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
2557
2558 --
2559 -- VIEW tag-search-view
2560 --
2561 DROP VIEW IF EXISTS `tag-search-view`;
2562 CREATE VIEW `tag-search-view` AS SELECT 
2563         `post-tag`.`uri-id` AS `uri-id`,
2564         `post-user`.`uid` AS `uid`,
2565         `post-user`.`id` AS `iid`,
2566         `post-user`.`private` AS `private`,
2567         `post-user`.`wall` AS `wall`,
2568         `post-user`.`origin` AS `origin`,
2569         `post-user`.`global` AS `global`,
2570         `post-user`.`gravity` AS `gravity`,
2571         `post-user`.`received` AS `received`,
2572         `post-user`.`network` AS `network`,
2573         `post-user`.`author-id` AS `author-id`,
2574         `tag`.`name` AS `name`
2575         FROM `post-tag`
2576                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
2577                         STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post-tag`.`uri-id`
2578                         WHERE `post-tag`.`type` = 1;
2579
2580 --
2581 -- VIEW workerqueue-view
2582 --
2583 DROP VIEW IF EXISTS `workerqueue-view`;
2584 CREATE VIEW `workerqueue-view` AS SELECT 
2585         `process`.`pid` AS `pid`,
2586         `workerqueue`.`priority` AS `priority`
2587         FROM `process`
2588                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
2589                         WHERE NOT `workerqueue`.`done`;
2590
2591 --
2592 -- VIEW profile_field-view
2593 --
2594 DROP VIEW IF EXISTS `profile_field-view`;
2595 CREATE VIEW `profile_field-view` AS SELECT
2596           `profile_field`.`id` AS `id`,
2597           `profile_field`.`uid` AS `uid`,
2598           `profile_field`.`label` AS `label`,
2599           `profile_field`.`value` AS `value`,
2600           `profile_field`.`order` AS `order`,
2601           `profile_field`.`psid` AS `psid`,
2602           `permissionset`.`allow_cid` AS `allow_cid`,
2603           `permissionset`.`allow_gid` AS `allow_gid`,
2604           `permissionset`.`deny_cid` AS `deny_cid`,
2605           `permissionset`.`deny_gid` AS `deny_gid`,
2606           `profile_field`.`created` AS `created`,
2607           `profile_field`.`edited` AS `edited`
2608   FROM `profile_field`
2609                    INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`;