Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update migrations when upgrading from a Rails 1.2.3 app?

I'm updating a Rails 1.2.3 app to 3.2.1.

I'm trying to figure out how I can update the migration structure to be compatible with the latest version of Rails, so that, ideally, you can just run rake db:migrate when setting up the app. Currently, I have solved this by just doing rake db:migrate:up VERSION=[version_number] of whatever migration I need to run. If I just run rake db:migrate, it tries to rerun all of the migrations from the beginning and it stops (since those migrations have already been run in the db dump I have).

Migrations in the app look like this 001_add_some_model.rb, 002_add_some_other_model.rb instead of 20120209182512_add_some_model.rb.

Does anyone have any experience with this? How can I fix this?

like image 219
jfedick Avatar asked Feb 10 '12 14:02

jfedick


2 Answers

I think you should restart your migrations, drop all the migration you have and create a new migration with definitions of your current models. See this migration as a starting example.

like image 161
lucapette Avatar answered Sep 21 '22 20:09

lucapette


It is not recommended to run all migrations to set up a new database even in an up-to-date Rails 3 app. This is explained in db/schema.rb:

Note that this schema.rb definition is the authoritative source for your database schema. If you need to create the application database on another system, you should be using db:schema:load, not running all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations you'll amass, the slower it'll run and the greater likelihood for issues).

like image 44
Simon Perepelitsa Avatar answered Sep 24 '22 20:09

Simon Perepelitsa