Fix handling of too long page image urls migration (#1552)

* Delete duplicated chapter page rows by index and chapter

In case duplicated rows based on the condition for the updated unique constraint existed, the new constraint could not be added and caused the migration to fail

* Drop UC_PAGE only if it exists
This commit is contained in:
schroda
2025-07-30 00:00:10 +02:00
committed by GitHub
parent ad7a8dd7dc
commit 02c4398e48

View File

@@ -13,7 +13,14 @@ import de.neonew.exposed.migrations.helpers.SQLMigration
class M0050_FixHandlingOfTooLongPageImageUrls : SQLMigration() {
override val sql: String =
"""
ALTER TABLE PAGE DROP CONSTRAINT UC_PAGE;
DELETE FROM PAGE
WHERE ID NOT IN (
SELECT MIN(ID)
FROM PAGE
GROUP BY INDEX, CHAPTER
);
ALTER TABLE PAGE DROP CONSTRAINT IF EXISTS UC_PAGE;
ALTER TABLE PAGE ADD CONSTRAINT UC_PAGE UNIQUE (INDEX, CHAPTER);
ALTER TABLE PAGE ALTER COLUMN IMAGE_URL VARCHAR; -- the default length is `Integer.MAX_VALUE`