mercoledì 8 febbraio 2012

[Ruby][Rake] Problem with migrations?

First of all, this happened to me trying to migrate db with a rake task on the production server. NOTE: please take a snapshot or a backup of your database data before starting with migrations.
Are you developing a Rails 3.0.x app? Are you using slim_scrooge gem?
Did your migration worked on development/test environment, but it looks having problem on production server?
Better: it looks like working but when you check your DB or schema.rb file you see nothing happened?

Before starting with the tricky solution please take care to try the following:
% This will do the job migration
% "bundle exec" will force to use gems of your bundle and
% perform it in the Rails Production Environment
bundle exec rake db:migrate RAILS_ENV=production
or
% This will deploy on server and
% then perform just last migrations
% Use this if you're using Capistrano to deploy on server
cap deploy:migrations
So, now, a question: are you sure having migration files in db/migrate directory? If you have it, please try with:
% Replace your migration version with the one you have to perform.
bundle exec rake db:migrate:up RAILS_ENV=production VERSION= YOUR_MIGRATE_VERSION
If it worked, let's speed it up calling more migrations at once:
% Replace step number with the one you have to perform.
bundle exec rake db:migrate:up RAILS_ENV=production STEP= HOW_MANY_MIGRATION_YOU_MISS
If you have the following after that command:
rake aborted!
No migration with version number YOUR_MIGRATE_VERSION
Ok, finally: my question at the beginning about slim_scrooge was a clue for the solution.
Take note:
  1. Comment slim_scrooge gem from your Gemfile
  2. Deploy your application with the deploy:migrations Capistrano task
  3. Restore slim_scrooge gem to your Gemfile
  4. Deploy again your application with deploy Capistrano task
Now you should have your migration task complete keeping slim_scrooge in your application.

The original solution has been found on StackOverflow.

N.B. This bug was for slim_scrooge version 1.0.12
As long as I see this should be fixed in the 1.0.13 version for Rails 3.1.

Nessun commento:

Posta un commento