mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 02:48:26 +00:00
Fix previously published db migration
This commit is contained in:
@ -17,7 +17,9 @@ import docspell.store.migrate.FlywayMigrate
|
||||
|
||||
import doobie._
|
||||
import munit._
|
||||
import org.h2.jdbcx.JdbcConnectionPool
|
||||
import org.h2.jdbcx.{JdbcConnectionPool, JdbcDataSource}
|
||||
import org.mariadb.jdbc.MariaDbDataSource
|
||||
import org.postgresql.ds.PGConnectionPoolDataSource
|
||||
|
||||
trait StoreFixture extends CatsEffectFunFixtures { self: CatsEffectSuite =>
|
||||
|
||||
@ -26,7 +28,7 @@ trait StoreFixture extends CatsEffectFunFixtures { self: CatsEffectSuite =>
|
||||
for {
|
||||
ds <- StoreFixture.dataSource(cfg)
|
||||
xa <- StoreFixture.makeXA(ds)
|
||||
_ <- Resource.eval(FlywayMigrate.run[IO](cfg))
|
||||
_ <- Resource.eval(FlywayMigrate[IO](cfg, xa).run)
|
||||
} yield xa
|
||||
}
|
||||
|
||||
@ -52,7 +54,30 @@ object StoreFixture {
|
||||
|
||||
def dataSource(jdbc: JdbcConfig): Resource[IO, JdbcConnectionPool] = {
|
||||
def jdbcConnPool =
|
||||
JdbcConnectionPool.create(jdbc.url.asString, jdbc.user, jdbc.password)
|
||||
jdbc.dbmsName match {
|
||||
case Some("mariadb") =>
|
||||
val ds = new MariaDbDataSource()
|
||||
ds.setUrl(jdbc.url.asString)
|
||||
ds.setUser(jdbc.user)
|
||||
ds.setPassword(jdbc.password)
|
||||
JdbcConnectionPool.create(ds)
|
||||
|
||||
case Some("postgresql") =>
|
||||
val ds = new PGConnectionPoolDataSource()
|
||||
ds.setURL(jdbc.url.asString)
|
||||
ds.setUser(jdbc.user)
|
||||
ds.setPassword(jdbc.password)
|
||||
JdbcConnectionPool.create(ds)
|
||||
|
||||
case Some("h2") =>
|
||||
val ds = new JdbcDataSource()
|
||||
ds.setURL(jdbc.url.asString)
|
||||
ds.setUser(jdbc.user)
|
||||
ds.setPassword(jdbc.password)
|
||||
JdbcConnectionPool.create(ds)
|
||||
|
||||
case n => sys.error(s"Unknown db name: $n")
|
||||
}
|
||||
|
||||
Resource.make(IO(jdbcConnPool))(cp => IO(cp.dispose()))
|
||||
}
|
||||
|
@ -18,8 +18,15 @@ class H2MigrateTest extends FunSuite with TestLoggingConfig {
|
||||
|
||||
test("h2 empty schema migration") {
|
||||
val jdbc = StoreFixture.memoryDB("h2test")
|
||||
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
|
||||
assert(result.migrationsExecuted > 0)
|
||||
}
|
||||
val ds = StoreFixture.dataSource(jdbc)
|
||||
val result =
|
||||
ds.flatMap(StoreFixture.makeXA).use { xa =>
|
||||
FlywayMigrate[IO](jdbc, xa).run
|
||||
}
|
||||
|
||||
assert(result.unsafeRunSync().migrationsExecuted > 0)
|
||||
|
||||
// a second time to apply fixup migrations
|
||||
assert(result.unsafeRunSync().migrationsExecuted == 0)
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import cats.effect.unsafe.implicits._
|
||||
|
||||
import docspell.common.LenientUri
|
||||
import docspell.logging.TestLoggingConfig
|
||||
import docspell.store.JdbcConfig
|
||||
import docspell.store.{JdbcConfig, StoreFixture}
|
||||
|
||||
import com.dimafeng.testcontainers.MariaDBContainer
|
||||
import com.dimafeng.testcontainers.munit.TestContainerForAll
|
||||
@ -30,8 +30,13 @@ class MariaDbMigrateTest
|
||||
withContainers { cnt =>
|
||||
val jdbc =
|
||||
JdbcConfig(LenientUri.unsafe(cnt.jdbcUrl), cnt.dbUsername, cnt.dbPassword)
|
||||
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
|
||||
assert(result.migrationsExecuted > 0)
|
||||
val ds = StoreFixture.dataSource(jdbc)
|
||||
val result = ds.flatMap(StoreFixture.makeXA).use { xa =>
|
||||
FlywayMigrate[IO](jdbc, xa).run
|
||||
}
|
||||
assert(result.unsafeRunSync().migrationsExecuted > 0)
|
||||
// a second time to apply fixup migrations
|
||||
assert(result.unsafeRunSync().migrationsExecuted == 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import cats.effect.unsafe.implicits._
|
||||
|
||||
import docspell.common.LenientUri
|
||||
import docspell.logging.TestLoggingConfig
|
||||
import docspell.store.JdbcConfig
|
||||
import docspell.store.{JdbcConfig, StoreFixture}
|
||||
|
||||
import com.dimafeng.testcontainers.PostgreSQLContainer
|
||||
import com.dimafeng.testcontainers.munit.TestContainerForAll
|
||||
@ -30,8 +30,16 @@ class PostgresqlMigrateTest
|
||||
withContainers { cnt =>
|
||||
val jdbc =
|
||||
JdbcConfig(LenientUri.unsafe(cnt.jdbcUrl), cnt.username, cnt.password)
|
||||
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
|
||||
assert(result.migrationsExecuted > 0)
|
||||
|
||||
val ds = StoreFixture.dataSource(jdbc)
|
||||
val result =
|
||||
ds.flatMap(StoreFixture.makeXA).use { xa =>
|
||||
FlywayMigrate[IO](jdbc, xa).run
|
||||
}
|
||||
assert(result.unsafeRunSync().migrationsExecuted > 0)
|
||||
|
||||
// a second time to apply fixup migrations
|
||||
assert(result.unsafeRunSync().migrationsExecuted == 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user