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

  def change do
    alter table(:contacts) do
      # Classifier output. `user_declared_prop_mode` is the raw ADIF
      # PROP_MODE string the operator submitted (if any); it's trusted
      # as ground truth by the classifier when present. The two
      # `propagation_mechanism*` columns are the classifier's output
      # and its enrichment status, following the same pattern as
      # hrrr_status / weather_status / terrain_status / radar_status.
      add :user_declared_prop_mode, :string
      add :propagation_mechanism, :string
      add :propagation_mechanism_confidence, :string
      add :propagation_mechanism_status, :string, null: false, default: "pending"
    end

    # Partial index for the backfill cron to scan only contacts that
    # still need classification. Matches the pattern on other *_status
    # columns.
    create index(:contacts, [:propagation_mechanism_status],
             where: "propagation_mechanism_status <> 'complete'",
             name: :contacts_propagation_mechanism_status_pending_index
           )

    # Lets algo.md / map / analysis queries filter by mechanism without
    # a full table scan.
    create index(:contacts, [:propagation_mechanism])
  end
end
