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