【问题标题】:'flyway-play' does not find/connect to a database that Slick has no problems connecting to“flyway-play”没有找到/连接到 Slick 连接没有问题的数据库
【发布时间】:2018-05-04 02:35:48
【问题描述】:

我想使用 Flyway (flyway-play) 进行 db 迁移。

我在使用 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]
}

【问题讨论】:

    标签: scala playframework database-migration slick flyway


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      @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
            }
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-22
        • 2014-08-11
        • 2013-07-26
        • 1970-01-01
        • 1970-01-01
        • 2016-02-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多