问题描述
我不想将 schema.rb 添加到 .gitignore 中,因为我希望能够从该文件加载新的数据库模式。但是,保持登录状态会导致各种各样的虚假冲突,这些冲突可以通过新鲜的 db:migrate:reset 轻松解决。
基本上我想要一种方式:
- 将schema.rb保存在部署时数据库的存储库中设置
- 将schema.rb保存在'.gitignore'中用于常规开发
一两个人负责更新 schema.rb 并知道它是正确的。
有没有办法可以有我的蛋糕,也可以吃吗? 解决方案
我不想将 schema.rb 添加到 .gitignore 中,因为我希望能够从该文件加载新的数据库模式。但是,保持登录状态会导致各种各样的虚假冲突,这些冲突可以通过新鲜的 db:migrate:reset 轻松解决。
基本上我想要一种方式:
一两个人负责更新 schema.rb 并知道它是正确的。
有没有办法可以有我的蛋糕,也可以吃吗? 解决方案
对我来说真正有效的是删除和.gitignore schema.rb ,然后在每个开发者 rake db:migrate 时重新生成。
通过简单地定期进行迁移汇总,您仍然可以实现自己想要的目标,而不需要从0迁移并冒着多年前破坏迁移的风险。您可以通过以下方式执行此操作:
现在您的initial_schema迁移是新系统的起点,您不必担心关于 schema.rb 中可能无法正确解析的冲突。这不是神奇的,但它的工作原理。
I don't want to add schema.rb to .gitignore, because I want to be able to load a new database schema from that file. However, keeping it checked in is causing all sorts of spurious conflicts that are easily resolved by a fresh db:migrate:reset.
Basically I want a way to:
There would be one or two people responsible for updating schema.rb and knowing that it was correct.
Is there a way I can have my cake and eat it, too?
What has worked really well for me is to delete and .gitignore schema.rb and then have it regenerated for each developer when they rake db:migrate.
You can still achieve what you wanted without migrating from 0 and risking broken migrations from years ago by simply doing a "roll-up" of the migrations periodically. You can do this by:
Now your initial_schema migration is your starting point for new systems and you don't have to worry about conflicts in schema.rb that may not be resolved correctly. It's not magical, but it works.
这篇关于在git中管理schema.rb的首选方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!