通过SBT中的系统属性指定flywayUrl [英] Specifying flywayUrl through system property in SBT

查看:88
本文介绍了通过SBT中的系统属性指定flywayUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flyway sbt 如何通过系统属性( -D )而不是 flywayUrl 来指定通过 build.sbt

Using Flyway with sbt how can the flywayUrl be specified through system properties (-D) instead of via build.sbt?

我想通过命令行运行迁移,并指定所有参数(驱动程序,URL ,用户,密码),而无需在 build.sbt 中定义它们。

I want to run the migrations via command line, specifying all parameters (driver, url, user, password) without defining them in build.sbt.

插件文档页面似乎表明这应该可行:

The plugin documentation page seems to indicate that this should be possible:


优先顺序

系统属性>插件配置

我尝试过这样运行:

sbt -Dflyway.url=jdbc:h2:file:target/foobar -Dflyway.user=SA flywayMigrate

但是飞行路线。 url 属性似乎对b e忽略了在 build.sbt 中定义的 flywayUrl 属性。

But the flyway.url property seems to be ignored in favor of the flywayUrl property defined in build.sbt.

正在考虑包含以下文件的项目:

Considering a project with these files:

libraryDependencies ++= Seq(
    "com.h2database" % "h2" % "1.3.174"
)

seq(flywaySettings: _*)

flywayUrl := "something that should be overriden"



项目/插件。 sbt



project/plugins.sbt

addSbtPlugin("com.googlecode.flyway" % "flyway-sbt" % "2.3")

resolvers += "Flyway" at "http://flywaydb.org/repo"



src / main / resources / db / migration / V1__Create_person_table.sql



src/main/resources/db/migration/V1__Create_person_table.sql

create table PERSON (
    ID int not null,
    NAME varchar(100) not null
);

运行此命令:

$ sbt -Dflyway.url=jdbc:h2:file:target/foobar -Dflyway.user=SA flywayMigrate

产生此错误:

Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Loading project definition from /home/fernando/work/scratch/flyway-sbt/foobar/project
[info] Updating {file:/home/fernando/work/scratch/flyway-sbt/foobar/project/}foobar-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to foobar (in build file:/home/fernando/work/scratch/flyway-sbt/foobar/)
[info] Updating {file:/home/fernando/work/scratch/flyway-sbt/foobar/}foobar...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
com.googlecode.flyway.core.api.FlywayException: Invalid JDBC URL (should start with jdbc:) : something that should be overriden
    at com.googlecode.flyway.core.util.jdbc.DriverDataSource.<init>(DriverDataSource.java:82)
    at com.googlecode.flyway.sbt.FlywayPlugin$FlywayOps$.configure$extension1(FlywayPlugin.scala:214)
    at com.googlecode.flyway.sbt.FlywayPlugin$FlywayOps$.configure$extension0(FlywayPlugin.scala:207)
    at com.googlecode.flyway.sbt.FlywayPlugin$Flyway$.apply(FlywayPlugin.scala:193)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply$mcI$sp(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26$$anonfun$apply$1.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$.withContextClassLoader(FlywayPlugin.scala:184)
    at com.googlecode.flyway.sbt.FlywayPlugin$.com$googlecode$flyway$sbt$FlywayPlugin$$withPrepared(FlywayPlugin.scala:167)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26.apply(FlywayPlugin.scala:145)
    at com.googlecode.flyway.sbt.FlywayPlugin$$anonfun$flywaySettings$26.apply(FlywayPlugin.scala:145)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:35)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
[error] (*:flywayMigrate) com.googlecode.flyway.core.api.FlywayException: Invalid JDBC URL (should start with jdbc:) : something that should be overriden
[error] Total time: 0 s, completed Feb 7, 2014 3:32:39 PM


推荐答案

以下是flywayUrl的定义

val flywayUrl = settingKey[String]("The jdbc url to use to connect to the database.")

我似乎找不到如何通过系统属性设置设置的方法。

I can't seem to find how the setting could be set through the system property. The plugin doesn't seem to support it.

话虽如此,您应该找到以下 build.sbt 解决方案,并可以通过适当的系统属性设置其值:

With that said, you should find the following build.sbt a solution and be able to set its value through an appropriate system property:

flywayUrl := System.getProperty("flyway.url", "[default]")

sbt 在未设置 flyway.url 的情况下执行:

When sbt executed with no flyway.url set:

$ sbt 'show flywayUrl'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to flyway (in build file:/Users/jacek/sandbox/so/flyway/)
[info] [default]

并且在命令上设置了它行:

And when it is set on command line:

$ sbt -Dflyway.url=command-line 'show flywayUrl'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to flyway (in build file:/Users/jacek/sandbox/so/flyway/)
[info] command-line

您可以还找到其他问题在构建中未定义默认值时在命令行上设置设置的值吗?有用。

You may also find the other question Setting value of setting on command line when no default value defined in build? useful.

这篇关于通过SBT中的系统属性指定flywayUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆