如何在生产中处理Play Framework 2数据库演变 [英] How to handle Play Framework 2 database evolutions in production

查看:130
本文介绍了如何在生产中处理Play Framework 2数据库演变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎每当我更改模型时,Play Framework都会要求我运行一个删除整个模式并重新创建它的脚本。显然这不适用于生产,那么在生产中处理这个问题的正确方法是什么?

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, so what is the proper way to handle this in production?

注意,我正在使用ebean和Postgres,并在heroku上托管。

Note, I'm using ebean and Postgres, and hosting on heroku.

推荐答案

不幸的是 Ebean 只能创建创建DDL (而不是 UPDATE DDL )(作为在他们的小组上回答),因此您需要切换到手动进化尽快。

Unfortunately Ebean can create only CREATE DDL (and not UPDATE DDL) (as answered on their group), therefore you need to switch to manual evolutions ASAP.

一些规则:


  1. 在实施任何更改之前始终备份您的实时数据库:)

  2. ebean插件重新创建整个DDL,如果它只有 1.sql 由它创建的进化

  3. 您需要从 1.sql 中删除​​两个第一条评论并开始编写自己的演变下一个数字 2.sql 3.sq l 等。在切换到手动演进之前,尝试放置尽可能多的模型/字段。最重要的部分将由插件自动完成。

  4. 手动演进应该包含 ALTERS 到现有的表/列而不是DROP / CREATE,他们应该同时拥有: Ups Downs 每次更改。

  5. 尝试为了在每次演变中尽可能多地进行更改,它会更容易管理,然后为每个小变化编写单独的演变。

  1. Always backup your live DB before implementing any changes :)
  2. ebean plugin recreates whole DDL if it has only 1.sql evolution created by it
  3. You need to remove two first comments from 1.sql and start to writing own evolutions with next numbers 2.sql, 3.sql etc. Try to place as many models/fields as possible before switching to manual evolutions. The biggest part will be done automatically by plugin.
  4. manual evolutions should contain ALTERS to existing tables/columns instead of DROP/CREATE, they should have both: Ups and Downs for each change.
  5. try to place as many changes in each evolution as possible, it's easier to manage then writing separate evolution for each small change.

事实上有时候使用DB gui修改数据库结构更容易,无论如何它主要适用于单个开发人员...当你需要与其他开发人员共享你的代码时,编写演进将是更好的选择。

De facto sometimes it's just easier to modify DB structure with DB gui, anyway it works mainly for the single developer... when you need to share your code with other developers writing evolutions will be better option.

如果过了一段时间你会添加下一个大部分的新模型,你可以再次启用临时自动DDL并使用本地git来复制新部件。然后恢复自己的革命并粘贴Ebean插件生成的新部件。

If after some time you'll add next 'big' portion of new models you can enable temporary auto DDL again and using local git just to copy new parts. Then revert to own revolution and paste new parts generated by Ebean plugin.

这篇关于如何在生产中处理Play Framework 2数据库演变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆