Rebase Rails迁移在一个长期运行的项目中 [英] Rebase Rails migrations in a long running project

查看:174
本文介绍了Rebase Rails迁移在一个长期运行的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中我的意思是在字典中的rebasing,而不是git定义...

In which I mean "rebasing" in the dictionary, rather than git definition...

我有一个大,长期运行的Rails项目, ,它触摸难以管理所有这些。

I have a large, long running Rails project that has about 250 migrations, it's getting a touch unwieldy to manage all of these.

也就是说,我需要一个基础,从中清除和重建我的数据库运行测试时。因此,这些数据中包含的数据很重要。

That said, I do need a base from which to purge and rebuild my database when running tests. So the data contained in these is important.

有没有任何策略可以说,在设定点转储架构 - 归档所有旧迁移并重新启动与新的迁移。

Does any one have any strategies for say, dumping the schema at a set point - archiving off all the old migrations and starting afresh with new migrations.

显然,我可以使用rake模式:dump - 但真的我需要一种方式db:migrate将首先加载模式,然后开始运行其余的

Obviously I can use rake schema:dump - but really I need a way that db:migrate will load the schema first and then start running the rest of the migrations.

我想继续使用迁移,因为它们在开发中非常有用,但是我没有办法从2007年开始编辑迁移

I would like to keep using migrations as they're very useful in development, however, there's no way I'm going back and editing a migration from 2007 so it seems silly to keep it.

推荐答案

一般来说,你不需要清理旧的迁移。如果你正在运行db:从头开始迁移(没有现有的数据库),Rails使用db / schema.rb创建表,而不是运行每个迁移。否则,它只运行从当前模式升级到最新模式所需的迁移。

In general, you don't need to clean up old migrations. If you're running db:migrate from scratch (no existing db), Rails uses db/schema.rb to create the tables instead of running every migration. Otherwise, it only runs the migrations required to upgrade from the current schema to the latest.

如果您仍然希望将到某个给定点的迁移合并为一个,您可以尝试:

If you still want to combine migrations up to a given point into a single one, you could try to:


  • 使用从头开始迁移到目标模式rake db:migrate VERSION = xxx

  • 使用转储模式rake db:schema:dump

  • 删除从头到版本xxx的迁移,并使用db / schema.rb(将create create_table和add_index语句添加到新迁移的self.up方法中)的内容创建一个新的迁移。

请确保为您的聚合新迁移选择一个旧的迁移版本号;否则,Rails会尝试在生产服务器上应用该迁移(这会擦除现有数据,因为create_table语句使用:force⇒true)。

Make sure to choose one of the old migration version numbers for your aggregated new migration; otherwise, Rails would try to apply that migration on your production server (which would wipe your existing data, since the create_table statements use :force⇒true).

不会推荐这样做,因为Rails通常自己处理迁移。但如果您仍然想要,请务必仔细检查所有内容,并尝试在本地第一,然后您的生产服务器上的数据丢失风险。

Anyway, I wouldn't recommend to do this since Rails usually handles migrations well itself. But if you still want to, make sure to double check everything and try locally first before you risk data loss on your production server.

这篇关于Rebase Rails迁移在一个长期运行的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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