defmodule Mv.Repo.Migrations.AddConstraintsForUserMemberAndProperty do
  @moduledoc """
  Updates resources based on their most recent snapshots.

  This file was autogenerated with `mix ash_postgres.generate_migrations`
  """

  use Ecto.Migration

  def up do
    drop constraint(:users, "users_member_id_fkey")

    alter table(:users) do
      modify :member_id,
             references(:members,
               column: :id,
               name: "users_member_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :nilify_all
             )
    end

    create unique_index(:properties, [:member_id, :property_type_id],
             name: "properties_unique_property_per_member_index"
           )
  end

  def down do
    drop_if_exists unique_index(:properties, [:member_id, :property_type_id],
                     name: "properties_unique_property_per_member_index"
                   )

    drop constraint(:users, "users_member_id_fkey")

    alter table(:users) do
      modify :member_id,
             references(:members,
               column: :id,
               name: "users_member_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end
  end
end
