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

defmodule AshPostgres.TestRepo.Migrations.MigrateResources46 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(:non_multitenant_post_links, primary_key: false) do
      add(:state, :text, default: "active")
      add(:source_id, :uuid, primary_key: true, null: false)

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

    create(
      unique_index(:non_multitenant_post_links, [:source_id, :dest_id],
        name: "non_multitenant_post_links_unique_link_index"
      )
    )
  end

  def down do
    drop_if_exists(
      unique_index(:non_multitenant_post_links, [:source_id, :dest_id],
        name: "non_multitenant_post_links_unique_link_index"
      )
    )

    drop(constraint(:non_multitenant_post_links, "non_multitenant_post_links_source_id_fkey"))

    drop(constraint(:non_multitenant_post_links, "non_multitenant_post_links_dest_id_fkey"))

    drop(table(:non_multitenant_post_links))
  end
end
