woensdag 29 april 2009

Add Table Fields with Rails Migrations

With Ruby on Rails you van easily add columns to an existing database table using migrations. The update can than automatically be applied to the different environments (i.e. development, test, production).

The code for the migration is as follows:

class AddAdministrationsMyclientsidBlocked < ActiveRecord::Migration
def self.up
add_column :administrations, :myclient_id, :integer
add_column :administrations, :blocked, :boolean, :default => false

end

def self.down
remove_column :administrations, :myclient_id
remove_column :administrations, :blocked
end
end