'flyway-play' 不会 find/connect 连接到 Slick 没有问题的数据库

'flyway-play' does not find/connect to a database that Slick has no problems connecting to

我想用Flyway(flyway-play)做数据库迁移

我在使用 Slick 连接数据库、查询和插入新数据等方面完全没有问题。 但是,我无法让 Flyway 使用它。

当我访问 http://localhost:9000/@flyway/postgres 端点时,我得到 database postgres not found。事实上,在 http://localhost:9000/@flyway 上,我可以看到没有检测到数据库。

我已经准备好迁移并将它们放在 conf\db\migration\postgres 文件夹中。

这是我对 postgres 数据库的配置:

slick {
  dbs {
    postgres {
      driver = "slick.driver.PostgresDriver$"
      db {
        profile = org.postgresql.Driver
        url = "jdbc:postgresql://localhost:5432/"${db-name}
        user = ${db-user}
        password = ${db-password}
        connectionPool = disabled
        keepAliveConnection = true
        autoCommit = false
      }
    }
  }
}

还有我的DatabaseProvider

package database.config

import javax.inject.{Inject, Singleton}

import play.api.db.slick.DatabaseConfigProvider
import play.db.NamedDatabase
import slick.jdbc.{JdbcProfile, PostgresProfile}

@Singleton
final class DatabaseProvider @Inject()(@NamedDatabase("postgres") configProvider: DatabaseConfigProvider) {
  val dbConfig = configProvider.get[PostgresProfile]
}

我还没有测试过,但 flyway 插件似乎希望数据库配置在 db.{dbname} 下并遵循 default config

您可以尝试将此添加到您的 application.conf:

db.default = ${slick.dbs.postgres.db}
db.default.driver = "org.postgresql.Driver"

@vdebergue 感谢您指出正确的方向,我让它工作了。

我将我的迁移移动到 conf\db\migration\default 文件夹中并稍微调整 application.conf 使其看起来像这样:

db {
    default = ${slick.dbs.postgres.db}
    default.migration.locations=["common","postgres"]
}

slick {
  dbs {
    postgres {
      driver = "slick.driver.PostgresDriver$"
      db {
        profile = org.postgresql.Driver
        driver = ${slick.dbs.postgres.db.profile} // required for Flyway
        url = "jdbc:postgresql://localhost:5432/"${db-name}
        user = ${db-user}
        password = ${db-password}
        connectionPool = disabled
        keepAliveConnection = true
        autoCommit = false
      }
    }
  }
}