]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20201004105659_create_doorkeeper_tables.rb
Merge remote-tracking branch 'upstream/pull/4717'
[rails.git] / db / migrate / 20201004105659_create_doorkeeper_tables.rb
1 # frozen_string_literal: true
2
3 class CreateDoorkeeperTables < ActiveRecord::Migration[6.0]
4   def change
5     create_table :oauth_applications do |t|
6       t.references :owner, :null => false, :type => :bigint, :polymorphic => true
7       t.string :name, :null => false
8       t.string :uid, :null => false
9       t.string :secret, :null => false
10       t.text :redirect_uri, :null => false
11       t.string :scopes, :null => false, :default => ""
12       t.boolean :confidential, :null => false, :default => true
13       t.timestamps :null => false
14     end
15
16     add_index :oauth_applications, :uid, :unique => true
17     add_foreign_key :oauth_applications, :users, :column => :owner_id, :validate => false
18
19     create_table :oauth_access_grants do |t|
20       t.references :resource_owner, :null => false, :type => :bigint
21       t.references :application, :null => false, :type => :bigint
22       t.string :token, :null => false
23       t.integer :expires_in, :null => false
24       t.text :redirect_uri, :null => false
25       t.datetime :created_at, :null => false
26       t.datetime :revoked_at
27       t.string :scopes, :null => false, :default => ""
28       t.column :code_challenge, :string, :null => true
29       t.column :code_challenge_method, :string, :null => true
30     end
31
32     add_index :oauth_access_grants, :token, :unique => true
33     add_foreign_key :oauth_access_grants, :users, :column => :resource_owner_id, :validate => false
34     add_foreign_key :oauth_access_grants, :oauth_applications, :column => :application_id, :validate => false
35
36     create_table :oauth_access_tokens do |t|
37       t.references :resource_owner, :index => true, :type => :bigint
38       t.references :application, :null => false, :type => :bigint
39       t.string :token, :null => false
40       t.string :refresh_token
41       t.integer :expires_in
42       t.datetime :revoked_at
43       t.datetime :created_at, :null => false
44       t.string :scopes
45       t.string :previous_refresh_token, :null => false, :default => ""
46     end
47
48     add_index :oauth_access_tokens, :token, :unique => true
49     add_index :oauth_access_tokens, :refresh_token, :unique => true
50     add_foreign_key :oauth_access_tokens, :users, :column => :resource_owner_id, :validate => false
51     add_foreign_key :oauth_access_tokens, :oauth_applications, :column => :application_id, :validate => false
52   end
53 end