-1

This is more of a best practice question. I've been using rails generate migration to add/remove/change columns from my table. Now my migration folder is filled with these migration files that I think makes things really messy. What would be your advice on keeping my migration folder groomed? (Are there better and more efficient ways to make changes to tables?) Can I delete migration files after they have been migrated to the db?

Thanks for your help!

pppp
  • 557
  • 3
  • 8
  • 21

3 Answers3

0

You can actually remove them all once you've performed the migrations and use rake db:schema:load for new deployments or to skip over problem migrations. More detail and some warnings can be found here.

Community
  • 1
  • 1
t56k
  • 6,769
  • 9
  • 52
  • 115
-1

Yes, You can do one thing, finalize all the migration file which you used for modifying tables later after creating tables. And create one single migration having all the modification within this file and remove all finalized files..

I hope it will clean your migration mess ups.

Example suppose you have three model post, school and club.And need to add colomns to these all. You can generate migration like..

rails g migration addTestingToPost

and open migration file and edit as:

class AddTestingToPost < ActiveRecord::Migration

def change

 add_column :posts, :user_id, :integer

 add_column :clubs, :coach_id, :integer

 add_column :school, :school_name, :string

end

end

Rojar
  • 1
  • 3
-1

What I do is export the schema of my database and keep it in the database migrations folder so I have an actual 'snapshot' of my DB in this moment and then move the older migrations to other directory, something like 'Migrations from 18072014 to 22092014' just in case something went wrong.

That way you will have your 'db/migrations' folder (the one with you usually work with) clean.

epergo
  • 565
  • 5
  • 17