fix(migration): add idempotent guards to V114-V117 migrations
Add IF NOT EXISTS / IF EXISTS / DROP IF EXISTS guards to prevent failures when migrations are re-run after partial application on MariaDB which lacks transactional DDL support.
This commit is contained in:
@@ -97,5 +97,5 @@ CREATE TABLE IF NOT EXISTS comic_metadata_creator_mapping
|
|||||||
CONSTRAINT fk_comic_creator_mapping_creator FOREIGN KEY (creator_id) REFERENCES comic_creator (id) ON DELETE CASCADE
|
CONSTRAINT fk_comic_creator_mapping_creator FOREIGN KEY (creator_id) REFERENCES comic_creator (id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_comic_creator_mapping_role ON comic_metadata_creator_mapping (role);
|
CREATE INDEX IF NOT EXISTS idx_comic_creator_mapping_role ON comic_metadata_creator_mapping (role);
|
||||||
CREATE INDEX idx_comic_creator_mapping_book ON comic_metadata_creator_mapping (book_id);
|
CREATE INDEX IF NOT EXISTS idx_comic_creator_mapping_book ON comic_metadata_creator_mapping (book_id);
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
ALTER TABLE library
|
ALTER TABLE library
|
||||||
ADD COLUMN metadata_source VARCHAR(20) DEFAULT 'EMBEDDED';
|
ADD COLUMN IF NOT EXISTS metadata_source VARCHAR(20) DEFAULT 'EMBEDDED';
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
ALTER TABLE library_path
|
ALTER TABLE library_path
|
||||||
DROP FOREIGN KEY fk_library_path;
|
DROP FOREIGN KEY IF EXISTS fk_library_path;
|
||||||
ALTER TABLE library_path
|
ALTER TABLE library_path
|
||||||
ADD CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE;
|
ADD CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE;
|
||||||
|
|||||||
+4
@@ -1,3 +1,4 @@
|
|||||||
|
DROP TRIGGER IF EXISTS trg_cleanup_orphaned_comic_character;
|
||||||
CREATE TRIGGER trg_cleanup_orphaned_comic_character
|
CREATE TRIGGER trg_cleanup_orphaned_comic_character
|
||||||
AFTER DELETE
|
AFTER DELETE
|
||||||
ON comic_metadata_character_mapping
|
ON comic_metadata_character_mapping
|
||||||
@@ -7,6 +8,7 @@ CREATE TRIGGER trg_cleanup_orphaned_comic_character
|
|||||||
WHERE id = OLD.character_id
|
WHERE id = OLD.character_id
|
||||||
AND NOT EXISTS (SELECT 1 FROM comic_metadata_character_mapping WHERE character_id = OLD.character_id);
|
AND NOT EXISTS (SELECT 1 FROM comic_metadata_character_mapping WHERE character_id = OLD.character_id);
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_cleanup_orphaned_comic_team;
|
||||||
CREATE TRIGGER trg_cleanup_orphaned_comic_team
|
CREATE TRIGGER trg_cleanup_orphaned_comic_team
|
||||||
AFTER DELETE
|
AFTER DELETE
|
||||||
ON comic_metadata_team_mapping
|
ON comic_metadata_team_mapping
|
||||||
@@ -16,6 +18,7 @@ CREATE TRIGGER trg_cleanup_orphaned_comic_team
|
|||||||
WHERE id = OLD.team_id
|
WHERE id = OLD.team_id
|
||||||
AND NOT EXISTS (SELECT 1 FROM comic_metadata_team_mapping WHERE team_id = OLD.team_id);
|
AND NOT EXISTS (SELECT 1 FROM comic_metadata_team_mapping WHERE team_id = OLD.team_id);
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_cleanup_orphaned_comic_location;
|
||||||
CREATE TRIGGER trg_cleanup_orphaned_comic_location
|
CREATE TRIGGER trg_cleanup_orphaned_comic_location
|
||||||
AFTER DELETE
|
AFTER DELETE
|
||||||
ON comic_metadata_location_mapping
|
ON comic_metadata_location_mapping
|
||||||
@@ -25,6 +28,7 @@ CREATE TRIGGER trg_cleanup_orphaned_comic_location
|
|||||||
WHERE id = OLD.location_id
|
WHERE id = OLD.location_id
|
||||||
AND NOT EXISTS (SELECT 1 FROM comic_metadata_location_mapping WHERE location_id = OLD.location_id);
|
AND NOT EXISTS (SELECT 1 FROM comic_metadata_location_mapping WHERE location_id = OLD.location_id);
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_cleanup_orphaned_comic_creator;
|
||||||
CREATE TRIGGER trg_cleanup_orphaned_comic_creator
|
CREATE TRIGGER trg_cleanup_orphaned_comic_creator
|
||||||
AFTER DELETE
|
AFTER DELETE
|
||||||
ON comic_metadata_creator_mapping
|
ON comic_metadata_creator_mapping
|
||||||
|
|||||||
Reference in New Issue
Block a user