简体   繁体   English

是否在每个git分支中分开Rails的`schema.rb`?

[英]Keep Rails' `schema.rb` separated in each git branch?

Using Rails and Git, if I run a migration in one branch, the table is now in the database. 使用Rails和Git,如果我在一个分支中运行迁移,则该表现在位于数据库中。 Now if I check out a branch in which I don't want that migration, the table is still committed to the schema.rb , because it gets dumped from the database. 现在,如果我签出了一个我不希望进行迁移的分支,该表仍将提交给schema.rb ,因为它是从数据库中转储的。

Is there a way to prevent the schema from getting dumped from the database? 有没有办法防止从数据库中转储架构? For example is it possible to maybe have the schema be generated by running the migrations instead of by dumping the tables from the DB? 例如,是否可能通过运行迁移而不是通过从DB转储表来生成模式? It's really annoying to me, and to the other people in my company. 这对我和公司中的其他人真的很烦。

When you switch branches, either create a brand new DB and load an empty schema, or rollback migrations to the common anscestor, then migrate up again once you're in the new branch. 切换分支时,要么创建一个全新的DB并加载一个空模式,要么将迁移回滚到公共祖先,然后在进入新分支后再次向上迁移。

There are some tools and scripts that can help with this, but I haven't used any of them personally so I can't vouch for them. 有一些工具和脚本可以帮助解决这个问题,但是我个人没有使用过它们,因此我不能为其提供担保。 Here's a couple that I found after googling: 这是我在谷歌搜索后发现的一对:

The schema file changing is only the symptom of the true problem: rails is dynamically building the properties of your models from the schema of the database. 更改模式文件只是真正问题的征兆:Rails正在根据数据库的模式动态构建模型的属性。 Sweeping the schema.rb file under the rug will be insufficient because rails will still be making assumptions about your models based on a database that has the incorrect schema for the branch you're currently working in. 完全扫除一下schema.rb文件将是不够的,因为Rails仍将基于一个数据库,该数据库基于您当前正在使用的分支的模式不正确的数据库,对您的模型进行假设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM