diff --git a/db/migrate/20201215175216_add_replica_identity_for_group_categories.rb b/db/migrate/20201215175216_add_replica_identity_for_group_categories.rb new file mode 100644 index 00000000000..acc5ff12685 --- /dev/null +++ b/db/migrate/20201215175216_add_replica_identity_for_group_categories.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# +# Copyright (C) 2020 - 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 . + +class AddReplicaIdentityForGroupCategories < ActiveRecord::Migration[5.2] + tag :postdeploy + disable_ddl_transaction! + + def up + add_replica_identity 'GroupCategory', :root_account_id, 0 + remove_index :group_categories, name: 'index_group_categories_on_root_account_id', if_exists: true + end + + def down + remove_replica_identity 'GroupCategory' + # no need to re-add index_group_categories_on_root_account_id + # since index_group_categories_on_root_account_id_and_sis_source_id exists + end +end diff --git a/spec/lib/data_fixup/populate_root_account_id_for_group_categories_spec.rb b/spec/lib/data_fixup/populate_root_account_id_for_group_categories_spec.rb deleted file mode 100644 index 702a12c077b..00000000000 --- a/spec/lib/data_fixup/populate_root_account_id_for_group_categories_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -# -# Copyright (C) 2011 - 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 . -# - -require 'spec_helper' -require File.expand_path(File.dirname(__FILE__) + '/../../../lib/data_fixup/populate_root_account_id_for_group_categories') - -describe DataFixup::PopulateRootAccountIdForGroupCategories do - before :once do - account_model - @other_acct = Account.create! - - course = Course.create!(account: @account) - other_course = Course.create!(account: @other_acct) - - @category_for_acct = GroupCategory.create!(account: @account, name: 'Account') - @category_for_course = GroupCategory.create!(course: course, name: 'Course') - # we have invalid contexts because they have been scrubbed, but they should - # allow the rest to enjoy a root_account_id even though they don't get one. - @cat_for_invalid_course = GroupCategory.create!(context_id: -42, context_type: 'Course', name: 'Other Course') - - @other_cat_for_acct = GroupCategory.create!(account: @other_acct, name: 'Other Account') - @other_cat_for_course = GroupCategory.create!(course: other_course, name: 'Other Course') - - @category_for_acct.update!(root_account_id: nil) - @category_for_course.update!(root_account_id: nil) - @other_cat_for_acct.update!(root_account_id: nil) - @other_cat_for_course.update(root_account_id: nil) - - # Some group categories that *do* have root_account_ids - @acct_cat_with_id = GroupCategory.create!(account: @account, name: 'Has ID', root_account_id: @account.id) - @course_cat_with_id = GroupCategory.create!(course: course, name: 'Has ID', root_account_id: @account.id) - end - - it 'should set root account ids on group categories' do - DataFixup::PopulateRootAccountIdForGroupCategories.run - expect(@category_for_acct.root_account_id).to eq(@account.id) - expect(@category_for_course.root_account_id).to eq(@account.id) - - expect(@other_cat_for_acct.root_account_id).to eq(@other_acct.id) - expect(@other_cat_for_course.root_account_id).to eq(@other_acct.id) - - expect(@acct_cat_with_id.root_account_id).to eq(@account.id) - expect(@course_cat_with_id.root_account_id).to eq(@account.id) - end -end diff --git a/spec/lib/data_fixup/populate_root_account_id_on_models_spec.rb b/spec/lib/data_fixup/populate_root_account_id_on_models_spec.rb index 8cf13a041dc..541b3468de4 100644 --- a/spec/lib/data_fixup/populate_root_account_id_on_models_spec.rb +++ b/spec/lib/data_fixup/populate_root_account_id_on_models_spec.rb @@ -629,20 +629,6 @@ describe DataFixup::PopulateRootAccountIdOnModels do end end - context 'with GroupCategory with course context' do - it_behaves_like 'a datafixup that populates root_account_id' do - let(:record) { group_category(context: @course) } - let(:reference_record) { @course } - end - end - - context 'with GroupCategory with account context' do - it_behaves_like 'a datafixup that populates root_account_id' do - let(:record) { group_category(context: reference_record) } - let(:reference_record) { account_model } - end - end - context 'with LatePolicy' do it_behaves_like 'a datafixup that populates root_account_id' do # for some reason late_policy_model doesn't save the record