fix: release 0.149.0 could wipe some database entries

fixes the faulty SQL migration
apply flyway repair
mark impacted books as OUTDATED so they can be updated
This commit is contained in:
Gauthier Roebroeck 2022-02-08 19:38:36 +08:00
parent ab6a855091
commit 5f2ce0fb30
3 changed files with 29 additions and 2 deletions

View file

@ -19,8 +19,8 @@ CREATE TABLE PAGE_HASH_THUMBNAIL
PRIMARY KEY (HASH, MEDIA_TYPE, SIZE)
);
DELETE
FROM MEDIA_PAGE
UPDATE MEDIA_PAGE
SET FILE_HASH = ''
WHERE BOOK_ID IN (
SELECT DISTINCT m.BOOK_ID
FROM MEDIA m

View file

@ -0,0 +1,8 @@
UPDATE MEDIA
SET STATUS = 'OUTDATED'
WHERE BOOK_ID IN (
SELECT M.BOOK_ID
FROM MEDIA M
LEFT JOIN MEDIA_PAGE MP on M.BOOK_ID = MP.BOOK_ID
GROUP BY M.BOOK_ID, M.PAGE_COUNT
HAVING M.PAGE_COUNT <> count(MP.BOOK_ID));

View file

@ -0,0 +1,19 @@
package org.gotson.komga.infrastructure.datasource
import org.flywaydb.core.Flyway
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
// TODO: remove after March 2022 - added to fix the 0.149.0 changed migration
// We should not rely on flyway repair on a permanent basis!
@Configuration
class FlywayConfiguration {
@Bean
fun cleanMigrateStrategy() =
FlywayMigrationStrategy { flyway: Flyway ->
flyway.repair()
flyway.migrate()
}
}