20161101131409_create_doorkeeper_tables.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. class CreateDoorkeeperTables < ActiveRecord::Migration
  2. def change
  3. create_table :oauth_applications do |t|
  4. t.string :name, null: false
  5. t.string :uid, null: false
  6. t.string :secret, null: false
  7. t.text :redirect_uri, null: false
  8. t.string :scopes, null: false, default: ''
  9. t.timestamps null: false
  10. end
  11. add_index :oauth_applications, :uid, unique: true
  12. create_table :oauth_access_grants do |t|
  13. t.integer :resource_owner_id, null: false
  14. t.references :application, null: false
  15. t.string :token, null: false
  16. t.integer :expires_in, null: false
  17. t.text :redirect_uri, null: false
  18. t.datetime :created_at, null: false
  19. t.datetime :revoked_at
  20. t.string :scopes
  21. end
  22. add_index :oauth_access_grants, :token, unique: true
  23. add_foreign_key(
  24. :oauth_access_grants,
  25. :oauth_applications,
  26. column: :application_id
  27. )
  28. create_table :oauth_access_tokens do |t|
  29. t.integer :resource_owner_id
  30. t.references :application
  31. # If you use a custom token generator you may need to change this column
  32. # from string to text, so that it accepts tokens larger than 255
  33. # characters. More info on custom token generators in:
  34. # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
  35. #
  36. # t.text :token, null: false
  37. t.string :token, null: false
  38. t.string :refresh_token
  39. t.integer :expires_in
  40. t.datetime :revoked_at
  41. t.datetime :created_at, null: false
  42. t.string :scopes
  43. # If there is a previous_refresh_token column,
  44. # refresh tokens will be revoked after a related access token is used.
  45. # If there is no previous_refresh_token column,
  46. # previous tokens are revoked as soon as a new access token is created.
  47. # Comment out this line if you'd rather have refresh tokens
  48. # instantly revoked.
  49. t.string :previous_refresh_token, null: false, default: ''
  50. end
  51. add_index :oauth_access_tokens, :token, unique: true
  52. add_index :oauth_access_tokens, :resource_owner_id
  53. add_index :oauth_access_tokens, :refresh_token, unique: true
  54. add_foreign_key(
  55. :oauth_access_tokens,
  56. :oauth_applications,
  57. column: :application_id
  58. )
  59. end
  60. end