1
1
Fork 0

New foreign key for the "photo" table

This commit is contained in:
Michael 2020-08-21 18:37:58 +00:00
parent 61a2b225bb
commit cbdaf6298a
3 changed files with 12 additions and 4 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2020.09-dev (Red Hot Poker) -- 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_profile` (`uid`,`profile`),
INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`), INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`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'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
-- --

View file

@ -54,7 +54,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1362); define('DB_UPDATE_VERSION', 1363);
} }
return [ return [
@ -984,7 +984,7 @@ return [
"fields" => [ "fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "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"], "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"], "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" => ""], "resource-id" => ["type" => "char(32)", "not null" => "1", "default" => "", "comment" => ""],
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation date"], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation date"],

View file

@ -49,6 +49,7 @@ use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Storage; use Friendica\Model\Storage;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -571,3 +572,9 @@ function pre_update_1358()
return Update::SUCCESS; return Update::SUCCESS;
} }
function pre_update_1363()
{
Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
return Update::SUCCESS;
}