defmodule Tololo.Repo.Migrations.PriceIdentities 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(:prices, "prices_variant_id_fkey")

    alter table(:prices) do
      modify :variant_id,
             references(:variants,
               column: :id,
               name: "prices_variant_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    create unique_index(:prices, ["((money).currency_code)", :product_id],
             name: "prices_unique_product_index"
           )

    create unique_index(:prices, ["((money).currency_code)", :variant_id],
             name: "prices_unique_variant_index"
           )
  end

  def down do
    drop_if_exists unique_index(:prices, ["((money).currency_code)", :variant_id],
                     name: "prices_unique_variant_index"
                   )

    drop_if_exists unique_index(:prices, ["((money).currency_code)", :product_id],
                     name: "prices_unique_product_index"
                   )

    drop constraint(:prices, "prices_variant_id_fkey")

    alter table(:prices) do
      modify :variant_id,
             references(:products,
               column: :id,
               name: "prices_variant_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end
  end
end
