Is it a good idea to purge old Rails migration files?

前端 未结 10 1596
清歌不尽
清歌不尽 2021-01-01 11:16

I have been running a big Rails application for over 2 years and, day by day, my ActiveRecord migration folder has been growing up to over 150 files.

There are very

10条回答
  •  -上瘾入骨i
    2021-01-01 11:59

    Personally I like to keep things tidy in the migrations files. I think once you have pushed all your changes into prod you should really look at archiving the migrations. The only difficulty I have faced with this is that when Travis runs it runs a db:migrate, so these are the steps I have used:

    1. Move historic migrations from /db/migrate/ to /db/archive/release-x.y/

    2. Create a new migration file manually using the version number from the last run migration in the /db/archive/release-x.y directory and change the description to something like from_previous_version. Using the old version number means that it won't run on your prod machine and mess up.

    3. Copy the schema.rb contents from inside the ActiveRecord::Schema.define(version: 20141010044951) do section and paste into the change method of your from_previous_version changelog

    4. Check all that in and Robert should be your parent's brother.

    The only other consideration would be if your migrations create any data (my test scenarios contain all their own data so I don't have this issue)

提交回复
热议问题