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

查看:65
本文介绍了如何处理生产中的 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 只能创建 CREATE 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.sql3.sql 编写自己的演变> 等.在切换到手动演变之前,尝试放置尽可能多的模型/字段.最大的部分将由插件自动完成.
  4. 手动演变应该包含对现有表/列的 ALTERS 而不是 DROP/CREATE,它们应该同时具有:UpsDowns改变.
  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 修改 DB 结构更容易,无论如何它主要适用于单个开发人员......当您需要与其他开发人员共享代码时,编写演变将是更好的选择.

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天全站免登陆