How to tell db:migrate to continue on exception

Is there a way to tell db:migrate to continue if it encounters an
exception? Sometimes during developing, the migration files aren’t
always exactly the way I want them (surprisingly;-).

For example:

001_add_table1.rb:

class AddTable1 < ActiveRecord::Migration
def self.up
create_table “table1”, :force => true do |t|
t.column :string1, :string, :limit => 40, :null => false
end
end

def self.down
drop_table :table1
end
end

002_add_column.rb:

class AddColumn < ActiveRecord::Migration
def self.up
add_column :table1, :text1, :text, :null => false
end

def self.down
remove_column :table1, :text1
end
end

Somewhere along the line I may end up deleting table ‘table1’ from the
database inadvertently. So, if I run db:migrate, it’s quite likely to
choke when applying version 2 (002_add_column.rb) or attempting a
rollback to version 1.

But during development, I want it to keep going. Is there a way to do
that?

Thanks,
Stan

On 1/25/07, stan.baptista [email protected] wrote:

def self.up
002_add_column.rb:

Somewhere along the line I may end up deleting table ‘table1’ from the
database inadvertently. So, if I run db:migrate, it’s quite likely to
choke when applying version 2 (002_add_column.rb) or attempting a
rollback to version 1.

But during development, I want it to keep going. Is there a way to do
that?

Thanks,
Stan

Usually deleting a table would be done as a migration too.

But, if you want migrations, and well, any ruby code, to continue on
exceptions, look into the use of begin/rescue.


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

But, if you want migrations, and well, any ruby code, to continue on
exceptions, look into the use of begin/rescue.

Got it. Thanks