From c0272e3e8e68a48125955641e760f78e15670cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Lemaitre?= Date: Wed, 13 Mar 2024 10:57:13 +0100 Subject: [PATCH] fix: remove db migration clash --- build.sbt | 2 +- docToolchainConfig.groovy | 2 +- .../pillars/db/migration/MigrationTests.scala | 29 ++++++++++--------- .../V001__init.sql | 0 .../example/src/main/scala/example/app.scala | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) rename modules/example/src/main/resources/{db/migrations => db-migrations}/V001__init.sql (100%) diff --git a/build.sbt b/build.sbt index 72bc4718e..ba0dcf44e 100644 --- a/build.sbt +++ b/build.sbt @@ -146,7 +146,7 @@ lazy val docs = Project("pillars-docs", file("modules/docs")) lazy val pillars = project .in(file(".")) - .aggregate(core, example, docs, db, flags, httpClient) + .aggregate(core, example, docs, db, dbDoobie, dbMigrations, flags, httpClient) .settings( name := "pillars", publishArtifact := false, diff --git a/docToolchainConfig.groovy b/docToolchainConfig.groovy index de5bdd969..0c970b017 100644 --- a/docToolchainConfig.groovy +++ b/docToolchainConfig.groovy @@ -127,7 +127,7 @@ microsite.with { // set a title to '-' in order to remove this menu entry. menu = ['user-guide': 'User Guide', 'contribute': 'Contribute', 'features': 'Features'] - version = '0.1.0' + version = '0.1.1' //tag::additionalConverters[] /** diff --git a/modules/db-migration/src/test/scala/pillars/db/migration/MigrationTests.scala b/modules/db-migration/src/test/scala/pillars/db/migration/MigrationTests.scala index b949d6294..2990a009b 100644 --- a/modules/db-migration/src/test/scala/pillars/db/migration/MigrationTests.scala +++ b/modules/db-migration/src/test/scala/pillars/db/migration/MigrationTests.scala @@ -11,16 +11,17 @@ import munit.CatsEffectSuite import org.testcontainers.utility.DockerImageName import org.typelevel.otel4s.trace.Tracer import pillars.Config.Secret +import pillars.Module +import pillars.Pillars import pillars.db.* -import pillars.db.migrations.{DBMigration, MigrationConfig} +import pillars.db.migrations.DBMigration +import pillars.db.migrations.MigrationConfig import pillars.probes.ProbeConfig -import pillars.{Module, Pillars} +import scala.concurrent.duration.* import skunk.* import skunk.codec.all.* import skunk.implicits.* -import scala.concurrent.duration.* - class MigrationTests extends CatsEffectSuite, TestContainerForEach: override val containerDef: PostgreSQLContainer.Def = PostgreSQLContainer.Def( @@ -58,11 +59,11 @@ class MigrationTests extends CatsEffectSuite, TestContainerForEach: ) val dbConfig: DatabaseConfig = configFor(pgContainer) val migration = DBMigration[IO](config, dbConfig) - val result = + val result = for - _ <- migration.migrate("db/migrations") + _ <- migration.migrate("db/migrations") res <- session(dbConfig).use: s => - s.unique(sql"SELECT count(*) FROM test where d is not null".query(int8)) + s.unique(sql"SELECT count(*) FROM test where d is not null".query(int8)) yield res assertIO(result, 5L) } @@ -75,11 +76,11 @@ class MigrationTests extends CatsEffectSuite, TestContainerForEach: ) val dbConfig: DatabaseConfig = configFor(pgContainer) val migration = DBMigration[IO](config, dbConfig) - val result = + val result = for - _ <- migration.migrate("db/migrations", DatabaseSchema.public, DatabaseTable("schema_history")) + _ <- migration.migrate("db/migrations", DatabaseSchema.public, DatabaseTable("schema_history")) res <- session(dbConfig).use: s => - s.unique(sql"SELECT count(*) FROM schema_history".query(int8)) + s.unique(sql"SELECT count(*) FROM schema_history".query(int8)) yield res assertIO(result, 3L) // 1 for init and one for each migration file } @@ -92,12 +93,12 @@ class MigrationTests extends CatsEffectSuite, TestContainerForEach: ) val dbConfig: DatabaseConfig = configFor(pgContainer) val migration = DBMigration[IO](config, dbConfig) - val result = + val result = for - _ <- migration.migrate("db/migrations") - _ <- migration.migrate("db/migrations") + _ <- migration.migrate("db/migrations") + _ <- migration.migrate("db/migrations") res <- session(dbConfig).use: s => - s.unique(sql"SELECT count(*) FROM test where d is not null".query(int8)) + s.unique(sql"SELECT count(*) FROM test where d is not null".query(int8)) yield res assertIO(result, 5L) } diff --git a/modules/example/src/main/resources/db/migrations/V001__init.sql b/modules/example/src/main/resources/db-migrations/V001__init.sql similarity index 100% rename from modules/example/src/main/resources/db/migrations/V001__init.sql rename to modules/example/src/main/resources/db-migrations/V001__init.sql diff --git a/modules/example/src/main/scala/example/app.scala b/modules/example/src/main/scala/example/app.scala index 80aa81e0f..8703d837d 100644 --- a/modules/example/src/main/scala/example/app.scala +++ b/modules/example/src/main/scala/example/app.scala @@ -20,7 +20,7 @@ object app extends pillars.EntryPoint: // // <1> def run: Run[IO, IO[Unit]] = // // <4> for _ <- Logger[IO].info(s"📚 Welcome to ${Config[IO].name}!") - _ <- DBMigration[IO].migrate("db/migrations") // // <5> + _ <- DBMigration[IO].migrate("db-migrations") // // <5> _ <- flag"feature-1".whenEnabled: DB[IO].use: session => for