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

defmodule AshPostgres.TestRepo.Migrations.CreateRecordTempEntitiesTable 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(:records_temp_entities, primary_key: false) do
      add(:id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true)

      add(
        :record_id,
        references(:records,
          column: :id,
          name: "records_temp_entities_record_id_fkey",
          type: :uuid,
          prefix: "public"
        )
      )

      add(
        :temp_entity_id,
        references(:temp_entities,
          column: :id,
          name: "records_temp_entities_temp_entity_id_fkey",
          type: :uuid,
          prefix: "temp"
        )
      )
    end
  end

  def down do
    drop(constraint(:records_temp_entities, "records_temp_entities_record_id_fkey"))

    drop(constraint(:records_temp_entities, "records_temp_entities_temp_entity_id_fkey"))

    drop(table(:records_temp_entities))
  end
end
