]> git.mxchange.org Git - friendica.git/blobdiff - database.sql
Centralised function for the sort order
[friendica.git] / database.sql
index 5a8cee23c4a88f50949da1cac4009a3d1e83722e..7da771e0ead0309aaec1f05b2a4218ca354e2e29 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2023.09-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1523
+-- DB_UPDATE_VERSION 1531
 -- ------------------------------------------
 
 
@@ -101,6 +101,19 @@ CREATE TABLE IF NOT EXISTS `user` (
        FOREIGN KEY (`parent-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users';
 
+--
+-- TABLE user-gserver
+--
+CREATE TABLE IF NOT EXISTS `user-gserver` (
+       `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
+       `gsid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Gserver id',
+       `ignored` boolean NOT NULL DEFAULT '0' COMMENT 'server accounts are ignored for the user',
+        PRIMARY KEY(`uid`,`gsid`),
+        INDEX `gsid` (`gsid`),
+       FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User settings about remote servers';
+
 --
 -- TABLE item-uri
 --
@@ -160,8 +173,8 @@ CREATE TABLE IF NOT EXISTS `contact` (
        `archive` boolean NOT NULL DEFAULT '0' COMMENT '',
        `unsearchable` boolean NOT NULL DEFAULT '0' COMMENT 'Contact prefers to not be searchable',
        `sensitive` boolean NOT NULL DEFAULT '0' COMMENT 'Contact posts sensitive content',
-       `baseurl` varbinary(383) DEFAULT '' COMMENT 'baseurl of the contact',
-       `gsid` int unsigned COMMENT 'Global Server ID',
+       `baseurl` varbinary(383) DEFAULT '' COMMENT 'baseurl of the contact from the gserver record, can be missing',
+       `gsid` int unsigned COMMENT 'Global Server ID, can be missing',
        `bd` date NOT NULL DEFAULT '0001-01-01' COMMENT '',
        `reason` text COMMENT '',
        `self` boolean NOT NULL DEFAULT '0' COMMENT '1 if the contact is the user him/her self',
@@ -497,9 +510,13 @@ CREATE TABLE IF NOT EXISTS `config` (
 CREATE TABLE IF NOT EXISTS `contact-relation` (
        `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact the related contact had interacted with',
        `relation-cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'related contact who had interacted with the contact',
-       `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction',
+       `last-interaction` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last interaction by relation-cid on cid',
        `follow-updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last update of the contact relationship',
-       `follows` boolean NOT NULL DEFAULT '0' COMMENT '',
+       `follows` boolean NOT NULL DEFAULT '0' COMMENT 'if true, relation-cid follows cid',
+       `score` smallint unsigned COMMENT 'score for interactions of cid on relation-cid',
+       `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',
         PRIMARY KEY(`cid`,`relation-cid`),
         INDEX `relation-cid` (`relation-cid`),
        FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
@@ -1283,6 +1300,25 @@ CREATE TABLE IF NOT EXISTS `post-delivery-data` (
        FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
 
+--
+-- TABLE post-engagement
+--
+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` varbinary(128) COMMENT 'Language information about this post',
+       `created` datetime COMMENT '',
+       `comments` mediumint unsigned COMMENT 'Number of comments',
+       `activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)',
+        PRIMARY KEY(`uri-id`),
+        INDEX `owner-id` (`owner-id`),
+        INDEX `created` (`created`),
+       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 RESTRICT
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Engagement data per post';
+
 --
 -- TABLE post-history
 --
@@ -1586,7 +1622,7 @@ CREATE TABLE IF NOT EXISTS `profile` (
        `profile-name` varchar(255) COMMENT 'Deprecated',
        `is-default` boolean COMMENT 'Deprecated',
        `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile',
-       `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
+       `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Unused in favor of user.username',
        `pdesc` varchar(255) COMMENT 'Deprecated',
        `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth',
        `address` varchar(255) NOT NULL DEFAULT '' COMMENT '',
@@ -1834,8 +1870,8 @@ CREATE TABLE IF NOT EXISTS `user-contact` (
        `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
        `info` mediumtext COMMENT '',
        `notify_new_posts` boolean COMMENT '',
-       `remote_self` boolean COMMENT '',
-       `fetch_further_information` tinyint unsigned COMMENT '',
+       `remote_self` tinyint unsigned COMMENT '0 => No mirroring, 1-2 => Mirror as own post, 3 => Mirror as reshare',
+       `fetch_further_information` tinyint unsigned COMMENT '0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both',
        `ffi_keyword_denylist` text COMMENT '',
        `subhub` boolean COMMENT '',
        `hub-verify` varbinary(383) COMMENT '',
@@ -2032,6 +2068,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
        `author`.`gsid` AS `author-gsid`,
+       `author`.`baseurl` AS `author-baseurl`,
        `post-user`.`owner-id` AS `owner-id`,
        `owner`.`uri-id` AS `owner-uri-id`,
        `owner`.`url` AS `owner-link`,
@@ -2044,6 +2081,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `owner`.`blocked` AS `owner-blocked`,
        `owner`.`hidden` AS `owner-hidden`,
        `owner`.`updated` AS `owner-updated`,
+       `owner`.`gsid` AS `owner-gsid`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-user`.`causer-id` AS `causer-id`,
        `causer`.`uri-id` AS `causer-uri-id`,
@@ -2056,6 +2094,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `causer`.`network` AS `causer-network`,
        `causer`.`blocked` AS `causer-blocked`,
        `causer`.`hidden` AS `causer-hidden`,
+       `causer`.`gsid` AS `causer-gsid`,
        `causer`.`contact-type` AS `causer-contact-type`,
        `post-delivery-data`.`postopts` AS `postopts`,
        `post-delivery-data`.`inform` AS `inform`,
@@ -2189,6 +2228,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `contact`.`pending` AS `contact-pending`,
        `contact`.`rel` AS `contact-rel`,
        `contact`.`uid` AS `contact-uid`,
+       `contact`.`gsid` AS `contact-gsid`,
        `contact`.`contact-type` AS `contact-contact-type`,
        IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
        `contact`.`self` AS `self`,
@@ -2224,6 +2264,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `owner`.`blocked` AS `owner-blocked`,
        `owner`.`hidden` AS `owner-hidden`,
        `owner`.`updated` AS `owner-updated`,
+       `owner`.`gsid` AS `owner-gsid`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-thread-user`.`causer-id` AS `causer-id`,
        `causer`.`uri-id` AS `causer-uri-id`,
@@ -2236,6 +2277,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `causer`.`network` AS `causer-network`,
        `causer`.`blocked` AS `causer-blocked`,
        `causer`.`hidden` AS `causer-hidden`,
+       `causer`.`gsid` AS `causer-gsid`,
        `causer`.`contact-type` AS `causer-contact-type`,
        `post-delivery-data`.`postopts` AS `postopts`,
        `post-delivery-data`.`inform` AS `inform`,
@@ -2391,6 +2433,7 @@ CREATE VIEW `post-view` AS SELECT
        `owner`.`hidden` AS `owner-hidden`,
        `owner`.`updated` AS `owner-updated`,
        `owner`.`contact-type` AS `owner-contact-type`,
+       `owner`.`gsid` AS `owner-gsid`,
        `post`.`causer-id` AS `causer-id`,
        `causer`.`uri-id` AS `causer-uri-id`,
        `causer`.`url` AS `causer-link`,
@@ -2403,6 +2446,7 @@ CREATE VIEW `post-view` AS SELECT
        `causer`.`blocked` AS `causer-blocked`,
        `causer`.`hidden` AS `causer-hidden`,
        `causer`.`contact-type` AS `causer-contact-type`,
+       `causer`.`gsid` AS `causer-gsid`,
        `post-question`.`id` AS `question-id`,
        `post-question`.`multiple` AS `question-multiple`,
        `post-question`.`voters` AS `question-voters`,
@@ -2533,6 +2577,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `owner`.`blocked` AS `owner-blocked`,
        `owner`.`hidden` AS `owner-hidden`,
        `owner`.`updated` AS `owner-updated`,
+       `owner`.`gsid` AS `owner-gsid`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-thread`.`causer-id` AS `causer-id`,
        `causer`.`uri-id` AS `causer-uri-id`,
@@ -2545,6 +2590,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `causer`.`network` AS `causer-network`,
        `causer`.`blocked` AS `causer-blocked`,
        `causer`.`hidden` AS `causer-hidden`,
+       `causer`.`gsid` AS `causer-gsid`,
        `causer`.`contact-type` AS `causer-contact-type`,
        `post-question`.`id` AS `question-id`,
        `post-question`.`multiple` AS `question-multiple`,
@@ -2666,18 +2712,16 @@ CREATE VIEW `network-item-view` AS SELECT
        `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`                     
+                       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`
-                       LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
-                       LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `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 (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
-                       AND (`owner`.`blocked` IS NULL OR NOT `owner`.`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
@@ -2700,14 +2744,12 @@ CREATE VIEW `network-thread-view` AS SELECT
                        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`
-                       LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
-                       LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `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 (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
-                       AND (`owner`.`blocked` IS NULL OR NOT `owner`.`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 owner-view