change resource link lookup_uuid uniqueness constraint

We're changing the uniquess constraint of lookup_uuid in favor a multiple
columns uniqueness constraint scoped to the context (context_id and
context_type).

refs INTEROP-6502
flag=none

test-plan
* specs should pass?

Change-Id: If2408b6677dd04439d8ef544ec6c864a212d90c1
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/258632
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Wagner Goncalves <wagner.goncalves@instructure.com>
Product-Review: Wagner Goncalves <wagner.goncalves@instructure.com>
Reviewed-by: Xander Moffatt <xmoffatt@instructure.com>
Reviewed-by: Ethan Vizitei <evizitei@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Wagner Gonçalves 2021-02-11 10:53:02 -03:00 committed by Wagner Goncalves
parent 7e23207b75
commit b241135806
3 changed files with 34 additions and 3 deletions

View File

@ -25,7 +25,7 @@ class Lti::ResourceLink < ApplicationRecord
validates :context_external_tool_id, :context_id, :context_type, :lookup_uuid,
:resource_link_uuid, presence: true
validates :lookup_uuid, uniqueness: true
validates :lookup_uuid, uniqueness: { scope: [:context_id, :context_type] }
belongs_to :context_external_tool
belongs_to :context, polymorphic: [:account, :assignment, :course]

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
# Copyright (C) 2021 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
class ChangeLookupUuidIndexAtLtiResourceLinks < ActiveRecord::Migration[5.2]
tag :predeploy
disable_ddl_transaction!
def change
add_index :lti_resource_links, [:lookup_uuid, :context_id, :context_type],
algorithm: :concurrently, if_not_exists: true, unique: true,
name: "index_lti_resource_links_unique_lookup_uuid_on_context"
remove_index :lti_resource_links, column: :lookup_uuid, if_exists: true
end
end

View File

@ -56,8 +56,8 @@ RSpec.describe Lti::ResourceLink, type: :model do
expect(resource_link.original_context_external_tool).to eq tool
end
it '`lookup_uuid` should be unique' do
expect(resource_link).to validate_uniqueness_of(:lookup_uuid).ignoring_case_sensitivity
it '`lookup_uuid` should be unique scoped to `context`' do
expect(resource_link).to validate_uniqueness_of(:lookup_uuid).scoped_to(:context_id, :context_type).ignoring_case_sensitivity
end
end