Migration to be called inside others migrations


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

class AddRailsFields < ActiveRecord::Migration

def self.up(tbname)
add_column tbname, “lock_version”, :integer, :default => 0
rename_column tbname, “oldtimestamp”, “updated_at”

def self.down(tbname)
remove_column tbname, “lock_version”
rename_column tbname, “updated_at”, “oldtimestamp”


And call it inside other migrations as


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