mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 02:48:26 +00:00
Apply fixup migration only from previous version
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -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"))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user