Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Created April 20, 2015 18:01
Show Gist options
  • Save oojikoo-gist/bd7d1e5e7ff117d4ef35 to your computer and use it in GitHub Desktop.
Save oojikoo-gist/bd7d1e5e7ff117d4ef35 to your computer and use it in GitHub Desktop.
rails: migration dictionary
# rails migration
########################
# add column to exsting table
########################
def up
add_column :users, :status, :string
User.find_each do |user|
user.status = 'active'
user.save!
end
end
def down
remove_column :users, :status
end
########################
# rename column
########################
def change
rename_column :table_name, :column_name_old, :column_name_new
end
########################
# rename column
########################
def change
change_table :table_name do |t|
t.rename :old_column1, :new_column1
t.rename :old_column2, :new_column2
...
end
end
########################
# rename table
########################
def change
rename_table :old_table_name, :new_table_name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment