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