botvector.net domain for sale $2k usd (negotiable). Em@il me t0: alex DOT creopolis at gmail DOT com

My Git activity

04 September 2008

Altering table

Adding and modifying table with Rails was never so easy and sexy !
You don't need to make tons of add_column for one type.. use change_table !!

and for def self.down use remove_column :table_name, [:column1, :column2 ...]

Add a column
 change_table(:suppliers) do |t|
t.column :name, :string, :limit => 60
end
Add 2 integer columns
 change_table(:suppliers) do |t|
t.integer :width, :height, :null => false, :default => 0
end
Add created_at/updated_at columns
 change_table(:suppliers) do |t|
t.timestamps
end
Add a foreign key column
 change_table(:suppliers) do |t|
t.references :company
end

Creates a company_id(integer) column

Add a polymorphic foreign key column
 change_table(:suppliers) do |t|
t.belongs_to :company, :polymorphic => true
end

Creates company_type(varchar) and company_id(integer) columns

Remove a column
 change_table(:suppliers) do |t|
t.remove :company
end
Remove several columns
 change_table(:suppliers) do |t|
t.remove :company_id
t.remove :width, :height
end
Remove an index
 change_table(:suppliers) do |t|
t.remove_index :company_id
end

HAVE FUN !!