# SPDX-FileCopyrightText: 2020 Zach Daniel
#
# SPDX-License-Identifier: MIT

defmodule AshPostgres.TestRepo.Migrations.MigrateResources47 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(:comment_links, primary_key: false) do
      add(
        :source_id,
        references(:comments,
          column: :id,
          name: "comment_links_source_id_fkey",
          type: :uuid,
          prefix: "public"
        ),
        primary_key: true,
        null: false
      )

      add(
        :dest_id,
        references(:comments,
          column: :id,
          name: "comment_links_dest_id_fkey",
          type: :uuid,
          prefix: "public"
        ),
        primary_key: true,
        null: false
      )
    end

    create(
      unique_index(:comment_links, [:source_id, :dest_id],
        name: "comment_links_unique_link_index"
      )
    )
  end

  def down do
    drop_if_exists(
      unique_index(:comment_links, [:source_id, :dest_id],
        name: "comment_links_unique_link_index"
      )
    )

    drop(constraint(:comment_links, "comment_links_source_id_fkey"))

    drop(constraint(:comment_links, "comment_links_dest_id_fkey"))

    drop(table(:comment_links))
  end
end
