Hi list
I''m writing some migrations to move a legacy db on a rails app. I have
a bunch of tables which need some custom modifications and the columns
updated_at to be added etc...
Now since the rails related columns will be the same for many (but not
all) tables I was thinking... can I write a Migration that sounds like
that
class AddRailsFields < ActiveRecord::Migration
def self.up(tbname)
add_column tbname, "lock_version", :integer, :default => 0
rename_column tbname, "oldtimestamp", "updated_at"
end
def self.down(tbname)
remove_column tbname, "lock_version"
rename_column tbname, "updated_at", "oldtimestamp"
end
end
And call it inside other migrations as
AddRailsFields.up("tablename")
I''ve tried this but AddRailsFields (which is located in dedicated file
in db/migrations/) seems to be not defined in other migrations. Maybe
a ''require'' in the right place could fix the problem, but I
would
avoid to add the require to each migration or to put it in some place
too generic.
Thanks for any help
Paolo