defmodule Radiator.Repo.Migrations.CreateEpisodes 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(:episodes, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :guid, :uuid, null: false
      add :title, :text, null: false
      add :subtitle, :text
      add :summary, :text
      add :number, :bigint, null: false
      add :itunes_type, :text, null: false, default: "full"
      add :publication_date, :utc_datetime
      add :duration_seconds, :bigint

      add :inserted_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")

      add :updated_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")
    end

    create unique_index(:episodes, [:guid], name: "episodes_guid_index")
  end

  def down do
    drop_if_exists unique_index(:episodes, [:guid], name: "episodes_guid_index")

    drop table(:episodes)
  end
end
