Skip to content

Commit

Permalink
Merge pull request #1630 from doconnor-clintel/patch-1
Browse files Browse the repository at this point in the history
Special case unique index creation for refresh_token on sql server
  • Loading branch information
nbulaj authored Jan 21, 2023
2 parents ae5252b + 1f9feba commit 234efe9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/generators/doorkeeper/templates/migration.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
end

add_index :oauth_access_tokens, :token, unique: true
add_index :oauth_access_tokens, :refresh_token, unique: true

# See https://github.com/doorkeeper-gem/doorkeeper/issues/1592
if ActiveRecord::Base.connection.adapter_name == "SQLServer"
execute <<~SQL.squish
CREATE UNIQUE NONCLUSTERED INDEX index_oauth_access_tokens_on_refresh_token ON oauth_access_tokens(refresh_token)
WHERE refresh_token IS NOT NULL
SQL
else
add_index :oauth_access_tokens, :refresh_token, unique: true
end

add_foreign_key(
:oauth_access_tokens,
:oauth_applications,
Expand Down

0 comments on commit 234efe9

Please sign in to comment.