Merge pull request #14097 from annando/enable-user-defined-channel
[friendica.git/.git] / database.sql
index da167e2..120edf3 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
--- Friendica 2024.03-dev (Yellow Archangel)
--- DB_UPDATE_VERSION 1549
+-- Friendica 2024.06-dev (Yellow Archangel)
+-- DB_UPDATE_VERSION 1559
 -- ------------------------------------------
 
 
@@ -539,6 +539,7 @@ CREATE TABLE IF NOT EXISTS `contact-relation` (
        `relation-score` smallint unsigned COMMENT 'score for interactions of relation-cid on cid',
        `thread-score` smallint unsigned COMMENT 'score for interactions of cid on threads of relation-cid',
        `relation-thread-score` smallint unsigned COMMENT 'score for interactions of relation-cid on threads of cid',
+       `post-score` smallint unsigned COMMENT 'score for the amount of posts from cid that can be seen by relation-cid',
         PRIMARY KEY(`cid`,`relation-cid`),
         INDEX `relation-cid` (`relation-cid`),
        FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
@@ -1283,6 +1284,7 @@ CREATE TABLE IF NOT EXISTS `post-content` (
        `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
        `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
        `language` text COMMENT 'Language information about this post',
+       `sensitive` boolean COMMENT 'If true, this post contains sensitive content',
        `app` varchar(255) NOT NULL DEFAULT '' COMMENT 'application which generated this item',
        `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '',
        `rendered-html` mediumtext COMMENT 'item.body converted to html',
@@ -1345,11 +1347,12 @@ CREATE TABLE IF NOT EXISTS `post-engagement` (
        `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
        `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
        `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay',
-       `media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio',
-       `language` varchar(128) COMMENT 'Language information about this post',
+       `media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio)',
+       `language` char(2) COMMENT 'Language information about this post in the ISO 639-1 format',
        `searchtext` mediumtext COMMENT 'Simplified text for the full text search',
        `size` int unsigned COMMENT 'Body size',
        `created` datetime COMMENT '',
+       `network` char(4) COMMENT '',
        `restricted` boolean NOT NULL DEFAULT '0' COMMENT 'If true, this post is either unlisted or not from a federated network',
        `comments` mediumint unsigned COMMENT 'Number of comments',
        `activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)',
@@ -1467,14 +1470,19 @@ CREATE TABLE IF NOT EXISTS `post-question-option` (
 --
 CREATE TABLE IF NOT EXISTS `post-searchindex` (
        `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
-       `network` char(4) COMMENT '',
-       `private` tinyint unsigned COMMENT '0=public, 1=private, 2=unlisted',
+       `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
+       `media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio)',
+       `language` char(2) COMMENT 'Language information about this post in the ISO 639-1 format',
        `searchtext` mediumtext COMMENT 'Simplified text for the full text search',
+       `size` int unsigned COMMENT 'Body size',
        `created` datetime COMMENT '',
+       `restricted` boolean NOT NULL DEFAULT '0' COMMENT 'If true, this post is either unlisted or not from a federated network',
         PRIMARY KEY(`uri-id`),
+        INDEX `owner-id` (`owner-id`),
         INDEX `created` (`created`),
         FULLTEXT INDEX `searchtext` (`searchtext`),
-       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
 
 --
@@ -1542,6 +1550,7 @@ CREATE TABLE IF NOT EXISTS `post-user` (
        `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
        `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
        `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
+       `restrictions` tinyint unsigned COMMENT 'Bit array of post restrictions (1 = Reply, 2 = Like, 4 = Announce)',
        `global` boolean NOT NULL DEFAULT '0' COMMENT '',
        `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
        `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
@@ -1939,6 +1948,7 @@ CREATE TABLE IF NOT EXISTS `user-contact` (
        `ignored` boolean COMMENT 'Posts from this contact are ignored',
        `collapsed` boolean COMMENT 'Posts from this contact are collapsed',
        `hidden` boolean COMMENT 'This contact is hidden from the others',
+       `channel-only` boolean COMMENT 'This contact is displayed only in channels, but not in the network stream.',
        `is-blocked` boolean COMMENT 'User is blocked by this contact',
        `channel-frequency` tinyint unsigned COMMENT 'Controls the frequency of the appearance of this contact in channels',
        `pending` boolean COMMENT '',
@@ -2009,7 +2019,8 @@ CREATE VIEW `application-view` AS SELECT
        `application-token`.`follow` AS `follow`,
        `application-token`.`push` AS `push`
        FROM `application-token`
-                       INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`;
+                       INNER JOIN `application` ON `application-token`.`application-id` = `application`.`id`
+                       INNER JOIN `user` ON `user`.`uid` = `application-token`.`uid` AND `user`.`verified` AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND NOT `user`.`account_expired`;
 
 --
 -- VIEW circle-member-view
@@ -2101,6 +2112,38 @@ CREATE VIEW `post-timeline-view` AS SELECT
                        STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
                        LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`;
 
+--
+-- VIEW post-searchindex-user-view
+--
+DROP VIEW IF EXISTS `post-searchindex-user-view`;
+CREATE VIEW `post-searchindex-user-view` AS SELECT 
+       `post-thread-user`.`uid` AS `uid`,
+       `post-searchindex`.`uri-id` AS `uri-id`,
+       `post-searchindex`.`owner-id` AS `owner-id`,
+       `post-searchindex`.`media-type` AS `media-type`,
+       `post-searchindex`.`language` AS `language`,
+       `post-searchindex`.`searchtext` AS `searchtext`,
+       `post-searchindex`.`size` AS `size`,
+       `post-thread-user`.`commented` AS `commented`,
+       `post-thread-user`.`received` AS `received`,
+       `post-thread-user`.`created` AS `created`,
+       `post-thread-user`.`network` AS `network`,
+       `post-searchindex`.`language` AS `restricted`,
+       0 AS `comments`,
+       0 AS `activities`
+       FROM `post-thread-user`
+                       INNER JOIN `post-searchindex` ON `post-searchindex`.`uri-id` = `post-thread-user`.`uri-id`
+                       INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
+                       STRAIGHT_JOIN `contact` AS `authorcontact` ON `authorcontact`.`id` = `post-thread-user`.`author-id`
+                       STRAIGHT_JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
+                       WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
+                       AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
+                       AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
+                       AND NOT `authorcontact`.`blocked` AND NOT `ownercontact`.`blocked`
+                       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`))
+                       AND NOT EXISTS(SELECT `gsid` FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
+
 --
 -- VIEW post-user-view
 --
@@ -2158,6 +2201,8 @@ CREATE VIEW `post-user-view` AS SELECT
        `post-content`.`plink` AS `plink`,
        `post-content`.`location` AS `location`,
        `post-content`.`coord` AS `coord`,
+       `post-content`.`sensitive` AS `sensitive`,
+       `post-user`.`restrictions` AS `restrictions`,
        `post-content`.`app` AS `app`,
        `post-content`.`object-type` AS `object-type`,
        `post-content`.`object` AS `object`,
@@ -2342,6 +2387,8 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `post-content`.`plink` AS `plink`,
        `post-content`.`location` AS `location`,
        `post-content`.`coord` AS `coord`,
+       `post-content`.`sensitive` AS `sensitive`,
+       `post-user`.`restrictions` AS `restrictions`,
        `post-content`.`app` AS `app`,
        `post-content`.`object-type` AS `object-type`,
        `post-content`.`object` AS `object`,
@@ -2512,6 +2559,7 @@ CREATE VIEW `post-view` AS SELECT
        `post-content`.`plink` AS `plink`,
        `post-content`.`location` AS `location`,
        `post-content`.`coord` AS `coord`,
+       `post-content`.`sensitive` AS `sensitive`,
        `post-content`.`app` AS `app`,
        `post-content`.`object-type` AS `object-type`,
        `post-content`.`object` AS `object`,
@@ -2658,6 +2706,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `post-content`.`plink` AS `plink`,
        `post-content`.`location` AS `location`,
        `post-content`.`coord` AS `coord`,
+       `post-content`.`sensitive` AS `sensitive`,
        `post-content`.`app` AS `app`,
        `post-content`.`object-type` AS `object-type`,
        `post-content`.`object` AS `object`,
@@ -2831,36 +2880,6 @@ CREATE VIEW `tag-view` AS SELECT
                        LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
                        LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
 
---
--- VIEW network-item-view
---
-DROP VIEW IF EXISTS `network-item-view`;
-CREATE VIEW `network-item-view` AS SELECT 
-       `post-user`.`uri-id` AS `uri-id`,
-       `post-thread-user`.`post-user-id` AS `parent`,
-       `post-user`.`received` AS `received`,
-       `post-thread-user`.`commented` AS `commented`,
-       `post-user`.`created` AS `created`,
-       `post-user`.`uid` AS `uid`,
-       `post-thread-user`.`starred` AS `starred`,
-       `post-thread-user`.`mention` AS `mention`,
-       `post-user`.`network` AS `network`,
-       `post-user`.`unseen` AS `unseen`,
-       `post-user`.`gravity` AS `gravity`,
-       `post-user`.`contact-id` AS `contact-id`,
-       `ownercontact`.`contact-type` AS `contact-type`
-       FROM `post-user`
-                       INNER JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
-                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
-                       STRAIGHT_JOIN `contact` AS `authorcontact` ON `authorcontact`.`id` = `post-thread-user`.`author-id`
-                       STRAIGHT_JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread-user`.`owner-id`
-                       WHERE `post-user`.`visible` AND NOT `post-user`.`deleted`
-                       AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
-                       AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
-                       AND NOT `authorcontact`.`blocked` AND NOT `ownercontact`.`blocked`
-                       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`))
-                       AND NOT EXISTS(SELECT `gsid`   FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
-
 --
 -- VIEW network-thread-view
 --
@@ -2886,8 +2905,8 @@ CREATE VIEW `network-thread-view` AS SELECT
                        AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
                        AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
                        AND NOT `authorcontact`.`blocked` AND NOT `ownercontact`.`blocked`
-                       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`))
-                       AND NOT EXISTS(SELECT `gsid`   FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
+                       AND NOT EXISTS(SELECT `cid`  FROM `user-contact` WHERE `uid` = `post-thread-user`.`uid` AND `cid` IN (`post-thread-user`.`author-id`, `post-thread-user`.`owner-id`, `post-thread-user`.`causer-id`) AND (`blocked` OR `ignored` OR `channel-only`))
+                       AND NOT EXISTS(SELECT `gsid` FROM `user-gserver` WHERE `uid` = `post-thread-user`.`uid` AND `gsid` IN (`authorcontact`.`gsid`, `ownercontact`.`gsid`) AND `ignored`);
 
 --
 -- VIEW owner-view