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