gendesign/data/sql/107_backfill_price_per_m2.sql
lekss361 bfe16ae71b
All checks were successful
Deploy / changes (push) Successful in 5s
Deploy / build-backend (push) Successful in 1m34s
Deploy / build-frontend (push) Has been skipped
Deploy / build-worker (push) Successful in 2m33s
Deploy / deploy (push) Successful in 58s
fix(sf-16): derive price_per_m2 from price_rub in _norm_flat + backfill SQL (#298)
2026-05-17 14:32:23 +00:00

24 lines
930 B
PL/PgSQL

-- 107_backfill_price_per_m2.sql
-- Backfill price_per_m2 = ROUND(price_rub / total_area, 2) for rows where
-- price_rub is known but price_per_m2 was not stored by the scraper.
--
-- Context (SF FixList #16):
-- domrf_kn.py _norm_flat() now derives price_per_m2 on ingest.
-- This one-time UPDATE covers historical rows scraped before the fix.
-- For Малевич (obj_id=64701) and the wider dataset, both price_rub AND
-- price_per_m2 are NULL (DOM.RF /portal/table API does not return per-flat
-- pricing for most objects). Those rows are unaffected by this UPDATE.
-- Only rows where price_rub IS NOT NULL benefit — currently ~849 rows.
--
-- Safe to re-run: idempotent (WHERE price_per_m2 IS NULL).
BEGIN;
UPDATE domrf_kn_flats
SET price_per_m2 = ROUND((price_rub / total_area)::numeric, 2)
WHERE price_per_m2 IS NULL
AND price_rub IS NOT NULL
AND total_area IS NOT NULL
AND total_area > 0;
COMMIT;