1 class AddUniqueNameConstraints < ActiveRecord::Migration
3 # Ensure uniqueness before adding constraints.
4 ["collections", "pipeline_templates", "groups"].each do |table|
5 rows = ActiveRecord::Base.connection.select_all %{
6 select uuid, owner_uuid, name from #{table} order by owner_uuid, name
11 if r["owner_uuid"] == prev["owner_uuid"] and !r["name"].nil? and r["name"] == prev["name"]
13 ActiveRecord::Base.connection.execute %{
14 update #{table} set name='#{r["name"]} #{n}' where uuid='#{r["uuid"]}'
23 add_index(:collections, [:owner_uuid, :name], unique: true,
24 name: 'collection_owner_uuid_name_unique')
25 add_index(:pipeline_templates, [:owner_uuid, :name], unique: true,
26 name: 'pipeline_template_owner_uuid_name_unique')
27 add_index(:groups, [:owner_uuid, :name], unique: true,
28 name: 'groups_owner_uuid_name_unique')