在GIT中处理Rails db / schema.rb文件的正确方法是什么? [英] What is the right approach to deal with Rails db/schema.rb file in GIT?

查看:120
本文介绍了在GIT中处理Rails db / schema.rb文件的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在向GIT发送消息时,是否应该包含 schema.rb ?或者我们应该忽略它?什么是正确的方法?

解决方案

那么标准 schema.rb Rails 2的文件在文件顶部的注释块的末尾有这个:

 #强烈建议检查这个文件进入你的版本控制系统。 

Rails 3 schema.rb 有踢着说同样的事情。
$ b

回复评论的更新
是的,错误可以发生,你可以得到相互冲突的变化和错误,这些错误会改变你的 schema.rb 但这就是为什么你需要在版本控制之下,版本控制允许你保持跟踪的一切,并在需要时进行备份。整个源代码树中只有一个指定数据库架构的东西,它是 schema.rb 。您的数据库架构绝对是一个关键的工件,任何重要的需要在修订控制中进行跟踪。

应该通过整理出冲突的迁移来整理出来,这样 schema.rb 将被固定为解决真正问题的副作用。 p>

是的, schema.rb 是一个生成的文件,但它只是在您的文本编辑器生成 pancakes.rb 模型文件或未编辑脚手架文件。



是的,您可以重建<$ c $通过构建一个新的数据库,然后运行所有的迁移,创建一个名为schema.rb 的文件。但是,您应该立即清理旧的迁移,以避免在每次 rake db:migrate >时检查数百个迁移文件,以便重建并运行所有迁移在高度活跃的项目中往往不是一种选择。


Should we include schema.rb while commiting to GIT? or should we ignore it? what is the right approach?

解决方案

Well the standard schema.rb file for Rails 2 has this at the end of the comment block at the top of the file:

# It's strongly recommended to check this file into your version control system.

The Rails 3 schema.rb that I have kicking around says the same thing. I think the comment says it all.


Update in response to comments: Yes, mistakes can be made and you can get conflicting changes and bugs mangling your schema.rb but that's why you want it under revision control, revision control allows you to keep track of everything and backup when needed. There is only one thing in your entire source tree that specifies your database schema and that is schema.rb. Your database schema absolutely is a critical artifact and anything that important needs to be tracked in revision control.

Any update/merge problems with schema.rb should be sorted out just by sorting out your conflicting migrations so schema.rb will get fixed as a side effect of fixing the real problem.

Yes, schema.rb is a generated file but it is only generated in the sense that your text editor generates your pancakes.rb model file or an unedited scaffold file is generated.

Yes, you could rebuild your schema.rb file by building a new database and then running all of your migrations. But, you should clear out your old migrations now and then to avoid having to check hundreds of migration files every time you rake db:migrate so "rebuild and run all the migrations" often isn't an option in a highly active project.

这篇关于在GIT中处理Rails db / schema.rb文件的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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