Run Evolutions in Command Line

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.


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.