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

defmodule AshPostgres.TestRepo.Migrations.MigrateResources18 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
    rename table(:post_followers), :user_id, to: :follower_id

    drop constraint(:post_followers, "post_followers_user_id_fkey")

    alter table(:post_followers) do
      modify :follower_id,
             references(:users,
               column: :id,
               name: "post_followers_follower_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    execute(
      "ALTER TABLE post_followers alter CONSTRAINT post_followers_follower_id_fkey NOT DEFERRABLE"
    )
  end

  def down do
    drop constraint(:post_followers, "post_followers_follower_id_fkey")

    alter table(:post_followers) do
      modify :user_id,
             references(:users,
               column: :id,
               name: "post_followers_user_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    rename table(:post_followers), :follower_id, to: :user_id
  end
end