Skip to content

Commit

Permalink
fix(db/migrate): delete return types and run unsafeRunSync before s…
Browse files Browse the repository at this point in the history
…elect a data from db
  • Loading branch information
yoshinorin committed Feb 13, 2024
1 parent 3bdcbf2 commit d43f008
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

}
Expand Down

0 comments on commit d43f008

Please sign in to comment.