5

The general consensus is that when migrating you should check schema.rb into version control.

What is the right approach to deal with Rails db/schema.rb file in GIT?

My question is this- if my senior dev creates a migration & checks schema.rb, I pull the repo down and migrate on my end and it shows schema.rb has been changed- do I also commit my version of schema.rb and check that into version control as well?

Community
  • 1
  • 1
Crash
  • 321
  • 1
  • 4
  • 15
  • http://stackoverflow.com/questions/6450263/what-is-the-right-approach-to-deal-with-rails-db-schema-rb-file-in-git – usha Apr 11 '14 at 16:39
  • 1
    We usually leave that commit to be made by whoever is deploying the migration - At the time of deployment, the migration has to be anyway run, and that is the most correct version for `schema.rb`. A check-in before can lead to possible conflicts between devs, and thus incorrect information in the repo. – Anshul Goyal Apr 11 '14 at 16:39
  • I prefer to add the file to .gitignore – house9 Apr 11 '14 at 18:26

2 Answers2

4

In theory, your schema.rb should be identical to the one that Senior Dev has committed, after you do the migration. If it isn't, then one of two things have happened:

  • Senior Dev actually forgot to commit schema.rb
  • The migration made a change that is not recorded by schema.rb in a consistent way (there are many creative uses of migrations that might lead to this, let alone bugs).

You should double check that Senior Dev has, in fact, committed schema.rb after they ran the migration. If they have, you should throw away the changes on your version of schema.rb in favour of theirs. If they have NOT, then you should commit your version of schema.rb, effectively correcting their mistake.

Sigi
  • 1,784
  • 13
  • 19
1

Yes, you should check-in your version of schema.rb. This would make sure that the entire team is working on the same version. Merging should be done whenever there are new changes to the schema. Your contributions to a project which alter the database are still contributions to the product, and as such are required to be checked-in.

The specific process of merging may differ per team. Some teams have a QA team which handles these things, others have a deployment team which handles this stuff. However, the case, communication is key. Try to keep your senior developer in the loop with your schema changes.

Igbanam
  • 5,904
  • 5
  • 44
  • 68