Play! framework - database issue with Evolutions

我怕爱的太早我们不能终老 提交于 2019-12-02 18:30:37

First you need to disable automatic generation of Evolution files by deleting the first 2 commented lines of the conf/evolutions/default/1.sql:

# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups
...

Then, you need to create a second file, called conf/evolutions/default/2.sql containing your update on the database schema with an Ups and a Downs section:

# --- !Ups
ALTER TABLE USER ADD COLUMN last_ip varchar(30) DEFAULT NULL;

# --- !Downs

ALTER TABLE USER DELETE COLUMN last_ip;

What you are probably doing is applying destructive evolutions. If you look in 1.sql (or whatever your evolutions file is), under DOWNS you have statemtnts like "DROP DATABASE X". Whenever Play detects changes in the evolution file, it runs all the down evolutions, then reapplies the up evolutions, resulting in all your data being lost.

Here is more info: http://www.playframework.org/documentation/2.0.2/Evolutions

I suggest you take a look at Liquibase. Liquibase handles database changes, is super flexible and is database independent. I use it in my applications to make sure when I apply a database change things don't get deleted or whatever.

You could disable Evolutions by setting evolutionplugin=disabled in application.conf

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