diff --git a/elixir/apps/domain/lib/domain/gateways/group/changeset.ex b/elixir/apps/domain/lib/domain/gateways/group/changeset.ex index c3fa8ccfa..99e7e9fba 100644 --- a/elixir/apps/domain/lib/domain/gateways/group/changeset.ex +++ b/elixir/apps/domain/lib/domain/gateways/group/changeset.ex @@ -37,7 +37,7 @@ defmodule Domain.Gateways.Group.Changeset do |> put_default_value(:name, &Domain.NameGenerator.generate/0) |> validate_required(@fields) |> validate_length(:name, min: 1, max: 64) - |> unique_constraint(:name, name: :gateway_groups_account_id_name_index) + |> unique_constraint(:name, name: :gateway_groups_account_id_name_managed_by_index) end def delete(%Gateways.Group{} = group) do diff --git a/elixir/apps/domain/priv/repo/migrations/20250219233330_scope_gateway_groups_name_index_by_managed_by.exs b/elixir/apps/domain/priv/repo/migrations/20250219233330_scope_gateway_groups_name_index_by_managed_by.exs new file mode 100644 index 000000000..0510b254c --- /dev/null +++ b/elixir/apps/domain/priv/repo/migrations/20250219233330_scope_gateway_groups_name_index_by_managed_by.exs @@ -0,0 +1,18 @@ +defmodule Domain.Repo.Migrations.ScopeGatewayGroupsNameIndexByManagedBy do + use Ecto.Migration + + # With the introduction of Internet Sites, some customers may have already named + # one of their Sites "Internet". This migration will scope the name constraint to + # include the managed_by column. + def change do + execute("DROP INDEX gateway_groups_account_id_name_index") + + create( + index(:gateway_groups, [:account_id, :name, :managed_by], + name: :gateway_groups_account_id_name_managed_by_index, + unique: true, + where: "deleted_at IS NULL" + ) + ) + end +end