defmodule Animina.Repo.Migrations.MigrateResources3 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(:reports, "reports_admin_id_fkey")

    drop constraint(:reports, "reports_accuser_id_fkey")

    drop constraint(:reports, "reports_accused_id_fkey")

    alter table(:reports) do
      modify :accused_id,
             references(:users,
               column: :id,
               name: "reports_accused_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    execute("ALTER TABLE reports alter CONSTRAINT reports_accused_id_fkey NOT DEFERRABLE")

    alter table(:reports) do
      modify :accuser_id,
             references(:users,
               column: :id,
               name: "reports_accuser_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    execute("ALTER TABLE reports alter CONSTRAINT reports_accuser_id_fkey NOT DEFERRABLE")

    alter table(:reports) do
      modify :admin_id,
             references(:users,
               column: :id,
               name: "reports_admin_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    execute("ALTER TABLE reports alter CONSTRAINT reports_admin_id_fkey NOT DEFERRABLE")
  end

  def down do
    drop constraint(:reports, "reports_admin_id_fkey")

    alter table(:reports) do
      modify :admin_id,
             references(:users,
               column: :id,
               name: "reports_admin_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:reports, "reports_accuser_id_fkey")

    alter table(:reports) do
      modify :accuser_id,
             references(:users,
               column: :id,
               name: "reports_accuser_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:reports, "reports_accused_id_fkey")

    alter table(:reports) do
      modify :accused_id,
             references(:users,
               column: :id,
               name: "reports_accused_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end
  end
end
