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

  def change do
    create table(:era5_profiles, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :valid_time, :utc_datetime, null: false
      add :lat, :float, null: false
      add :lon, :float, null: false
      add :profile, {:array, :map}, default: []
      add :hpbl_m, :float
      add :pwat_mm, :float
      add :surface_temp_c, :float
      add :surface_dewpoint_c, :float
      add :surface_pressure_mb, :float
      add :surface_refractivity, :float
      add :min_refractivity_gradient, :float
      add :ducting_detected, :boolean, default: false, null: false
      add :duct_characteristics, {:array, :map}

      timestamps(type: :utc_datetime)
    end

    create unique_index(:era5_profiles, [:lat, :lon, :valid_time])
    create index(:era5_profiles, [:valid_time])

    create table(:rtma_observations, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :valid_time, :utc_datetime, null: false
      add :lat, :float, null: false
      add :lon, :float, null: false
      add :temp_c, :float
      add :dewpoint_c, :float
      add :pressure_mb, :float
      add :wind_u_ms, :float
      add :wind_v_ms, :float
      add :visibility_m, :float
      add :precip_mm, :float

      timestamps(type: :utc_datetime)
    end

    create unique_index(:rtma_observations, [:lat, :lon, :valid_time])
    create index(:rtma_observations, [:valid_time])
  end
end
