Commit a8c4735

mo <mo.khan@gmail.com>
2018-09-09 17:37:56
create token model.
1 parent 276c55b
app/models/token.rb
@@ -0,0 +1,4 @@
+class Token < ApplicationRecord
+  belongs_to :subject, polymorphic: true
+  belongs_to :audience, polymorphic: true
+end
db/migrate/20180909173139_create_tokens.rb
@@ -0,0 +1,14 @@
+class CreateTokens < ActiveRecord::Migration[5.2]
+  def change
+    create_table :tokens do |t|
+      t.string :uuid, index: { unique: true }
+      t.references :subject, polymorphic: true
+      t.references :audience, polymorphic: true
+      t.integer :token_type, default: 0
+      t.datetime :expires_at
+      t.datetime :revoked_at
+
+      t.timestamps
+    end
+  end
+end
db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2018_09_05_020708) do
+ActiveRecord::Schema.define(version: 2018_09_09_173139) do
 
   create_table "authorizations", force: :cascade do |t|
     t.integer "user_id"
@@ -44,6 +44,22 @@ ActiveRecord::Schema.define(version: 2018_09_05_020708) do
     t.index ["updated_at"], name: "index_sessions_on_updated_at"
   end
 
+  create_table "tokens", force: :cascade do |t|
+    t.string "uuid"
+    t.string "subject_type"
+    t.integer "subject_id"
+    t.string "audience_type"
+    t.integer "audience_id"
+    t.integer "token_type", default: 0
+    t.datetime "expires_at"
+    t.datetime "revoked_at"
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
+    t.index ["audience_type", "audience_id"], name: "index_tokens_on_audience_type_and_audience_id"
+    t.index ["subject_type", "subject_id"], name: "index_tokens_on_subject_type_and_subject_id"
+    t.index ["uuid"], name: "index_tokens_on_uuid", unique: true
+  end
+
   create_table "users", force: :cascade do |t|
     t.string "email"
     t.string "uuid", null: false
spec/models/token_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Token, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end
spec/factories.rb
@@ -1,4 +1,8 @@
 FactoryBot.define do
+  factory :token do
+    uuid { SecureRandom.uuid }
+  end
+
   factory :authorization do
     user
     client