LoginSignup
6
2

More than 5 years have passed since last update.

sbtマルチプロジェクト下でのsbt-flyway設定

Last updated at Posted at 2016-04-21

マルチプロジェクトじゃない時

以下の様な構成の時は問題なく動作する。

.
├── build.sbt
├── flyway.sbt
├── project
│   └── plugins.sbt
└── src
    └── main
        └── resources
            └── db
                └── migration
                    ├── V1__create_tables.sql
                    ├── V2__create_tables.sql
                    └── V3__create_tables.sql

plugins.sbt

resolvers += "Flyway" at "https://flywaydb.org/repo"
addSbtPlugin("org.flywaydb" % "flyway-sbt" % "4.0")

flyway.sbt

flywayUser := "ユーザー名"
flywayPassword := "パスワード"
flywayUrl := "jdbc:mysql://localhost:3306/DBスキーマ"

操作

ドキュメント通りこんな感じで使える。

% sbt -Dflyway.target=2 flywayMigrate

詳細は以下を参照。
https://flywaydb.org/documentation/sbt/migrate

マルチプロジェクトにした場合

構造はこのようになり、

.
├── build.sbt
├── project
│   └── plugins.sbt
└── subprojects
    └── XXX
        ├── flyway.sbt
        └── src
            └── main
                └── resources
                    └── db
                        └── migration
                            ├── V1__create_tables.sql
                            ├── V2__create_tables.sql
                            └── V3__create_tables.sql

次にsbtの実行。

% sbt
> project XXX
[XXX] $ flywayMigrate

すると以下の警告が出てしまい、マイグレーション用の各種sqlファイルが読み込めていない模様で当然マイグレーションは実行されない。

[warn] Unable to resolve location filesystem:src/main/resources/db/migration

少しハマってしまったが、flyway.sbtに以下を設定することで無事認識されるようになった。

flywayLocations := Seq("filesystem:./subprojects/XXX/src/main/resources/db/migration")
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2