Debugging migrations in rails 3 using ruby-debug?

2.1k views Asked by At

How do I debug my migrations using ruby-debug in rails 3?

running rake db:migrate does not seem to trigger any debugger command as in Rails 2. And rake db:migrate --debugger does not work either.

Thanks.

1

There are 1 answers

0
Augusto On BEST ANSWER

I was able to debug a migration by doing the following

Add ruby-debug to Gemfile

gem 'ruby-debug19'

In the migration add require 'ruby-debug' and execute debugger in the line you want to stop. For example

require 'ruby-debug'

class CreatePeople < ActiveRecord::Migration

  def self.up
    debugger
    create_table :people do |t|
      t.string :name
      t.String :email

      t.timestamps
    end
  end

  def self.down
    drop_table :people
  end
end

then run rake db:migrate or any other db command. For example

~/dev/ruby/migrate$ rake db:migrate
(in /Users/augusto/dev/ruby/migrate)
==  CreatePeople: migrating ===================================================
/Users/augusto/dev/ruby/migrate/db/migrate/20110212134536_create_people.rb:7
create_table :people do |t|
(rdb:1) list
[2, 11] in /Users/augusto/dev/ruby/migrate/db/migrate/20110212134536_create_people.rb
   2  
   3  class CreatePeople < ActiveRecord::Migration
   4  
   5    def self.up
   6      debugger
=> 7      create_table :people do |t|
   8        t.string :name
   9        t.String :email
   10  
   11        t.timestamps
(rdb:1)