如何在Play中保留单独的dev,test和prod数据库!2框架?

tux*_*dna 5 testing scala playframework

特别是,对于测试用例,我希望将测试数据库保持独立,以便测试用例不会干扰开发或生产数据库.

分离开发,测试和生产环境有哪些好的做法?

编辑1:一些背景

在Ruby On Rails中,对于不同的环境,按惯例有不同的配置文件.Play也是如此!2还支持吗?

或者,我是否必须烹饪配置文件,然后编写一些选择适当配置文件的粘合代码?

目前,如果我运行sbt test它使用开发数据库(在conf/application.conf中配置为"default").但是我想Play!2使用不同的测试数据库.

EDIT2:播放提供的命令

为......而玩!2框架,我观察到了这一点.

$ help play
Welcome to Play 2.2.2!

These commands are available:
-----------------------------
...OUTPUT SKIPPED...
run <port>                 Run the current application in DEV mode.
test                       Run Junit tests and/or Specs from the command line
start <port>               Start the current application in another JVM in PROD mode.
...OUTPUT SKIPPED...
Run Code Online (Sandbox Code Playgroud)

"test","development"和"production"实例有三个定义良好的命令,它们是:

  • test:这运行测试用例.所以它应该自动选择test配置.
  • run <port>:这将运行development指定的实例port.所以这个命令应该自动选择development配置.
  • start <port>:这将运行production指定的实例port.所以这应该自动选择production配置.

但是,所有这些命令都会选择提供的值conf/application.conf.我觉得这里有一些空白.

如果我错了,请纠正我.

EDIT3:最好的方法是使用Global.scala

这里描述:如何在Play 2.0的几个环境中管理application.conf?

bie*_*ior 0

好的做法是将应用程序的单独实例保存在单独的文件夹中并通过 git repo 同步它们。

当您想保留单个实例时,您可以为每个环境使用替代配置文件

  • 我发现这种方法最合适:http://stackoverflow.com/a/15937831/1119997 (2认同)