#
# Copyright (C) 2020 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify
# the terms of the GNU Affero General Public License as publishe
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but
# WARRANTY; without even the implied warranty of MERCHANTABILITY
# A PARTICULAR PURPOSE. See the GNU Affero General Public Licens
# details.
#
# You should have received a copy of the GNU Affero General Publ
# with this program. If not, see <http://www.gnu.org/licenses/>.

class RemoveFkConstraintsForCrossShardRootAccountIds < ActiveRecord::Migration[5.2]
  tag :predeploy

  def change
    remove_foreign_key :attachment_associations, :accounts, column: :root_account_id, if_exists: true
    remove_foreign_key :attachments, :accounts, column: :root_account_id, if_exists: true
    remove_foreign_key :communication_channels, :accounts, column: :root_account_id, if_exists: true
    remove_foreign_key :folders, :accounts, column: :root_account_id, if_exists: true
  end
end

Remove FK constraints for possibly global RA ids
Remove FK constraints for possibly global RA ids

root_account_id on these tables can be cross-shard, so cannot have an FK
constraint.

Test plan:
- run migration and make sure you can set root_account_id to a global ID e.g.
  10000000000001 on an Attachment, AttachmentAssociation, Folder,
  CommunicationChannel (this one you need to use update_all() with SQL
  to avoid validations apparently)
- run `rake db:migrate:down VERSION=20200713114812` and make sure that you
  can not set root_Account to a global ID anymove

Change-Id: Ibcb8b54d1ba3af96bf4fad64a8ea3b7e4a613c2e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/242500
Reviewed-by: Weston Dransfield <e9203059795dc94e28a8831c65eb7869e818825e@instructure.com>
Reviewed-by: Cody Cutrer <c4fe2b1d90ef8f2548c8aeabfa633434316f0305@instructure.com>
QA-Review: Weston Dransfield <e9203059795dc94e28a8831c65eb7869e818825e@instructure.com>
QA-Review: Cody Cutrer <c4fe2b1d90ef8f2548c8aeabfa633434316f0305@instructure.com>
Product-Review: Cody Cutrer <c4fe2b1d90ef8f2548c8aeabfa633434316f0305@instructure.com>
Tested-by: Service Cloud Jenkins <9144042a601061f88f1e1d7a1753ea3e2972119d@instructure.com>
