]> git.mxchange.org Git - friendica.git/commitdiff
New foreign key for the "photo" table
authorMichael <heluecht@pirati.ca>
Fri, 21 Aug 2020 18:37:58 +0000 (18:37 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 21 Aug 2020 18:37:58 +0000 (18:37 +0000)
database.sql
static/dbstructure.config.php
update.php

index f544d319bffe4c62167d1913fbac909eb18f2c30..3622e27930c845f70aa1ace683710fff2d409003 100644 (file)
@@ -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';
 
 --
index 045d0be9719165c23098b1421d5aa25b96aff8c7..e37c343f1e8e8c6bab41ecfb192ceed9784f6ec4 100755 (executable)
@@ -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"],
index 6152e2b1e01e144f760566d98cb3c42e8797477b..a8b238b528affd80554f1a20f1d036336fb31455 100644 (file)
@@ -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