11

这是我修改 Play 框架的第一天,我在进化方面遇到了困难。我正在使用播放 2.4。

我从许多出现的应用程序中挑选了一个示例应用程序activator ui,它使用play-slickplay-slick-evolutions用于数据库连接和演变。

我仔细阅读了文档,但似乎找不到从命令行运行演变的方法。当我activator在 bash 上运行时,我被扔进了一个 shell 中,并且help没有提出任何关于运行进化或光滑的信息。

我做 PHP 已经有一段时间了,所以我习惯于从命令行向上/向下运行这些。我可以从数据库客户端中删除表并执行activator run这应该会提示我运行演进,但我正在寻找正确的手动方式来执行此操作。我想这是可能的,因为它需要在部署时完成。

4

2 回答 2

14

As far as I know, they are not designed to be run manually. In development, Play asks you to run them: Play evolutions script application

In Production I trigger the evolutions by starting my server with the parameter -DapplyEvolutions.default=true. You can write this (without -D of course) also to the application.conf-file to run them always. You can also use only the down- or up-evolutions with -DapplyUpEvolutions.default=true or -DapplyDownEvolutions.default=true.

And of course there is always the option to just copy the part of the script you need manually and apply it with your favorite database tool. However, you then need to tell Play what you did by manually altering the table play_evolutions. An easier solution then would be to not use the evolutions mechanism provided by the Play Framework at all.

于 2015-10-04T19:58:05.940 回答
1

一个对我有用且不涉及启动播放实例的快速技巧:

export PGPASSWORD=<password>
for SQL_FILE in $(ls <path-to-evolution-files>); do
    psql -h localhost -U <username> -c "$(sed '1,/Ups/d' <path-to-evolution-files>/$SQL_FILE | sed -n '/Downs/q;p')";
done

删除之前的所有内容以及 includeUps和之后的所有内容Downs,并在 Postgres 实例上运行命令。

于 2017-11-10T11:31:29.540 回答