Last Updated: February 25, 2016
· pzgz

Rebase a rails project after long time running

Rebase might be necessary for a project after a longtime running. I just did once for one of my project, it's dangerous so make sure you aware what you are doing and make backup before you apply it to production.

Following are steps I did:

  • Create a new migration, whatever name you like, just meaning for the rebase, for example rails g migration Rebase
  • Migrate this migration into your location, and all environments which already have data and latest schema, this is important!!!
  • Run rake db:schema:dump, to make sure schema.rb get latest schema, actually we will have this on the above step, just for sure
  • Copy content in schema.rb (In the block of ActiveRecord::Schema.define(:version => xxxxxxxx) do), into the up method of the new created rebase migration
  • Now you can remove all migrations except the new created rebase migration. And then we are done

Once again, make sure you understand what you are doing!!!