Browse Source

Migrate to separate tokens table

Maarten van den Berg 8 years ago
parent
commit
ac1fb7bea3
2 changed files with 32 additions and 5 deletions
  1. 21 0
      db/migrate/20170210180426_remove_tokens_from_users.rb
  2. 11 5
      db/schema.rb

+ 21 - 0
db/migrate/20170210180426_remove_tokens_from_users.rb

@@ -0,0 +1,21 @@
1
+class RemoveTokensFromUsers < ActiveRecord::Migration[5.0]
2
+  def up
3
+    remove_column :users, :confirmation_token
4
+    remove_column :users, :password_reset_token
5
+
6
+    create_table :tokens do |t|
7
+      t.string    :token
8
+      t.datetime  :expires
9
+      t.string    :tokentype
10
+      t.integer   :user_id
11
+      t.index ["token"], name: "index_tokens_on_token", unique: true
12
+    end
13
+  end
14
+
15
+  def down
16
+    add_column :users, :confirmation_token, :string
17
+    add_column :users, :password_reset_token, :string
18
+
19
+    drop_table :tokens
20
+  end
21
+end

+ 11 - 5
db/schema.rb

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 20161231185937) do
13
+ActiveRecord::Schema.define(version: 20170210180426) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "public_name"
@@ -80,14 +80,20 @@ ActiveRecord::Schema.define(version: 20161231185937) do
80 80
     t.index ["user_id"], name: "index_sessions_on_user_id"
81 81
   end
82 82
 
83
+  create_table "tokens", force: :cascade do |t|
84
+    t.string   "token"
85
+    t.datetime "expires"
86
+    t.string   "tokentype"
87
+    t.integer  "user_id"
88
+    t.index ["token"], name: "index_tokens_on_token", unique: true
89
+  end
90
+
83 91
   create_table "users", force: :cascade do |t|
84 92
     t.string   "email"
85 93
     t.string   "password_digest"
86
-    t.string   "confirmation_token"
87
-    t.string   "password_reset_token"
88 94
     t.integer  "person_id"
89
-    t.datetime "created_at",           null: false
90
-    t.datetime "updated_at",           null: false
95
+    t.datetime "created_at",      null: false
96
+    t.datetime "updated_at",      null: false
91 97
     t.index ["email"], name: "index_users_on_email", unique: true
92 98
     t.index ["person_id"], name: "index_users_on_person_id", unique: true
93 99
   end