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

defmodule Demo.Repo.Migrations.MigrateResources2 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
    alter table(:users) do
      add :type, :text
    end

    drop_if_exists unique_index(:users, [:first_name, :last_name],
                     name: "users_representative_name_index"
                   )

    create unique_index(:users, [:id, :first_name, :last_name],
             where: "representative = true",
             name: "users_representative_name_index"
           )
  end

  def down do
    drop_if_exists unique_index(:users, [:id, :first_name, :last_name],
                     name: "users_representative_name_index"
                   )

    create unique_index(:users, [:id, :first_name, :last_name],
             where: "representative = true",
             name: "users_representative_name_index"
           )

    alter table(:users) do
      remove :type
    end
  end
end