defmodule AshHq.Repo.Migrations.MigrateResources55 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(:options, "options_dsl_id_fkey"))

    alter table(:options) do
      modify(
        :dsl_id,
        references(:dsls,
          column: :id,
          name: "options_dsl_id_fkey",
          type: :uuid,
          prefix: "public",
          on_delete: :delete_all
        )
      )
    end

    drop(constraint(:dsls, "dsls_dsl_id_fkey"))

    alter table(:dsls) do
      modify(
        :dsl_id,
        references(:dsls,
          column: :id,
          name: "dsls_dsl_id_fkey",
          type: :uuid,
          prefix: "public",
          on_delete: :delete_all
        )
      )
    end

    execute("ALTER TABLE dsls alter CONSTRAINT dsls_dsl_id_fkey NOT DEFERRABLE")

    execute("ALTER TABLE options alter CONSTRAINT options_dsl_id_fkey NOT DEFERRABLE")
  end

  def down do
    drop(constraint(:dsls, "dsls_dsl_id_fkey"))

    alter table(:dsls) do
      modify(
        :dsl_id,
        references(:dsls,
          column: :id,
          name: "dsls_dsl_id_fkey",
          type: :uuid,
          prefix: "public"
        )
      )
    end

    drop(constraint(:options, "options_dsl_id_fkey"))

    alter table(:options) do
      modify(
        :dsl_id,
        references(:dsls,
          column: :id,
          name: "options_dsl_id_fkey",
          type: :uuid,
          prefix: "public"
        )
      )
    end
  end
end
