Skip to content

Commit

Permalink
Adds up and down for alterUsers migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kinseyost committed Sep 19, 2016
1 parent 1b100f2 commit 242ff77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 19 additions & 0 deletions db/migrate/20160918172700_alter_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class AlterUsers < ActiveRecord::Migration[5.0]

def up
rename_table("users", "admin_users")
add_column("admin_users", "username", :string, :limit => 25, :after => "email")
change_column("admin_users", "email", :string, :limit => 100)
rename_column("admin_users", "password", "hashed_password")
puts("Always add an index for foreign keys and columns that are used frequently!")
add_index("admin_users", "username")
end

def down
rename_column("admin_users", "hashed_password", "password")
change_column("admin_users", "email", :string, :default => '', :null => false)
remove_column("admin_users", "username")
rename_table("admin_users", "users")
end
# TODO: add up and down methods
end
13 changes: 1 addition & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160918172700) do

create_table "admin_users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
t.string "first_name", limit: 25
t.string "last_name", limit: 50
t.string "email", limit: 100, default: "", null: false
t.string "username", limit: 25
t.string "hashed_password", limit: 40
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["username"], name: "index_admin_users_on_username", using: :btree
end
ActiveRecord::Schema.define(version: 0) do

end

0 comments on commit 242ff77

Please sign in to comment.