如何在 IntegrationTest 范围内配置 FlyWay
Posted
技术标签:
【中文标题】如何在 IntegrationTest 范围内配置 FlyWay【英文标题】:How would I configure FlyWay in IntegrationTest scope 【发布时间】:2016-05-05 03:03:08 【问题描述】:我正在尝试在 sbt
的子项目内的 IntegrationTest 配置范围内以不同方式配置 flyway:
// build.sbt
lazy val api = Project.project.in(file("api")).
// ...
settings(flywaySettings: _*).
settings(
// ...
flywayUrl in IntegrationTest := "jdbc:postgresql://localhost:5432/mydb_test"
flywayUser in IntegrationTest := "user"
flywayPassword in IntegrationTest := "pw"
)
但是当从 sbt 运行时,它仍在寻找默认范围内的值:
$ sbt
> api/it:flywayUrl
[info] jdbc:postgresql://localhost:5432/mydb_test
> api/it:flywayUser
[info] user
> api/it:flywayPassword
[info] pw
> api/it:flywayMigrate
// ...
[info] Flyway 3.2.1 by Boxfuse
[trace] Stack trace suppressed: run last api/*:flywayMigrate for the full output.
[error] (api/*:flywayMigrate) org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!
[error] Total time: 3 s, completed 27-Jan-2016 1:33:08 PM
不知道我做错了什么......
【问题讨论】:
看起来这是已修复但仍未部署:github.com/flyway/flyway/issues/763 我认为这不是固定的,即使在未发布的 4.0.0 源中:github.com/flyway/flyway/issues/763#issuecomment-177636052 【参考方案1】:看来我需要使用inConfig
:
// build.sbt
lazy val api = Project.project.in(file("api")).
// copy the settings into the IntegrationTest Configuration
settings(inConfig(IntegrationTest)(flywaySettings): _*).
settings(
// ...
flywayUrl in IntegrationTest := "jdbc:postgresql://localhost:5432/mydb_test"
flywayUser in IntegrationTest := "user"
flywayPassword in IntegrationTest := "pw"
),
现在api/it:flywayMigrate
命令将从正确的范围内获取值。
【讨论】:
以上是关于如何在 IntegrationTest 范围内配置 FlyWay的主要内容,如果未能解决你的问题,请参考以下文章