1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class AddUniqueNameConstraints < ActiveRecord::Migration
7 # Ensure uniqueness before adding constraints.
8 ["collections", "pipeline_templates", "groups"].each do |table|
9 rows = ActiveRecord::Base.connection.select_all %{
10 select uuid, owner_uuid, name from #{table} order by owner_uuid, name
15 if r["owner_uuid"] == prev["owner_uuid"] and !r["name"].nil? and r["name"] == prev["name"]
17 ActiveRecord::Base.connection.execute %{
18 update #{table} set name='#{r["name"]} #{n}' where uuid='#{r["uuid"]}'
27 add_index(:collections, [:owner_uuid, :name], unique: true,
28 name: 'collection_owner_uuid_name_unique')
29 add_index(:pipeline_templates, [:owner_uuid, :name], unique: true,
30 name: 'pipeline_template_owner_uuid_name_unique')
31 add_index(:groups, [:owner_uuid, :name], unique: true,
32 name: 'groups_owner_uuid_name_unique')