rubyonrailsin

A Ruby and Rails talk

Saturday, March 13, 2010


[Rails] Coding a migration to change a column's attribute

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi All,

I want a migration to change the Amount column of the Expense table to
the precision/scale to 10/2.

It's easy to say in one sentence. It's a little harder to do.

1 Ran: ruby script/generate migration ChangeExpenseTbl_AmountCol
2.Got db/migrate/20100313180401_change_expense_tbl_amount_col.rb
3.Modified the migration as follows:

class ChangeExpenseTblAmountCol < ActiveRecord::Migration
def self.up
class Expense
change_column :amount, decimal :precision=>10, scale=>2
end
end

def self.down
end
end

This looks like it could be DRYed to this:

class Expense < ActiveRecord::Migration
def self.up
change_column :amount, decimal :precision=>10, scale=>2
end

def self.down
end
end

Do either of these look correct?

Thanks in Advance,
Richard

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive