How to handle Play Framework 2 database evolutions in production

前端 未结 2 1889
刺人心
刺人心 2020-12-08 01:36

It seems that whenever I change my models, Play Framework asks me to run a script that deletes my entire schema and recreates it. Obviously this won\'t work for production,

2条回答
  •  旧时难觅i
    2020-12-08 01:56

    Biesior basically summed it up quite well. However, as a beginner in Play, I find that a bit more clarification with a concrete example might be helpful.

    First, the following example is for Java.

    Suppose you added a new field

    public String dum_str;
    

    in your model Dum. Then, you will need a 2.sql under conf/evolutions/ like this:

    # --- !Ups
    ALTER TABLE dum ADD COLUMN dum_str VARCHAR(255);
    
    # --- !Downs
    ALTER TABLE dum DROP dum_str;
    

    I hope this would be helpful.

提交回复
热议问题