From eb57758e257df8b5bae3c42f531cafc993adff1b Mon Sep 17 00:00:00 2001 From: Pat Losoponkul Date: Wed, 14 Sep 2022 15:44:51 +0700 Subject: [PATCH] feat(castor): initializing transactorLayer type can fail --- .../iohk/atala/castor/apiserver/Modules.scala | 18 +++++++++++------- .../service/docker/docker-compose-local.yaml | 2 +- .../JdbcDIDOperationRepository.scala | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/castor/service/api-server/src/main/scala/io/iohk/atala/castor/apiserver/Modules.scala b/castor/service/api-server/src/main/scala/io/iohk/atala/castor/apiserver/Modules.scala index 6c940a8876..923b093548 100644 --- a/castor/service/api-server/src/main/scala/io/iohk/atala/castor/apiserver/Modules.scala +++ b/castor/service/api-server/src/main/scala/io/iohk/atala/castor/apiserver/Modules.scala @@ -99,16 +99,20 @@ object GrpcModule { } object RepoModule { - val transactorLayer: ULayer[Transactor[Task]] = ZLayer.succeed( - Transactor.fromDriverManager[Task]( - "org.postgresql.Driver", - "jdbc:postgresql://localhost:5432/castor?user=postgres&password=postgres", - "postgres", - "postgres" + // NOTE: consider migrating to Hikari connection pool + val transactorLayer: TaskLayer[Transactor[Task]] = ZLayer.fromZIO( + ZIO.attempt( + Transactor.fromDriverManager[Task]( + "org.postgresql.Driver", + "jdbc:postgresql://localhost:5432/castor", + "postgres", + "postgres" + ) ) ) - val didOperationRepoLayer: ULayer[DIDOperationRepository[Task]] = transactorLayer >>> JdbcDIDOperationRepository.layer + val didOperationRepoLayer: TaskLayer[DIDOperationRepository[Task]] = + transactorLayer >>> JdbcDIDOperationRepository.layer val layers = didOperationRepoLayer } diff --git a/castor/service/docker/docker-compose-local.yaml b/castor/service/docker/docker-compose-local.yaml index 98ae0a927d..27a3d1dc5a 100644 --- a/castor/service/docker/docker-compose-local.yaml +++ b/castor/service/docker/docker-compose-local.yaml @@ -13,7 +13,7 @@ services: volumes: - pg_data_castor_db:/var/lib/postgresql/data - # delay to ensure DB is up before apply migrations + # delay to ensure DB is up before applying migrations db_init_delay: image: alpine:3 command: sleep 5 diff --git a/castor/service/sql/src/main/scala/io/iohk/atala/castor/sql/repository/JdbcDIDOperationRepository.scala b/castor/service/sql/src/main/scala/io/iohk/atala/castor/sql/repository/JdbcDIDOperationRepository.scala index 31952f5567..d59ad1c923 100644 --- a/castor/service/sql/src/main/scala/io/iohk/atala/castor/sql/repository/JdbcDIDOperationRepository.scala +++ b/castor/service/sql/src/main/scala/io/iohk/atala/castor/sql/repository/JdbcDIDOperationRepository.scala @@ -11,11 +11,11 @@ import zio.interop.catz.* class JdbcDIDOperationRepository(xa: Transactor[Task]) extends DIDOperationRepository[Task] { override def getPublishedOperations: Task[Seq[PublishedDIDOperation]] = { - val io = sql""" + val cxnIO = sql""" |SELECT foo FROM public.published_did_operations |""".stripMargin.query[String].to[Seq] - io.transact(xa) + cxnIO.transact(xa) .map(_.map(PublishedDIDOperation.apply)) }