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

  def change do
    create table(:pskr_spots_hourly, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :hour_utc, :utc_datetime, null: false
      add :band, :string, null: false
      add :sender_grid, :string, null: false
      add :receiver_grid, :string, null: false
      add :sender_country, :integer
      add :receiver_country, :integer
      add :sender_lat, :float
      add :sender_lon, :float
      add :receiver_lat, :float
      add :receiver_lon, :float
      add :midpoint_lat, :float
      add :midpoint_lon, :float
      add :distance_km, :float
      add :spot_count, :integer, null: false, default: 0
      add :max_snr_db, :integer
      add :min_snr_db, :integer
      add :modes, {:array, :string}, null: false, default: []
      add :first_spot_at, :utc_datetime
      add :last_spot_at, :utc_datetime

      timestamps(type: :utc_datetime)
    end

    create unique_index(:pskr_spots_hourly, [:hour_utc, :band, :sender_grid, :receiver_grid])
    create index(:pskr_spots_hourly, [:hour_utc])
  end
end
