defmodule Radiator.Repo.Migrations.AddCascadeDeleteToRelationships 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
    drop constraint(:episodes, "episodes_show_id_fkey")

    alter table(:episodes) do
      modify :show_id,
             references(:shows,
               column: :id,
               name: "episodes_show_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end

    drop constraint(:chapters, "chapters_episode_id_fkey")

    alter table(:chapters) do
      modify :episode_id,
             references(:episodes,
               column: :id,
               name: "chapters_episode_id_fkey",
               type: :uuid,
               prefix: "public",
               on_delete: :delete_all
             )
    end
  end

  def down do
    drop constraint(:chapters, "chapters_episode_id_fkey")

    alter table(:chapters) do
      modify :episode_id,
             references(:episodes,
               column: :id,
               name: "chapters_episode_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end

    drop constraint(:episodes, "episodes_show_id_fkey")

    alter table(:episodes) do
      modify :show_id,
             references(:shows,
               column: :id,
               name: "episodes_show_id_fkey",
               type: :uuid,
               prefix: "public"
             )
    end
  end
end
