Fix missing precipitation columns and backfill weather data
Add idempotent migration to ensure precip_1h_in and wx_codes columns exist, then reset weather_queued flag and clear stale observations so the cron re-fetches with precipitation data included.
This commit is contained in:
parent
3228835636
commit
da3503223f
2 changed files with 49 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
defmodule Microwaveprop.Repo.Migrations.EnsurePrecipitationColumns do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
execute """
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'surface_observations' AND column_name = 'precip_1h_in'
|
||||
) THEN
|
||||
ALTER TABLE surface_observations ADD COLUMN precip_1h_in double precision;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'surface_observations' AND column_name = 'wx_codes'
|
||||
) THEN
|
||||
ALTER TABLE surface_observations ADD COLUMN wx_codes character varying(255);
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:surface_observations) do
|
||||
remove :precip_1h_in
|
||||
remove :wx_codes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
defmodule Microwaveprop.Repo.Migrations.BackfillSurfaceObservationsWithPrecipitation do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
# Delete surface observations that were fetched without precipitation data
|
||||
# so the weather cron re-fetches them with the new p01i/wxcodes fields
|
||||
execute "DELETE FROM surface_observations WHERE precip_1h_in IS NULL AND wx_codes IS NULL"
|
||||
|
||||
# Reset the weather_queued flag so QSOs are re-enqueued for weather fetching
|
||||
execute "UPDATE qsos SET weather_queued = false"
|
||||
end
|
||||
|
||||
def down do
|
||||
# Cannot restore deleted observations; no-op
|
||||
:ok
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue