Apply fixup migration only from previous version

This commit is contained in:
eikek
2022-03-23 23:52:41 +01:00
parent f5c5aab27f
commit 0346c5a654
4 changed files with 976 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -97,4 +97,20 @@ object StoreFixture {
store = new StoreImpl[IO](fr, jdbc, ds, xa)
_ <- Resource.eval(store.migrate)
} yield store
def restoreH2Dump(resourceName: String, ds: DataSource): IO[Unit] =
Option(getClass.getResource(resourceName)).map(_.getFile) match {
case Some(file) =>
IO {
org.log4s.getLogger.info(s"Restoring dump from $file")
val stmt = ds.getConnection.createStatement()
val sql = s"RUNSCRIPT FROM '$file'"
stmt.execute(sql)
stmt.close()
}
case None =>
IO.raiseError(new Exception(s"Resource not found: $resourceName"))
}
}

View File

@ -29,4 +29,21 @@ class H2MigrateTest extends FunSuite with TestLoggingConfig {
// a second time to apply fixup migrations
assert(result.unsafeRunSync().migrationsExecuted == 0)
}
test("h2 upgrade db from 0.24.0") {
val dump = "/docspell-0.24.0-dump-h2-1.24.0-2021-07-13-2307.sql"
val jdbc = StoreFixture.memoryDB("h2test2")
val ds = StoreFixture.dataSource(jdbc)
ds.use(StoreFixture.restoreH2Dump(dump, _)).unsafeRunSync()
val result =
ds.flatMap(StoreFixture.makeXA).use { xa =>
FlywayMigrate[IO](jdbc, xa).run
}
result.unsafeRunSync()
result.unsafeRunSync()
}
}