defmodule Tololo.Repo.Migrations.ReferenceDelete 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(:variant_option, "variant_option_option_value_id_fkey")

    drop constraint(:variant_option, "variant_option_variant_id_fkey")

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

      modify :option_value_id,
             references(:option_values,
               column: :id,
               name: "variant_option_option_value_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    drop constraint(:product_option, "product_option_option_id_fkey")

    drop constraint(:product_option, "product_option_product_id_fkey")

    alter table(:product_option) do
      modify :product_id,
             references(:products,
               column: :id,
               name: "product_option_product_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )

      modify :option_id,
             references(:options,
               column: :id,
               name: "product_option_option_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    drop constraint(:options, "options_product_id_fkey")

    alter table(:options) do
      modify :product_id,
             references(:products,
               column: :id,
               name: "options_product_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    drop constraint(:option_values, "option_values_variant_id_fkey")

    drop constraint(:option_values, "option_values_option_id_fkey")

    alter table(:option_values) do
      modify :option_id,
             references(:options,
               column: :id,
               name: "option_values_option_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )

      modify :variant_id,
             references(:variants,
               column: :id,
               name: "option_values_variant_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end
  end

  def down do
    drop constraint(:option_values, "option_values_option_id_fkey")

    drop constraint(:option_values, "option_values_variant_id_fkey")

    alter table(:option_values) do
      modify :variant_id,
             references(:variants,
               column: :id,
               name: "option_values_variant_id_fkey",
               type: :uuid,
               prefix: "public"
             )

      modify :option_id,
             references(:options,
               column: :id,
               name: "option_values_option_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:options, "options_product_id_fkey")

    alter table(:options) do
      modify :product_id,
             references(:products,
               column: :id,
               name: "options_product_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:product_option, "product_option_product_id_fkey")

    drop constraint(:product_option, "product_option_option_id_fkey")

    alter table(:product_option) do
      modify :option_id,
             references(:options,
               column: :id,
               name: "product_option_option_id_fkey",
               type: :uuid,
               prefix: "public"
             )

      modify :product_id,
             references(:products,
               column: :id,
               name: "product_option_product_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:variant_option, "variant_option_variant_id_fkey")

    drop constraint(:variant_option, "variant_option_option_value_id_fkey")

    alter table(:variant_option) do
      modify :option_value_id,
             references(:option_values,
               column: :id,
               name: "variant_option_option_value_id_fkey",
               type: :uuid,
               prefix: "public"
             )

      modify :variant_id,
             references(:variants,
               column: :id,
               name: "variant_option_variant_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end
  end
end
