defmodule Microwaveprop.Repo.Migrations.DropEra5CdsJobs do
  use Ecto.Migration

  # The ERA5/CDS pipeline was retired in favor of NARR (see
  # rename_era5_profiles_to_narr_profiles). Orphan rows in this table are
  # useless without the workers that wrote them.
  def up do
    drop table(:era5_cds_jobs)
  end

  def down do
    create table(:era5_cds_jobs, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :year, :integer, null: false
      add :month, :integer, null: false
      add :tile_lat, :integer, null: false
      add :tile_lon, :integer, null: false
      add :single_job_id, :string, null: false
      add :pressure_job_id, :string, null: false
      add :submitted_at, :utc_datetime, null: false
      add :last_polled_at, :utc_datetime
      add :poll_count, :integer, default: 0, null: false

      timestamps(type: :utc_datetime)
    end

    create unique_index(:era5_cds_jobs, [:year, :month, :tile_lat, :tile_lon])
  end
end
