How can I rename a database column in a Ruby on Rails migration?

rename_column :table, :old_column, :new_column You’ll probably want to create a separate migration to do this. (Rename FixColumnName as you will.): script/generate migration FixColumnName # creates db/migrate/xxxxxxxxxx_fix_column_name.rb Then edit the migration to do your will: # db/migrate/xxxxxxxxxx_fix_column_name.rb class FixColumnName < ActiveRecord::Migration def self.up rename_column :table_name, :old_column, :new_column end def self.down # rename back if you need … Read more

add column to mysql table if it does not exist

Here is a working solution (just tried out with MySQL 5.0 on Solaris): DELIMITER $$ DROP PROCEDURE IF EXISTS upgrade_database_1_0_to_2_0 $$ CREATE PROCEDURE upgrade_database_1_0_to_2_0() BEGIN — rename a table safely IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=’my_old_table_name’) ) THEN RENAME TABLE my_old_table_name TO my_new_table_name, END IF; — add a column safely … Read more