+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
# Protect referential integrity of owner_uuid columns in other tables
# that can refer to the uuid column in this table.
# record when other objects refer to it.
ActiveRecord::Base.connection.tables.each do |t|
next if t == base.table_name
- next if t == 'schema_migrations'
+ next if t.in?([
+ 'schema_migrations',
+ 'permission_refresh_lock',
+ 'ar_internal_metadata',
+ 'commit_ancestors',
+ 'commits',
+ 'humans',
+ 'jobs',
+ 'job_tasks',
+ 'keep_disks',
+ 'nodes',
+ 'pipeline_instances',
+ 'pipeline_templates',
+ 'repositories',
+ 'specimens',
+ 'traits',
+ ])
klass = t.classify.constantize
next unless klass and 'owner_uuid'.in?(klass.columns.collect(&:name))
base.has_many(t.to_sym,
- foreign_key: :owner_uuid,
- primary_key: :uuid,
+ foreign_key: 'owner_uuid',
+ primary_key: 'uuid',
dependent: :restrict_with_exception)
end
# We need custom protection for changing an owner's primary
# "name" arg is a query label that appears in logs:
"descendant_project_uuids for #{self.uuid}",
# "binds" arg is an array of [col_id, value] for '$1' vars:
- [[nil, self.uuid], [nil, 'project']],
+ [self.uuid, 'project'],
).rows.map do |project_uuid,|
project_uuid
end
# Check for objects that have my old uuid listed as their owner.
self.class.reflect_on_all_associations(:has_many).each do |assoc|
- next unless assoc.foreign_key == :owner_uuid
+ next unless assoc.foreign_key == 'owner_uuid'
if assoc.klass.where(owner_uuid: uuid_was).any?
errors.add(:uuid,
"cannot be changed on a #{self.class} that owns objects")