From d43f00836ad17d9804add15161b53b5b51391441 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 13 Feb 2024 22:32:19 +0900 Subject: [PATCH] fix(db/migrate): delete return types and run `unsafeRunSync` before select a data from db --- .../qualtet/infrastructure/db/Migrator.scala | 4 ++-- .../qualtet/infrastructure/db/MigratorSpec.scala | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/scala/net/yoshinorin/qualtet/infrastructure/db/Migrator.scala b/src/main/scala/net/yoshinorin/qualtet/infrastructure/db/Migrator.scala index 3f266e8a..819ad421 100644 --- a/src/main/scala/net/yoshinorin/qualtet/infrastructure/db/Migrator.scala +++ b/src/main/scala/net/yoshinorin/qualtet/infrastructure/db/Migrator.scala @@ -14,7 +14,7 @@ class Migrator(config: DBConfig) { /** * Do migration */ - def migrate[F[_]: Monad](contentTypeService: ContentTypeService[F]): Unit = { + def migrate[F[_]: Monad](contentTypeService: ContentTypeService[F]) = { val _ = flyway.migrate() (for { _ <- contentTypeService.create(ContentType(name = "article")) @@ -34,7 +34,7 @@ class Migrator(config: DBConfig) { * DROP all tables and re-create * NOTE: for development */ - def recrate[F[_]: Monad](contentTypeService: ContentTypeService[F]): Unit = { + def recrate[F[_]: Monad](contentTypeService: ContentTypeService[F]) = { this.clean() this.migrate(contentTypeService) } diff --git a/src/test/scala/net/yoshinorin/qualtet/infrastructure/db/MigratorSpec.scala b/src/test/scala/net/yoshinorin/qualtet/infrastructure/db/MigratorSpec.scala index fe920e47..e94c3056 100644 --- a/src/test/scala/net/yoshinorin/qualtet/infrastructure/db/MigratorSpec.scala +++ b/src/test/scala/net/yoshinorin/qualtet/infrastructure/db/MigratorSpec.scala @@ -1,6 +1,5 @@ package net.yoshinorin.qualtet.infrastructure.db -import cats.effect.IO import net.yoshinorin.qualtet.fixture.Fixture.contentTypeService import net.yoshinorin.qualtet.Modules import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor @@ -16,14 +15,16 @@ class MigratorSpec extends AnyWordSpec { "Migrator" should { "be migrate" in { - val (a, p) = (for { - _ <- IO(Modules.migrator.migrate(contentTypeService)) + + Modules.migrator.migrate(contentTypeService).unsafeRunSync() + + val result = (for { a <- contentTypeService.findByName("article") p <- contentTypeService.findByName("page") } yield (a, p)).unsafeRunSync() - assert(a.isDefined) - assert(p.isDefined) + assert(result._1.isDefined) + assert(result._2.isDefined) } }