Run Evolutions in Command Line

不想你离开。 提交于 2019-12-05 02:07:36

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

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.

Brendan Maguire

A quick hack that works for me and doesn't involve bringing up a play instance:

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

Removes everything up to and include Ups and everything after and including Downs, and runs the commands on the Postgres instance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!