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