diff --git a/lib/beacon/content/component.ex b/lib/beacon/content/component.ex index 8202a1bd..7791542c 100644 --- a/lib/beacon/content/component.ex +++ b/lib/beacon/content/component.ex @@ -47,6 +47,7 @@ defmodule Beacon.Content.Component do |> validate_required([:site, :name, :template, :example, :category]) |> validate_format(:name, ~r/^[a-z0-9_!]+$/, message: "can only contain lowercase letters, numbers, and underscores") |> validate_exclusion(:name, reserved_names) + |> unique_constraint([:site, :name]) |> validate_unique_attr_name(attrs) |> cast_assoc(:attrs, with: &ComponentAttr.changeset/2) |> cast_assoc(:slots, with: &ComponentSlot.changeset/2) diff --git a/lib/beacon/migration.ex b/lib/beacon/migration.ex index 101b8291..e6dbbb12 100644 --- a/lib/beacon/migration.ex +++ b/lib/beacon/migration.ex @@ -52,7 +52,7 @@ defmodule Beacon.Migration do """ @initial_version 1 - @current_version 6 + @current_version 7 @doc """ Upgrades Beacon database schemas. diff --git a/lib/beacon/migrations/v007.ex b/lib/beacon/migrations/v007.ex new file mode 100644 index 00000000..7e75c644 --- /dev/null +++ b/lib/beacon/migrations/v007.ex @@ -0,0 +1,12 @@ +defmodule Beacon.Migrations.V007 do + @moduledoc false + use Ecto.Migration + + def up do + create_if_not_exists unique_index(:beacon_components, [:site, :name]) + end + + def down do + drop_if_exists unique_index(:beacon_components, [:site, :name]) + end +end