diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-21 12:36:27 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-21 12:36:27 -0700 |
| commit | df3daf73da872a6872582fa925ffae29f6fdca6b (patch) | |
| tree | 402b52221f35d7176b996c31ebc5956bb3d39da8 | |
| parent | 6ada62adfd2b60e3af4f721ed8e09a5658920fa6 (diff) | |
fix users table schema.
| -rw-r--r-- | app/controllers/sessions_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/user.rb | 1 | ||||
| -rw-r--r-- | db/migrate/20150221192553_create_users.rb | 8 | ||||
| -rw-r--r-- | db/schema.rb | 8 |
4 files changed, 13 insertions, 6 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index baf8679..42987e4 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -13,5 +13,7 @@ class SessionsController < ApplicationController end def destroy + reset_session + redirect_to new_session_path end end diff --git a/app/models/user.rb b/app/models/user.rb index 40f0705..cac42c8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ class User < ActiveRecord::Base has_secure_password + validates_presence_of :username end diff --git a/db/migrate/20150221192553_create_users.rb b/db/migrate/20150221192553_create_users.rb index 72a9f38..f1a7146 100644 --- a/db/migrate/20150221192553_create_users.rb +++ b/db/migrate/20150221192553_create_users.rb @@ -1,10 +1,12 @@ class CreateUsers < ActiveRecord::Migration def change - create_table :users do |t| - t.string :username - t.string :password_digest + create_table :users, id: :uuid, default: 'uuid_generate_v4()' do |t| + t.string :username, null: false + t.string :password_digest, null: false t.timestamps null: false end + + add_index :users, :username, unique: true end end diff --git a/db/schema.rb b/db/schema.rb index d7219a5..45aa6ea 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,11 +47,13 @@ ActiveRecord::Schema.define(version: 20150221192553) do t.datetime "updated_at", null: false end - create_table "users", force: :cascade do |t| - t.string "username" - t.string "password_digest" + create_table "users", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t| + t.string "username", null: false + t.string "password_digest", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end + add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree + end |
