Created
April 20, 2015 18:01
-
-
Save oojikoo-gist/bd7d1e5e7ff117d4ef35 to your computer and use it in GitHub Desktop.
rails: migration dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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