schema.rb messed up due to migrations in other branches

Vikko picture Vikko · May 8, 2013 · Viewed 7.5k times · Source

Currently I'm working with a huge rails application and multiple branches with each a new feature for this application. It happens a lot a feature will require migrations, which shouldn't be a problem until you merge it with master: schema.rb got updated with the information of your dev database!

To clarify:

1. Branch A has migration create_table_x
2. Branch B has migration create_table_y
3. Branch A adds another create_table_z and runs db:migrate
4. You want to merge Branch A with Master and you see table_x, table_y and table_z in the schema.rb of Branch A.

It's not an option to reset+seed the database before every migration in a branch or create a database per branch. Due to the huge size of 2 GB SQL data, it would not be workable.

My question:

Is it really required to keep schema.rb in the repository since it gets rebuilt every migration?

If so, is it possible to build schema off the migrations instead of database dump?

Answer

Stephen Nguyen picture Stephen Nguyen · Jun 18, 2013

you should keep the schema within your repo. running the migration will fix merge conflicts within your schema.rb file for you. my simple take on your questions

  1. Is it Required? not really, but good practice.

"It's strongly recommended to check this file into your version control system." -schema.rb

  1. It is possible? yes but you may want to ask yourself if you really save any time by doing so, either manually or building the schema off your migrations elsewhere and pushing it in.

you ge tthe added benefit of using

rake db:schema:load

and

rake db:schema:dump

http://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html