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