prop/test/microwaveprop/workers/partition_maintenance_worker_test.exs
Graham McIntire 413cc92cab
feat(infra): auto-extend quarterly partitions for hrrr/hrdps tables
Partition list for hrrr_profiles + hrdps_profiles was hand-edited in
priv/repo/structure.sql; if no human extended it, writes for the next
quarter would silently fail at the worker level (Rust hrrr-point-worker
marks tasks failed; the calibration pipeline silently joins NULLs).

Adds:

* Microwaveprop.PartitionManager — runtime DDL helper. Quarter math via
  a single integer index (year*4 + quarter) for rollover safety.
  Coverage check via pg_inherits before CREATE so a quarterly target
  inside an existing wider partition (some 2027 ones are half-year)
  is treated as :exists rather than colliding.
* Microwaveprop.Workers.PartitionMaintenanceWorker — daily cron at
  03:15 UTC, 4-quarter lookahead. Idempotent; cheap when nothing's
  missing. lookback_quarters arg lets ops widen for catch-up.

Tests cover the create + idempotent re-run + name format + year
rollover paths via a synthetic parent created inside the sandbox
transaction (no DDL leaks into the shared test DB).
2026-05-05 16:22:16 -05:00

28 lines
1.2 KiB
Elixir

defmodule Microwaveprop.Workers.PartitionMaintenanceWorkerTest do
use Microwaveprop.DataCase, async: true
use Oban.Testing, repo: Microwaveprop.Repo
alias Microwaveprop.Workers.PartitionMaintenanceWorker
describe "perform/1" do
test "returns :ok with default args against the real partitioned tables" do
# The test DB ships with hrrr_profiles + hrdps_profiles partitions
# well into 2027 (some of them half-year-wide), so a default
# lookahead pass should be a complete no-op. The coverage check
# in PartitionManager.ensure_partition/3 is what makes that
# safe — without it, this call would try to CREATE a quarterly
# partition that overlaps an existing half-year one and crash.
assert :ok = perform_job(PartitionMaintenanceWorker, %{})
end
test "respects lookahead_quarters override" do
assert :ok = perform_job(PartitionMaintenanceWorker, %{"lookahead_quarters" => 0})
end
test "rejects negative lookahead at the worker boundary" do
# Worker falls through to default when args don't match the
# is_integer + >= 0 guard, so a bogus arg still succeeds.
assert :ok = perform_job(PartitionMaintenanceWorker, %{"lookahead_quarters" => -1})
end
end
end