defmodule Tololo.Repo.Migrations.Prices 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
    create table(:prices, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
      add :money, :money_with_currency, null: false

      add :inserted_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")

      add :updated_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")

      add :product_id,
          references(:products,
            column: :id,
            name: "prices_product_id_fkey",
            type: :uuid,
            prefix: "public",
            on_delete: :delete_all
          )

      add :variant_id,
          references(:products,
            column: :id,
            name: "prices_variant_id_fkey",
            type: :uuid,
            prefix: "public",
            on_delete: :delete_all
          )
    end
  end

  def down do
    drop constraint(:prices, "prices_product_id_fkey")

    drop constraint(:prices, "prices_variant_id_fkey")

    drop table(:prices)
  end
end
