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