Rails 永久回滚迁移然后分支

发布于 2024-09-09 04:38:39 字数 521 浏览 0 评论 0原文

这是一个关于迁移版本的 Rails 问题

所以我已经存在一些迁移。即在我的 db/migrate/ 文件夹中,我有一些这样的文件:

  • 1_add_products.rb
  • 2_add_customers.rb
  • 3_add_addresses.rb
  • 4_add_tags.rb

并且我运行了“rake db:migrate”,所以当前版本是 4。我想返回永久到版本 2 并从那里开始分支。所以我做了“rake db:migrate VERSION=2”,这正确地恢复了更改以反映版本 2。但是,每当我现在运行“rake db:migrate”时,它都会运行所有 4 个迁移并将我带回到版本 4有

没有办法永久返回到一个修订版,然后从那里开始新的分支?我可以简单地删除迁移 3 & 吗? 4 在我回滚到版本 2 后?

我问的原因是因为在我回滚到版本 2 后,我需要添加新的迁移并运行“rake db:migrate”,并且我绝对不希望包含迁移 3 和迁移 4。

This is a rails question about migration versions

So i have a few migrations already existing. i.e. in my db/migrate/ folder i have some files like this:

  • 1_add_products.rb
  • 2_add_customers.rb
  • 3_add_addresses.rb
  • 4_add_tags.rb

and i've ran "rake db:migrate" so the current version is 4. I want to go back to version 2 permanently and start branching from there. So i did "rake db:migrate VERSION=2" and this reverted the changes correctly to reflect version 2. However, whenever i run "rake db:migrate" now, it runs all 4 of the migrations and puts me back at version 4.

Is there a way to permanently go back to one revision and then start branching newly from there? Can i just simply delete migration 3 & 4 after i roll back to version 2 ??

The reason I ask is because after i roll back to version 2, i need to add new migrations and run "rake db:migrate" and i definitely do not want migration 3 and migration 4 to be included.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2024-09-16 04:38:39

删除应该没问题。只要确保你在所有地方(开发、暂存、生产)都将其回滚,否则你会遇到一些奇怪的问题。

是的,一定要回滚然后删除,否则你的数据库会认为它处于实际不存在的状态。

Deleting should work just fine. Just make sure that you have it rolled back EVERYWHERE (development, staging, production) otherwise you'll run into some weird problems.

And yes, definitely rollback THEN delete, otherwise your database will think it's in a state that doesn't actually exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文