digikam/digikam-5.8.0.fix-db-migration-0001.patch

237 lines
19 KiB
Diff

From 5893fde69518d70904d2b96e13800c7432b4e4c4 Mon Sep 17 00:00:00 2001
From: Maik Qualmann <metzpinguin@gmail.com>
Date: Mon, 15 Jan 2018 20:24:41 +0100
Subject: fix schema update from V7/8 to V9 with temporary tables BUGS: 388977
BUGS: 388867 BUGS: 388824 FIXED-IN: 5.9.0
---
data/database/dbconfig.xml.cmake.in | 154 +++++++++++++++++++++++++++++-------
2 files changed, 124 insertions(+), 30 deletions(-)
diff --git a/data/database/dbconfig.xml.cmake.in b/data/database/dbconfig.xml.cmake.in
index a315361..2c5008f 100644
--- a/data/database/dbconfig.xml.cmake.in
+++ b/data/database/dbconfig.xml.cmake.in
@@ -1992,8 +1992,6 @@
END IF;
END;
</statement>
- <statement mode="plain">SET SESSION OLD_ALTER_TABLE=1;</statement>
- <statement mode="plain">SET SESSION FOREIGN_KEY_CHECKS=0;</statement>
<statement mode="plain">DROP TRIGGER IF EXISTS delete_image;</statement>
<statement mode="plain">DROP TRIGGER IF EXISTS delete_tag;</statement>
<statement mode="plain">DROP TRIGGER IF EXISTS move_tagstree;</statement>
@@ -2064,85 +2062,181 @@
<statement mode="plain">ALTER TABLE TagProperties MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci;</statement>
<statement mode="plain">ALTER TABLE ImageTagProperties MODIFY COLUMN property TEXT CHARACTER SET utf8 COLLATE utf8_general_ci;</statement>
<statement mode="plain">ALTER TABLE ImageTagProperties MODIFY COLUMN value LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci;</statement>
- <statement mode="plain">ALTER IGNORE TABLE AlbumRoots
+
+ <statement mode="plain">RENAME TABLE AlbumRoots TO AlbumRoots_old;</statement>
+ <statement mode="plain">CREATE TABLE AlbumRoots LIKE AlbumRoots_old;</statement>
+ <statement mode="plain">ALTER TABLE AlbumRoots
ADD UNIQUE (identifier(127), specificPath(128)),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Albums
+ <statement mode="plain">INSERT IGNORE INTO AlbumRoots SELECT * FROM AlbumRoots_old;</statement>
+
+ <statement mode="plain">RENAME TABLE Albums TO Albums_old;</statement>
+ <statement mode="plain">CREATE TABLE Albums LIKE Albums_old;</statement>
+ <statement mode="plain">ALTER TABLE Albums
ADD CONSTRAINT Albums_AlbumRoots FOREIGN KEY (albumRoot) REFERENCES AlbumRoots (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD UNIQUE (albumRoot, relativePath(255)),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Images
+ <statement mode="plain">INSERT IGNORE INTO Albums SELECT * FROM Albums_old;</statement>
+ <statement mode="plain">UPDATE Albums SET icon = NULL WHERE icon = 0;</statement>
+
+ <statement mode="plain">RENAME TABLE Images TO Images_old;</statement>
+ <statement mode="plain">CREATE TABLE Images LIKE Images_old;</statement>
+ <statement mode="plain">ALTER TABLE Images
ADD CONSTRAINT Images_Albums FOREIGN KEY (album) REFERENCES Albums (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD UNIQUE (album, name(255)),
ENGINE InnoDB;</statement>
- <statement mode="plain">UPDATE Albums SET icon = NULL WHERE icon = 0;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Albums
+ <statement mode="plain">INSERT IGNORE INTO Images SELECT * FROM Images_old;</statement>
+
+ <statement mode="plain">ALTER TABLE Albums
ADD CONSTRAINT Albums_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageHaarMatrix
+
+ <statement mode="plain">RENAME TABLE ImageHaarMatrix TO ImageHaarMatrix_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageHaarMatrix LIKE ImageHaarMatrix_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageHaarMatrix
ADD CONSTRAINT ImageHaarMatrix_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageInformation
+ <statement mode="plain">INSERT IGNORE INTO ImageHaarMatrix SELECT * FROM ImageHaarMatrix_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageInformation TO ImageInformation_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageInformation LIKE ImageInformation_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageInformation
ADD CONSTRAINT ImageInformation_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageMetadata
+ <statement mode="plain">INSERT IGNORE INTO ImageInformation SELECT * FROM ImageInformation_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageMetadata TO ImageMetadata_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageMetadata LIKE ImageMetadata_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageMetadata
ADD CONSTRAINT ImageMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE VideoMetadata
+ <statement mode="plain">INSERT IGNORE INTO ImageMetadata SELECT * FROM ImageMetadata_old;</statement>
+
+ <statement mode="plain">RENAME TABLE VideoMetadata TO VideoMetadata_old;</statement>
+ <statement mode="plain">CREATE TABLE VideoMetadata LIKE VideoMetadata_old;</statement>
+ <statement mode="plain">ALTER TABLE VideoMetadata
ADD CONSTRAINT VideoMetadata_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImagePositions
+ <statement mode="plain">INSERT IGNORE INTO VideoMetadata SELECT * FROM VideoMetadata_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImagePositions TO ImagePositions_old;</statement>
+ <statement mode="plain">CREATE TABLE ImagePositions LIKE ImagePositions_old;</statement>
+ <statement mode="plain">ALTER TABLE ImagePositions
ADD CONSTRAINT ImagePositions_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageComments
+ <statement mode="plain">INSERT IGNORE INTO ImagePositions SELECT * FROM ImagePositions_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageComments TO ImageComments_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageComments LIKE ImageComments_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageComments
ADD CONSTRAINT ImageComments_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD UNIQUE(imageid, type, language, author(202)),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageCopyright
+ <statement mode="plain">INSERT IGNORE INTO ImageComments SELECT * FROM ImageComments_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageCopyright TO ImageCopyright_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageCopyright LIKE ImageCopyright_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageCopyright
ADD CONSTRAINT ImageCopyright_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD UNIQUE(imageid, property(110), value(111), extraValue(111)),
ENGINE InnoDB;</statement>
+ <statement mode="plain">INSERT IGNORE INTO ImageCopyright SELECT * FROM ImageCopyright_old;</statement>
+
+ <statement mode="plain">RENAME TABLE Tags TO Tags_old;</statement>
+ <statement mode="plain">CREATE TABLE Tags LIKE Tags_old;</statement>
+ <statement mode="plain">ALTER TABLE Tags
+ ADD CONSTRAINT Tags_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE,
+ ADD UNIQUE(pid, name(100)),
+ ENGINE InnoDB;</statement>
+ <statement mode="plain">INSERT IGNORE INTO Tags SELECT * FROM Tags_old;</statement>
<statement mode="plain">SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';</statement>
<statement mode="plain">REPLACE INTO Tags (id, pid, name, icon, iconkde, lft, rgt) VALUES (0, -1, '_Digikam_root_tag_', NULL, NULL,
(SELECT MIN(tl.lft) FROM Tags AS tl),
(SELECT MAX(tr.rgt) FROM Tags AS tr));</statement>
<statement mode="plain">SET SQL_MODE=@OLD_SQL_MODE;</statement>
- <statement mode="plain">UPDATE Tags set icon = NULL WHERE icon = 0;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Tags
- ADD CONSTRAINT Tags_Images FOREIGN KEY (icon) REFERENCES Images (id) ON DELETE SET NULL ON UPDATE CASCADE,
- ADD UNIQUE(pid, name(100)),
- ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageTags
+ <statement mode="plain">UPDATE Tags SET icon = NULL WHERE icon = 0;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageTags TO ImageTags_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageTags LIKE ImageTags_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageTags
ADD CONSTRAINT ImageTags_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT ImageTags_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageProperties
+ <statement mode="plain">INSERT IGNORE INTO ImageTags SELECT * FROM ImageTags_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageProperties TO ImageProperties_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageProperties LIKE ImageProperties_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageProperties
ADD CONSTRAINT ImageProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD UNIQUE (imageid, property(255)),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Searches
+ <statement mode="plain">INSERT IGNORE INTO ImageProperties SELECT * FROM ImageProperties_old;</statement>
+
+ <statement mode="plain">ALTER TABLE Searches
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE DownloadHistory
+
+ <statement mode="plain">RENAME TABLE DownloadHistory TO DownloadHistory_old;</statement>
+ <statement mode="plain">CREATE TABLE DownloadHistory LIKE DownloadHistory_old;</statement>
+ <statement mode="plain">ALTER TABLE DownloadHistory
ADD UNIQUE(identifier(164), filename(165), filesize, filedate),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE Settings
+ <statement mode="plain">INSERT IGNORE INTO DownloadHistory SELECT * FROM DownloadHistory_old;</statement>
+
+ <statement mode="plain">RENAME TABLE Settings TO Settings_old;</statement>
+ <statement mode="plain">CREATE TABLE Settings LIKE Settings_old;</statement>
+ <statement mode="plain">ALTER TABLE Settings
ADD UNIQUE(keyword(255)),
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageHistory
+ <statement mode="plain">INSERT IGNORE INTO Settings SELECT * FROM Settings_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageHistory TO ImageHistory_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageHistory LIKE ImageHistory_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageHistory
ADD CONSTRAINT ImageHistory_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageRelations
+ <statement mode="plain">INSERT IGNORE INTO ImageHistory SELECT * FROM ImageHistory_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageRelations TO ImageRelations_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageRelations LIKE ImageRelations_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageRelations
ADD CONSTRAINT ImageRelations_ImagesS FOREIGN KEY (subject) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT ImageRelations_ImagesO FOREIGN KEY (object) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE TagProperties
+ <statement mode="plain">INSERT IGNORE INTO ImageRelations SELECT * FROM ImageRelations_old;</statement>
+
+ <statement mode="plain">RENAME TABLE TagProperties TO TagProperties_old;</statement>
+ <statement mode="plain">CREATE TABLE TagProperties LIKE TagProperties_old;</statement>
+ <statement mode="plain">ALTER TABLE TagProperties
ADD CONSTRAINT TagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">ALTER IGNORE TABLE ImageTagProperties
+ <statement mode="plain">INSERT IGNORE INTO TagProperties SELECT * FROM TagProperties_old;</statement>
+
+ <statement mode="plain">RENAME TABLE ImageTagProperties TO ImageTagProperties_old;</statement>
+ <statement mode="plain">CREATE TABLE ImageTagProperties LIKE ImageTagProperties_old;</statement>
+ <statement mode="plain">ALTER TABLE ImageTagProperties
ADD CONSTRAINT ImageTagProperties_Images FOREIGN KEY (imageid) REFERENCES Images (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT ImageTagProperties_Tags FOREIGN KEY (tagid) REFERENCES Tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
ENGINE InnoDB;</statement>
- <statement mode="plain">SET SESSION FOREIGN_KEY_CHECKS=1;</statement>
- <statement mode="plain">SET SESSION OLD_ALTER_TABLE=0;</statement>
+ <statement mode="plain">INSERT IGNORE INTO ImageTagProperties SELECT * FROM ImageTagProperties_old;</statement>
+
+ <statement mode="plain">DROP TABLE ImageTagProperties_old;</statement>
+ <statement mode="plain">DROP TABLE TagProperties_old;</statement>
+ <statement mode="plain">DROP TABLE ImageRelations_old;</statement>
+ <statement mode="plain">DROP TABLE ImageHistory_old;</statement>
+ <statement mode="plain">DROP TABLE Settings_old;</statement>
+ <statement mode="plain">DROP TABLE DownloadHistory_old;</statement>
+ <statement mode="plain">DROP TABLE ImageProperties_old;</statement>
+ <statement mode="plain">DROP TABLE ImageTags_old;</statement>
+ <statement mode="plain">DROP TABLE Tags_old;</statement>
+ <statement mode="plain">DROP TABLE ImageCopyright_old;</statement>
+ <statement mode="plain">DROP TABLE ImageComments_old;</statement>
+ <statement mode="plain">DROP TABLE ImagePositions_old;</statement>
+ <statement mode="plain">DROP TABLE VideoMetadata_old;</statement>
+ <statement mode="plain">DROP TABLE ImageMetadata_old;</statement>
+ <statement mode="plain">DROP TABLE ImageInformation_old;</statement>
+ <statement mode="plain">DROP TABLE ImageHaarMatrix_old;</statement>
+ <statement mode="plain">DROP TABLE Images_old;</statement>
+ <statement mode="plain">DROP TABLE Albums_old;</statement>
+ <statement mode="plain">DROP TABLE AlbumRoots_old;</statement>
</dbaction>
<dbaction name="UpdateThumbnailsDBSchemaFromV1ToV2" mode="transaction">
--
cgit v0.11.2