在GIT中处理Rails db / schema.rb文件的正确方法是什么?

编程入门 行业动态 更新时间:2024-10-13 02:20:42
本文介绍了在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文件的正确方法是什么?

本文发布于:2023-10-18 04:27:36,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   文件   方法   Rails   GIT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!