Commit 004e0410 authored by manojmj's avatar manojmj

Use cascading delete for openid_request upon deleting an access_grant

This change adds `on_delete: :cascade`for the
foreign_key in `oauth_openid_requests` table.
parent 2c72034b
---
title: Use cascading deletes for deleting oauth_openid_requests upon deleting an oauth_access_grant
merge_request: 19617
author:
type: fixed
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class UpdateOauthOpenIdRequestsForeignKeys < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
remove_foreign_key_if_exists(:oauth_openid_requests, column: :access_grant_id)
add_foreign_key(:oauth_openid_requests, :oauth_access_grants, column: :access_grant_id, on_delete: :cascade)
end
def down
remove_foreign_key_if_exists(:oauth_openid_requests, column: :access_grant_id)
add_foreign_key(:oauth_openid_requests, :oauth_access_grants, column: :access_grant_id, on_delete: false, name: 'fk_oauth_openid_requests_oauth_access_grants_access_grant_id')
end
end
......@@ -4532,7 +4532,7 @@ ActiveRecord::Schema.define(version: 2019_11_25_140458) do
add_foreign_key "notes", "projects", name: "fk_99e097b079", on_delete: :cascade
add_foreign_key "notes", "reviews", name: "fk_2e82291620", on_delete: :nullify
add_foreign_key "notification_settings", "users", name: "fk_0c95e91db7", on_delete: :cascade
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_oauth_openid_requests_oauth_access_grants_access_grant_id"
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_77114b3b09", on_delete: :cascade
add_foreign_key "operations_feature_flag_scopes", "operations_feature_flags", column: "feature_flag_id", on_delete: :cascade
add_foreign_key "operations_feature_flags", "projects", on_delete: :cascade
add_foreign_key "operations_feature_flags_clients", "projects", on_delete: :cascade
......
# frozen_string_literal: true
FactoryBot.define do
factory :oauth_openid_request, class: 'Doorkeeper::OpenidConnect::Request' do
access_grant factory: :oauth_access_grant
sequence(:nonce) { |n| n.to_s }
end
end
# frozen_string_literal: true
require 'spec_helper'
describe OauthAccessGrant do
let(:user) { create(:user) }
let(:application) { create(:oauth_application, owner: user) }
describe '#delete' do
it 'cascades to oauth_openid_requests' do
access_grant = create(:oauth_access_grant, application: application)
create(:oauth_openid_request, access_grant: access_grant)
expect { access_grant.delete }.to change(Doorkeeper::OpenidConnect::Request, :count).by(-1)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment