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