Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging db/migration files

Is there a good way to merge rails db migration files into 1 file per table besides splitting schema.rb manually?

Most of my migration file was created during development and does not represent real data changes. For historical reasons those files will be still accessible on source control system. I feel uncomfortable keeping those unnecessary files.

like image 694
guiding5 Avatar asked Nov 10 '11 21:11

guiding5


2 Answers

Well, i can imagine that you want to have a clean start. While being in project development mode for your first version release you don't want all the separate migration files. Although they can't hurt obviously.

Basically what you can do, is this.

FIRST BACKUP your schema and data.

The db/schema.rb contains (or should contain) the latest version of your schema. Otherwise run:

rake db:schema:dump

Now you can clean your migration folder.

Then run:

rake db:drop
rake db:schema:load

The last command runs the db/schema.rb and create a new schema. This should bring you to the last version of your database.

show db task

rake -T db

like image 94
Roger Avatar answered Oct 02 '22 02:10

Roger


You can use Squasher gem to merge the migrations all olds into one.

like image 45
Manish Shrivastava Avatar answered Oct 02 '22 01:10

Manish Shrivastava