sbt tasks do not use scope specific settings
See original GitHub issueHello,
Firstly, thanks for this excellent library. I am really enjoying the compactness and direct SQL-access.
I am trying to use the sbt plugin with a play application. I would like to use different databases for dev and test. I have overridden the flywayUrl
in the Test
scope. But the test:flywayMigrate
task still uses the flywayUrl
setting value and not the test:flywayUrl
setting value.
I have a sample app - https://github.com/diwa/flyway_play_test to reproduce the problem
The following is the configuration extract from build.sbt
flywaySettings
flywayUrl := "jdbc:h2:file:target/devbar"
flywayUser := "SA"
flywayLocations := Seq("filesystem:conf/db/migrations/main")
flywayUrl in Test := "jdbc:h2:file:target/testbar"
flywayLocations in Test := Seq("filesystem:conf/db/migrations/main", "filesystem:conf/db/migrations/test")
SBT session
Global settings are recognized
➜ flyway_play_test git:(master) sbt
[info] Loading project definition from /Users/diwa/code/sandbox/flyway_play_test/project
[info] Set current project to flyway_play_test (in build file:/Users/diwa/code/sandbox/flyway_play_test/)
[flyway_play_test] $ flywayUrl
[info] jdbc:h2:file:target/devbar
[flyway_play_test] $ flywayLocations
[info] List(filesystem:conf/db/migrations/main)
[flyway_play_test] $ flywayInfo
[info] Database: jdbc:h2:file:target/devbar (H2 1.3)
[info] +----------------+----------------------------+---------------------+---------+
[info] | Version | Description | Installed on | State |
[info] +----------------+----------------------------+---------------------+---------+
[info] | 1 | Create person table | | Pending |
[info] +----------------+----------------------------+---------------------+---------+
[success] Total time: 1 s, completed May 25, 2014 10:24:01 PM
Test Scope settings are recognized
[flyway_play_test] $ test:flywayUrl
[info] jdbc:h2:file:target/testbar
[flyway_play_test] $ test:flywayLocations
[info] List(filesystem:conf/db/migrations/main, filesystem:conf/db/migrations/test)
flywayInfo Task does not use test scope settings (see database)
[flyway_play_test] $ test:flywayInfo
[info] Database: jdbc:h2:file:target/devbar (H2 1.3)
[info] +----------------+----------------------------+---------------------+---------+
[info] | Version | Description | Installed on | State |
[info] +----------------+----------------------------+---------------------+---------+
[info] | 1 | Create person table | | Pending |
[info] +----------------+----------------------------+---------------------+---------+
[success] Total time: 0 s, completed May 25, 2014 10:24:25 PM
Normal migration works
[flyway_play_test] $ flywayMigrate
[info] Database: jdbc:h2:file:target/devbar (H2 1.3)
[info] Validated 1 migration (execution time 00:00.003s)
[info] Creating Metadata table: "PUBLIC"."schema_version"
[info] Current version of schema "PUBLIC": << Empty Schema >>
[info] Migrating schema "PUBLIC" to version 1
[info] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.027s).
[success] Total time: 0 s, completed May 25, 2014 10:25:09 PM
Test Scope migration does not work (nothing found to migrate)
[flyway_play_test] $ test:flywayMigrate
[info] Database: jdbc:h2:file:target/devbar (H2 1.3)
[info] Validated 1 migration (execution time 00:00.003s)
[info] Current version of schema "PUBLIC": 1
[info] Schema "PUBLIC" is up to date. No migration necessary.
[success] Total time: 0 s, completed May 25, 2014 10:25:15 PM
Can you please help with this as it is essential to have different dbs for dev and test ?
@jsuereth - Am I doing something wrong in the sbt settings for scopes here ?
Thanks in advance for all your support.
Issue Analytics
- State:
- Created 9 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
sbt Reference Manual — Scopes
Build-level settings are often used as a fallback when a project doesn't define a project-specific setting. We will discuss more on build-level settings...
Read more >How to make a sbt task use a specific configuration scope?
I have a task lazy val task = TaskKey[Unit] that takes a lazy val setting = SettingKey[String] as input. I also have three...
Read more >[sbt] How to make a sbt task use a specific configuration scope?
However, this does not seem to work. > > How can I force task to use the settings from a specific config scope?...
Read more >sbt Beyond the Defaults: Part III - Scopes - Alejandro Marín
sbt has three scope types (called axes) in where each key can be defined with its own value: Project Axis. Configuration Axis. Task...
Read more >Making sense of SBT - Beyond the lines
Scopes. So far we've seen that a setting or task key is always linked to a single value or task body. In fact...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What is the way in Flyway 4.0 to do this? By default, only default and
Test
configuration seem to be respected, and @mikebridge 's solution does not work sinceflywaySettings
is no longer defined.Results in:
@axelfontaine I believe that the current implementation in master is correct. This appears to be the magic sbt incantation to execute tasks in a different Configuration scope:
With that set, I can run either
it:flywayMigrate
orflywayMigrate
and they each find the variables from the correct scope.