909 B · text 5af55d9
defmodule GitGud.Repo.Migrations.SplitRepoUniqueness do
use Ecto.Migration
def up do
# Old index: (owner_id, name). Replace with two partial indexes so
# user-owned and org-owned namespaces don't collide.
drop_if_exists unique_index(:repositories, [:owner_id, :name])
create unique_index(:repositories, [:owner_id, :name],
where: "organization_id IS NULL",
name: :repositories_user_owner_id_name_index
)
create unique_index(:repositories, [:organization_id, :name],
where: "organization_id IS NOT NULL",
name: :repositories_org_id_name_index
)
end
def down do
drop_if_exists index(:repositories, [], name: :repositories_user_owner_id_name_index)
drop_if_exists index(:repositories, [], name: :repositories_org_id_name_index)
create unique_index(:repositories, [:owner_id, :name])
end
end