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

吃可爱长大的小学妹 提交于 2020-01-01 01:15:49

问题


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.

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 .

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

thank you


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6520017/is-it-a-good-idea-to-put-db-schema-rb-to-gitignore-list

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