defmodule <%= @app_module %>.<%= @module %> do use Ecto.Schema import Ecto.Changeset <%= if @use_binary_id do %> @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id <% end %> schema "<%= @table %>" do field :name, :string field :slug, :string field :domain, :string field :status, :string, default: "active" field :settings, :map, default: %{} timestamps() end @doc false def changeset(<%= @resource %>, attrs) do <%= @resource %> |> cast(attrs, [:name, :slug, :domain, :status, :settings]) |> validate_required([:name, :slug]) |> validate_format(:slug, ~r/^[a-z0-9_]+$/, message: "must be lowercase alphanumeric with underscores") |> unique_constraint(:slug) |> unique_constraint(:domain) |> validate_inclusion(:status, ["active", "suspended", "pending"]) end end