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