From f4f44b5ebe2c2904e4eeaaeff723569f49f3c9fe Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 21 Apr 2026 09:28:27 -0500 Subject: [PATCH] refactor(contacts): rename propagation_mechanism_status -> mechanism_status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Column name now matches the type key used everywhere else: :hrrr -> hrrr_status, :weather -> weather_status, :terrain -> terrain_status, :mechanism -> mechanism_status Drops the @status_column_overrides remap in BackfillEnqueueWorker (status_column/1 is now a straight :"#{type}_status" derivation) and the long-form references in Contact, ContactWeatherEnqueueWorker, and MechanismClassifyWorker. Migration is a metadata-only RENAME COLUMN + RENAME INDEX — safe to land in prod (no table rewrite, brief catalog lock only). --- lib/microwaveprop/radio/contact.ex | 2 +- .../workers/backfill_enqueue_worker.ex | 8 +------ .../workers/contact_weather_enqueue_worker.ex | 4 ++-- .../workers/mechanism_classify_worker.ex | 5 ++--- ...36_rename_propagation_mechanism_status.exs | 21 +++++++++++++++++++ .../contact_weather_enqueue_worker_test.exs | 2 +- .../mechanism_classify_worker_test.exs | 6 +++--- 7 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 priv/repo/migrations/20260421142436_rename_propagation_mechanism_status.exs diff --git a/lib/microwaveprop/radio/contact.ex b/lib/microwaveprop/radio/contact.ex index 6378a78f..52fab53d 100644 --- a/lib/microwaveprop/radio/contact.ex +++ b/lib/microwaveprop/radio/contact.ex @@ -52,7 +52,7 @@ defmodule Microwaveprop.Radio.Contact do field :propagation_mechanism, :string field :propagation_mechanism_confidence, Ecto.Enum, values: [:high, :medium, :low] - field :propagation_mechanism_status, Ecto.Enum, + field :mechanism_status, Ecto.Enum, values: [:pending, :queued, :processing, :complete, :failed, :unavailable], default: :pending diff --git a/lib/microwaveprop/workers/backfill_enqueue_worker.ex b/lib/microwaveprop/workers/backfill_enqueue_worker.ex index 4410b3da..074ab609 100644 --- a/lib/microwaveprop/workers/backfill_enqueue_worker.ex +++ b/lib/microwaveprop/workers/backfill_enqueue_worker.ex @@ -33,12 +33,6 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do # Skip these in any reconcile / ordering pass that reads a _status field. @virtual_types [:narr] - # `radar` and `mechanism` use differently-named *_status columns than - # `_status`, so we remap them when building queries and update_alls. - @status_column_overrides %{ - mechanism: :propagation_mechanism_status - } - # A :queued contact whose updated_at is older than this is one the cron has # already tried ~144 times over 3 days without the underlying worker landing # data. At that point the data is effectively unreachable (dead ASOS station, @@ -118,7 +112,7 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do end end - defp status_column(type), do: Map.get(@status_column_overrides, type, :"#{type}_status") + defp status_column(type), do: :"#{type}_status" # Flip contacts that have been stuck in :queued for longer than # @stale_queued_cutoff_seconds to :unavailable. One Repo.update_all per type, diff --git a/lib/microwaveprop/workers/contact_weather_enqueue_worker.ex b/lib/microwaveprop/workers/contact_weather_enqueue_worker.ex index ddee2e87..c60d0f8a 100644 --- a/lib/microwaveprop/workers/contact_weather_enqueue_worker.ex +++ b/lib/microwaveprop/workers/contact_weather_enqueue_worker.ex @@ -117,7 +117,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorker do if :radar in types, do: Radio.set_enrichment_status!(ids, :radar_status, :unavailable) if :mechanism in types, - do: Radio.set_enrichment_status!(ids, :propagation_mechanism_status, :unavailable) + do: Radio.set_enrichment_status!(ids, :mechanism_status, :unavailable) end defp mark_pos1_statuses(contact, ids, types, jobs_by_type) do @@ -131,7 +131,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorker do if :radar in types, do: mark_radar_status!(contact, ids, jobs_by_type[:radar]) if :mechanism in types, - do: mark_status!(ids, :propagation_mechanism_status, jobs_by_type[:mechanism]) + do: mark_status!(ids, :mechanism_status, jobs_by_type[:mechanism]) end # IEM n0q composite reflectivity archive only has meaningful CONUS diff --git a/lib/microwaveprop/workers/mechanism_classify_worker.ex b/lib/microwaveprop/workers/mechanism_classify_worker.ex index 2c513a81..614f3a05 100644 --- a/lib/microwaveprop/workers/mechanism_classify_worker.ex +++ b/lib/microwaveprop/workers/mechanism_classify_worker.ex @@ -13,8 +13,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorker do * `active_meteor_shower` — looked up from the static shower calendar Results land on the contact as `propagation_mechanism` (string), - `propagation_mechanism_confidence` (enum), and - `propagation_mechanism_status`. + `propagation_mechanism_confidence` (enum), and `mechanism_status`. Unique on `contact_id` so the submit-time enqueue path and the backfill cron collapse to a single job per contact. @@ -236,7 +235,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorker do defp mark_status(%Contact{} = contact, status, mechanism, confidence) do contact |> Ecto.Changeset.change(%{ - propagation_mechanism_status: status, + mechanism_status: status, propagation_mechanism: mechanism, propagation_mechanism_confidence: confidence }) diff --git a/priv/repo/migrations/20260421142436_rename_propagation_mechanism_status.exs b/priv/repo/migrations/20260421142436_rename_propagation_mechanism_status.exs new file mode 100644 index 00000000..07dded1d --- /dev/null +++ b/priv/repo/migrations/20260421142436_rename_propagation_mechanism_status.exs @@ -0,0 +1,21 @@ +defmodule Microwaveprop.Repo.Migrations.RenamePropagationMechanismStatus do + use Ecto.Migration + + def up do + execute """ + ALTER INDEX contacts_propagation_mechanism_status_pending_index + RENAME TO contacts_mechanism_status_pending_index + """ + + rename table(:contacts), :propagation_mechanism_status, to: :mechanism_status + end + + def down do + rename table(:contacts), :mechanism_status, to: :propagation_mechanism_status + + execute """ + ALTER INDEX contacts_mechanism_status_pending_index + RENAME TO contacts_propagation_mechanism_status_pending_index + """ + end +end diff --git a/test/microwaveprop/workers/contact_weather_enqueue_worker_test.exs b/test/microwaveprop/workers/contact_weather_enqueue_worker_test.exs index d7b124b1..b3e674f8 100644 --- a/test/microwaveprop/workers/contact_weather_enqueue_worker_test.exs +++ b/test/microwaveprop/workers/contact_weather_enqueue_worker_test.exs @@ -736,7 +736,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do # BackfillEnqueueWorker from re-scanning these contacts every cron. assert updated.terrain_status == :unavailable assert updated.radar_status == :unavailable - assert updated.propagation_mechanism_status == :unavailable + assert updated.mechanism_status == :unavailable end # Pre-2014 contacts have no HRRR data ever; mark hrrr_status :unavailable diff --git a/test/microwaveprop/workers/mechanism_classify_worker_test.exs b/test/microwaveprop/workers/mechanism_classify_worker_test.exs index eefc0203..43bcf039 100644 --- a/test/microwaveprop/workers/mechanism_classify_worker_test.exs +++ b/test/microwaveprop/workers/mechanism_classify_worker_test.exs @@ -64,7 +64,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do reloaded = Repo.get!(Contact, contact.id) assert reloaded.propagation_mechanism == "rain_scatter" - assert reloaded.propagation_mechanism_status == :complete + assert reloaded.mechanism_status == :complete assert reloaded.propagation_mechanism_confidence == :high end @@ -78,7 +78,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do reloaded = Repo.get!(Contact, contact.id) assert reloaded.propagation_mechanism == "troposcatter" - assert reloaded.propagation_mechanism_status == :complete + assert reloaded.mechanism_status == :complete assert reloaded.propagation_mechanism_confidence == :low end @@ -126,7 +126,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do }) reloaded = Repo.get!(Contact, contact.id) - assert reloaded.propagation_mechanism_status == :unavailable + assert reloaded.mechanism_status == :unavailable end test "missing contact (deleted) returns :ok gracefully" do