问题
We have around 100 database migration files. Many of them make schema changes which are irreversible. There are also later migrations which change or remove tables which were created in earlier migrations.
We are creating new databases straight from the schema.rb file, so we were wondering if there is any reason to keep the full set of migrations?
We would create a new migration which is based on our existing schema.rb.
回答1:
Yes, what you're proposing is considered a best practice.
I've done this with my old apps several times. You'll want to back your migrations up somewhere until you're satisfied all is well, of course, this is an important part of application maintenance - if you have a lot of old migrations, it can take forever to do a db:reset
or to get a new development environment running.
回答2:
I use rake db:setup
and rake db:reset
exclusively (never rake db:migrate
) to install a new database, on a production server or on a new development machine. Those commands already use the schema.rb
or structure.sql
to recreate the database.
That said, it is really easy to make a copy of schema.rb
, use that as a new starting-point and delete all the old migrations.
I prefer to keep my migrations for historic purposes, but that is a matter of taste.
来源:https://stackoverflow.com/questions/9321671/we-have-lots-of-database-migration-files-should-we-keep-them