Skip to content

Commit

Permalink
Improve Database container code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunk3l committed Dec 8, 2021
1 parent f107668 commit d98c0e0
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import org.testcontainers.utility.DockerImageName

class DatabaseContainer {

val dataSource: HikariDataSource

val postgresContainer: PostgreSQLContainer<*> = PostgreSQLContainer(DockerImageName.parse("postgres:14.1"))
.also {
it.withDatabaseName("somedatabasename")
Expand All @@ -19,18 +17,17 @@ class DatabaseContainer {
}
.also { it.start() }

init {
val databaseConfig = HikariConfig().also {
val dataSource: HikariDataSource = HikariConfig()
.also {
it.jdbcUrl = postgresContainer.jdbcUrl
it.username = postgresContainer.username
it.password = postgresContainer.password
it.driverClassName = postgresContainer.driverClassName
}.let {
HikariDataSource(it)
}.also {
Flyway(
FluentConfiguration().dataSource(it)
).migrate()
}
dataSource = HikariDataSource(databaseConfig)

Flyway(
FluentConfiguration()
.dataSource(dataSource)
).migrate()
}
}

0 comments on commit d98c0e0

Please sign in to comment.