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

defmodule AshPostgres.TestRepo.Migrations.MigrateResources9 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(:managers, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
      add :name, :text
      add :code, :text, null: false
      add :must_be_present, :text, null: false
      add :role, :text

      add :organization_id,
          references(:orgs,
            column: :id,
            name: "managers_organization_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end

    create unique_index(:managers, [:code], name: "managers_uniq_code_index")
  end

  def down do
    drop_if_exists unique_index(:managers, [:code], name: "managers_uniq_code_index")

    drop constraint(:managers, "managers_organization_id_fkey")

    drop table(:managers)
  end
end