add root_account_id to account_users
closes PLAT-5579 test plan: * verify migrations run * verify root_account_id can be set on an AccountUser * verify AccountUser_s live on the same shard as their root account Change-Id: I5a227a9d62552803085eb2db6d6568f58020d0d0 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/235721 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Product-Review: Xander Moffatt <xmoffatt@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Reviewed-by: Clint Furse <cfurse@instructure.com> QA-Review: Clint Furse <cfurse@instructure.com>
This commit is contained in:
parent
c5fe88bfc0
commit
56f9db167a
|
@ -1099,7 +1099,7 @@ class Account < ActiveRecord::Base
|
|||
raise "must be a root account" unless self.root_account?
|
||||
Shard.partition_by_shard(account_chain(include_site_admin: true).uniq) do |accounts|
|
||||
next unless user.associated_shards.include?(Shard.current)
|
||||
AccountUser.active.eager_load(:account).where("user_id=? AND (root_account_id IN (?) OR account_id IN (?))", user, accounts, accounts)
|
||||
AccountUser.active.eager_load(:account).where("user_id=? AND (accounts.root_account_id IN (?) OR account_id IN (?))", user, accounts, accounts)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
class AddRootAccountIdToAccountUsers < ActiveRecord::Migration[5.2]
|
||||
include MigrationHelpers::AddColumnAndFk
|
||||
|
||||
tag :predeploy
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_column_and_fk :account_users, :root_account_id, :accounts
|
||||
add_index :account_users, :root_account_id, algorithm: :concurrently
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :account_users, :root_account_id
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue