X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6a53a3c5d97d33586567f8df082a725f7d229327..a74c5dc699722769537455504d2f59455100cd29:/services/api/db/migrate/20140501165548_add_unique_name_index_to_links.rb diff --git a/services/api/db/migrate/20140501165548_add_unique_name_index_to_links.rb b/services/api/db/migrate/20140501165548_add_unique_name_index_to_links.rb index 0195cf00dd..9c177f788a 100644 --- a/services/api/db/migrate/20140501165548_add_unique_name_index_to_links.rb +++ b/services/api/db/migrate/20140501165548_add_unique_name_index_to_links.rb @@ -1,6 +1,17 @@ -class AddUniqueNameIndexToLinks < ActiveRecord::Migration +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + +class AddUniqueNameIndexToLinks < ActiveRecord::Migration[4.2] def change - # todo: add "check (link_class is not 'name' or name is not null)" - add_index :links, [:tail_uuid, :name], where: "link_class='name'", unique: true + # Make sure PgPower is here. Otherwise the "where" will be ignored + # and we'll end up with a far too restrictive unique + # constraint. (Rails4 should work without PgPower, but that isn't + # tested.) + if not PgPower then raise "No partial column support" end + + add_index(:links, [:tail_uuid, :name], unique: true, + where: "link_class='name'", + name: 'links_tail_name_unique_if_link_class_name') end end