You're right, dropping and recreating the database to solve a conflict in db/structure.sql
(or db/schema.rb
for that matter) is a little ridiculous. You should be able to simply run the new migrations and get an updated structure.sql
from the db:migrate
.
The db/stucture.sql
file is simply the database's structure as the database sees it (whereas db/schema.rb
is the database's structure in the limited view of it that ActiveRecord has). If there is a conflict in structure.sql
, that simply means:
- The merge involves new migrations which change the database structure.
- The branch you're merging in has run the migrations in a different order so the schema's don't quite match up even though they may be functionally equivalent.
(1) is solved by running the new migrations and possibly fixing any places where the migrations themselves are in conflict. A quick bin/rake db:migrate
should fix this and leave you with a new non-conflicted db/structure.sql
.
(2) is solved the same way. You could also do a a manual bin/rake db:structure:dump
to rebuild db/structure.sql
but you'd only do this if you're certain that you really do have this situation; but really, db:migrate
will take care of it so there's no reason not to just db:migrate
.
Conflicts in db/structure.sql
(or db/schema.rb
) don't indicate a problem with the db/structure.sql
itself, they indicate problems with the database that git can't directly see. The solution to the conflicts is to fix the database.