Skip to content

Instantly share code, notes, and snippets.

@rubyrider
Last active December 22, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubyrider/6462829 to your computer and use it in GitHub Desktop.
Save rubyrider/6462829 to your computer and use it in GitHub Desktop.
Example of migration
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