-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared): add Flyway Migrations and expose in ZIO Layer to be use…
…d in consuming service (#115) * feat(shared): add Flyway Migrations and expose in ZIO Layer to be used in consuming service Previously, migrations were managed by the infrastructure layer and needed to be composed at docker image build stage. This change allows a consumer of the pollux and castor library to execute migrations in the application layer, by composing a db config layer with the provided miggrations layer and calling the `migrate` method on the output. Implements ATL-2174 * chore(shared): run scalafmt on all castor/lib and pollux/lib
- Loading branch information
davidpoltorak-io
committed
Nov 14, 2022
1 parent
b0ab7d0
commit cd11493
Showing
10 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
castor/lib/sql-doobie/src/main/scala/io/iohk/atala/castor/sql/repository/Migrations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.iohk.atala.castor.sql.repository | ||
|
||
import org.flywaydb.core.Flyway | ||
import zio.* | ||
|
||
import javax.sql.DataSource | ||
|
||
final case class Migrations(config: DbConfig) { | ||
|
||
val migrationScriptsLocation: String = "sql/castor" | ||
|
||
def migrate: Task[Unit] = | ||
ZIO.logInfo("Applying database migrations") | ||
for { | ||
_ <- ZIO.attempt { | ||
Flyway | ||
.configure() | ||
.dataSource( | ||
config.jdbcUrl, | ||
config.username, | ||
config.password | ||
) | ||
.locations(migrationScriptsLocation) | ||
.load() | ||
.migrate() | ||
} | ||
} yield () | ||
|
||
} | ||
|
||
object Migrations { | ||
val layer: URLayer[DbConfig, Migrations] = | ||
ZLayer.fromFunction(Migrations.apply _) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...re/src/main/scala/io/iohk/atala/pollux/core/model/error/PublishCredentialBatchError.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/repository/Migrations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.iohk.atala.pollux.sql.repository | ||
|
||
import org.flywaydb.core.Flyway | ||
import zio.* | ||
|
||
import javax.sql.DataSource | ||
|
||
final case class Migrations(config: DbConfig) { | ||
|
||
val migrationScriptsLocation: String = "sql/pollux" | ||
|
||
def migrate: Task[Unit] = | ||
ZIO.logInfo("Applying database migrations") | ||
for { | ||
_ <- ZIO.attempt { | ||
Flyway | ||
.configure() | ||
.dataSource( | ||
config.jdbcUrl, | ||
config.username, | ||
config.password | ||
) | ||
.locations(migrationScriptsLocation) | ||
.load() | ||
.migrate() | ||
} | ||
} yield () | ||
|
||
} | ||
|
||
object Migrations { | ||
val layer: URLayer[DbConfig, Migrations] = | ||
ZLayer.fromFunction(Migrations.apply _) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters