From cbdaf6298af2654b6b85fcf7b561ee54935c4dcc Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Aug 2020 18:37:58 +0000 Subject: [PATCH] New foreign key for the "photo" table --- database.sql | 5 +++-- static/dbstructure.config.php | 4 ++-- update.php | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/database.sql b/database.sql index f544d319bf..3622e27930 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2020.09-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1362 +-- DB_UPDATE_VERSION 1363 -- ------------------------------------------ @@ -922,7 +922,8 @@ CREATE TABLE IF NOT EXISTS `photo` ( INDEX `uid_profile` (`uid`,`profile`), INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`), INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`), - INDEX `resource-id` (`resource-id`) + INDEX `resource-id` (`resource-id`), + FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage'; -- diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 045d0be971..e37c343f1e 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -54,7 +54,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1362); + define('DB_UPDATE_VERSION', 1363); } return [ @@ -984,7 +984,7 @@ return [ "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], - "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"], + "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "contact.id"], "guid" => ["type" => "char(16)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this photo"], "resource-id" => ["type" => "char(32)", "not null" => "1", "default" => "", "comment" => ""], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation date"], diff --git a/update.php b/update.php index 6152e2b1e0..a8b238b528 100644 --- a/update.php +++ b/update.php @@ -49,6 +49,7 @@ use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Photo; use Friendica\Model\User; use Friendica\Model\Storage; use Friendica\Util\DateTimeFormat; @@ -571,3 +572,9 @@ function pre_update_1358() return Update::SUCCESS; } + +function pre_update_1363() +{ + Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]); + return Update::SUCCESS; +} \ No newline at end of file