Forum: Ruby on Rails migration to be called inside others migrations

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Paolo N. (Guest)
on 2006-06-05 22:15
(Received via mailing list)
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

This topic is locked and can not be replied to.