Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred way to manage schema.rb in git?

I don't want to add schema.rb to .gitignore, because I want to be able to load a new database schema from that file. However, keeping it checked in is causing all sorts of spurious conflicts that are easily resolved by a fresh db:migrate:reset.

Basically I want a way to:

  1. Keep schema.rb in the repository for deploy-time database setup
  2. Keep schema.rb in '.gitignore' for general development

There would be one or two people responsible for updating schema.rb and knowing that it was correct.

Is there a way I can have my cake and eat it, too?

like image 611
Otto Avatar asked Apr 10 '09 14:04

Otto


2 Answers

I'm afraid the magic solution you're looking for does not exist. This file is normally managed in version control, then for any conflicts on the version line just choose the later of the two dates. As long as you're also running all of the associated migrations nothing should get out of sync this way. If two developers have caused modifications to a similar area of schema.rb and you get conflicts in addition to the version then you are faced with a normal merge conflict resolution, but in my opinion these are normally easy to understand and resolve. I hope this helps some!

like image 192
Adam Alexander Avatar answered Sep 30 '22 11:09

Adam Alexander


One other thing you can do is use:

git update-index --assume-unchanged /path/schema.rb 

This will keep the file in the repository but won't track changes. you can switch the tracking anytime by using:

git update-index --no-assume-unchanged /path/schema.rb 
like image 35
Headshota Avatar answered Sep 30 '22 11:09

Headshota