From 242ff77f1027d79c935744526ff079d03f25a332 Mon Sep 17 00:00:00 2001 From: kinseyost Date: Mon, 19 Sep 2016 03:06:29 +0000 Subject: [PATCH] Adds up and down for alterUsers migration --- db/migrate/20160918172700_alter_users.rb | 19 +++++++++++++++++++ db/schema.rb | 13 +------------ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20160918172700_alter_users.rb diff --git a/db/migrate/20160918172700_alter_users.rb b/db/migrate/20160918172700_alter_users.rb new file mode 100644 index 0000000..5e87616 --- /dev/null +++ b/db/migrate/20160918172700_alter_users.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 741c1b8..52ab025 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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