Last active
December 22, 2015 10:59
-
-
Save rubyrider/6462829 to your computer and use it in GitHub Desktop.
Example of migration
This file contains 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
class AlterUser < ActiveRecord::Migration | |
def up | |
rename_table :users, :customers | |
add_column :customers, :username, :string, limit: 25 | |
change_column :customers, :email, :string, limit: 100 | |
rename_column :customers, :password, :hashed_password | |
add_column :customers, :salt, :string, limit: 40 | |
add_index :customers, :username | |
end | |
def down | |
rename_table :customers, :users | |
remove_column :users, :username | |
change_column :users, :email, :string, default: "", null: false # you should specify field type after column name as the third argument in the change_column funtion | |
rename_column :users, :hashed_password, :password | |
remove_column :users, :salt | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment