Commit dd415d1

mo <mo.khan@gmail.com>
2018-09-05 02:12:44
generate an authorization code on save.
1 parent 7d98779
app/models/authorization.rb
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 class Authorization < ApplicationRecord
+  has_secure_token :code
   belongs_to :user
   belongs_to :client
 end
db/migrate/20180905020708_create_authorizations.rb
@@ -5,6 +5,7 @@ class CreateAuthorizations < ActiveRecord::Migration[5.2]
     create_table :authorizations do |t|
       t.references :user, foreign_key: true
       t.references :client, foreign_key: true
+      t.string :code, null: false, index: true
 
       t.timestamps
     end
db/schema.rb
@@ -15,9 +15,11 @@ ActiveRecord::Schema.define(version: 2018_09_05_020708) do
   create_table "authorizations", force: :cascade do |t|
     t.integer "user_id"
     t.integer "client_id"
+    t.string "code", null: false
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
     t.index ["client_id"], name: "index_authorizations_on_client_id"
+    t.index ["code"], name: "index_authorizations_on_code"
     t.index ["user_id"], name: "index_authorizations_on_user_id"
   end