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

做~自己de王妃 提交于 2019-12-03 04:41:51

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

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

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

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.

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

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

  1. rake db:migrate:down VERSION=xxx migrations which were create some time ago, but not merged to other branches
  2. git checkout branch
  3. rake db:migrate migrate all newly created branches

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:seed to load data. But it wasn't critical.

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:dump and just add it as merge resolution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!