git 将 db/schema.rb 放入 .gitignore 列表是个好主意吗??

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6520017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:37:46  来源:igfitidea点击:

Is it a good idea to put db/schema.rb to .gitignore list ??

ruby-on-railsgitmigrationgitignore

提问by equivalent8

so what I'm suggesting in my job, is to put db/schema.rb into .gitignore file, so we don't have (time to time) merging problems.

所以我在我的工作中建议的是将 db/schema.rb 放入 .gitignore 文件中,这样我们就不会(不时)出现合并问题。

There are some concerns that if something terrible happen (meteor fall from the sky right on the DB server and simultaneously all the db/migrete files are corrupt) we could loose the schema, and we will have to use rake db:purge (to reuse the schema.rb). I agree that this is possible and it's a good argument, but it shouldn't be problem because db/schema.rb is generated each time we do rake db:migrate. So even if we won't push schema.rb on server, we are pushing migrations add running db:migrate each time we are deploying with DB changes and with that db:migrate rails will automatically generate schema.rb on server side, and that schema.rb sits on the server unchanged until we do another db:migrate .

有人担心如果发生可怕的事情(流星从天而降在 DB 服务器上,同时所有 db/migrete 文件都损坏了)我们可能会丢失架构,我们将不得不使用 rake db:purge(重用模式.rb)。我同意这是可能的,这是一个很好的论点,但它不应该是问题,因为每次我们执行 rake db:migrate 时都会生成 db/schema.rb。因此,即使我们不会在服务器上推送 schema.rb,我们也会在每次部署数据库更改时推送迁移添加运行 db:migrate 并且使用该 db:migrate rails 将在服务器端自动生成 schema.rb,并且schema.rb 保持不变,直到我们执行另一个 db:migrate 。

so whats your opinion, should we or should we not put the db/schema.rb into git ignore ?

那么你的意见是,我们应该还是不应该将 db/schema.rb 放入 git ignore ?

thank you

谢谢你

回答by Martijn

I would always suggest to keep schema.rb in version contol, since tasks like rake db:schema:load depend on it being there.

我总是建议将 schema.rb 保留在版本控制中,因为像 rake db:schema:load 这样的任务依赖于它的存在。

About the conflicts, are you talking about the schema version conflicts? These are easily mitigated using the merge algorithm showed here: http://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html

关于冲突,您是在谈论架构版本冲突吗?使用此处显示的合并算法可以轻松缓解这些问题:http: //tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html

Other conflicts, like column definition switching locations can easily be avoided by being careful what you commit to the repository.

其他冲突,如列定义切换位置,可以通过小心提交到存储库的内容轻松避免。

回答by VonC

You should put in a VCS whatever you need to reproduce an operational environment.
If, for rebuilding your application, you need to have the right schema.rb(at the right version), then yes, it can be versionned.

您应该将重现操作环境所需的任何内容放入 VCS。
如果为了重建您的应用程序,您需要拥有正确的权限schema.rb(在正确的版本上),那么是的,可以对其进行版本控制。

But if you can get it back through another process, then it is better backed up through some other referential than a VCS.

但是,如果您可以通过另一个过程将其取回,那么通过其他一些引用而不是 VCS 来备份它会更好。

回答by MBO

When you switch between feature branches which develop different set of model attributes, then without schema.rb you sometimes would need to:

当您在开发不同模型属性集的功能分支之间切换时,如果没有 schema.rb,您有时需要:

  1. rake db:migrate:down VERSION=xxxmigrations which were create some time ago, but not merged to other branches
  2. git checkout branch
  3. rake db:migratemigrate all newly created branches
  1. rake db:migrate:down VERSION=xxx前一段时间创建的迁移,但没有合并到其他分支
  2. git checkout branch
  3. rake db:migrate迁移所有新创建的分支

I run into some problems with this in previous projects where schema.rb was in .gitignore. Every time I see something was wrong, I had to drop database and recreate from migrations, while with schema.rb I could just load schema in fraction of second and then rake db:seedto load data. But it wasn't critical.

我在之前的项目中遇到了一些问题,其中 schema.rb 在 .gitignore 中。每次我发现有问题时,我都必须删除数据库并从迁移中重新创建,而使用 schema.rb 我可以在几分之一秒内加载架构,然后rake db:seed加载数据。但这并不重要。

I'm also curious what problems you have with merging schema.rb? Most of the time you can override this file without worrying about changes (I assume you haven't modified your database structure by hand) with rake db:dumpand just add it as merge resolution.

我也很好奇你在合并 schema.rb 时遇到了什么问题?大多数情况下,您可以覆盖此文件而无需担心更改(我假设您没有手动修改数据库结构),rake db:dump只需将其添加为合并解析。