如何使用Git分支和Rails迁移 [英] How to work with Git branches and Rails migrations

查看:186
本文介绍了如何使用Git分支和Rails迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个rails应用程序与很多git分支,其中许多包括数据库迁移。我们尽量小心,但偶尔在master中的一些代码要求在另一个分支中删除/重命名的列。

I am working on a rails app with quite a few git branches and many of them include db migrations. We try to be careful but occasionally some piece of code in master asks for a column that got removed/renamed in another branch.


  1. 什么是一个好的解决方案来耦合git分支与DB状态?

如果数据库的大小为几GB,我们不能重复。

We can't just duplicate a database if it's a few GBs in size.

合并会发生什么情况?

我们目前使用MySQL,mongodb和redis

We currently use MySQL, mongodb and redis






编辑:看起来我忘了提到一个非常重要的一点,我只对开发环境感兴趣,

推荐答案

在任何分支中添加新迁移时,请运行 rake db:migrate 并提交迁移 db / schema.rb

When you add a new migration in any branch, run rake db:migrate and commit both the migration and db/schema.rb

如果这样做,在开发中,您可以切换到另一个具有不同迁移集合的分支,只需运行 rake db:schema:load

If you do this, in development, you'll be able to switch to another branch that has a different set of migrations and simply run rake db:schema:load.

请注意,这将重新创建整个数据库,现有数据将丢失

你可能只想从一个分支运行生产,你非常小心,所以这些步骤不适用那里(只需运行 rake db:migrate 像往常一样)。但在开发中,从模式重建数据库应该没什么大不了的,这是 rake db:schema:load 会做的。

You'll probably only want to run production off of one branch which you're very careful with, so these steps don't apply there (just run rake db:migrate as usual there). But in development, it should be no big deal to recreate the database from the schema, which is what rake db:schema:load will do.

这篇关于如何使用Git分支和Rails迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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