gendesign/tradein-mvp/backend/data/sql/032_yandex_history.sql
lekss361 f452b132c9
All checks were successful
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / build-backend (push) Successful in 23s
Deploy Trade-In / deploy (push) Successful in 19s
feat(tradein): SQL migrations 030-032 — Yandex schema (listings/houses/history) (#453)
2026-05-23 13:00:54 +00:00

31 lines
1.4 KiB
PL/PgSQL

-- 032_yandex_history.sql
-- Purpose: Enable source='yandex_valuation' on existing house_placement_history table by
-- updating the column COMMENT to document the new value and adding analytics-friendly
-- indexes for efficient filtered queries on the new source.
-- Dependencies: 017_house_placement_history.sql (table must already exist)
-- Deploy order: Apply after 031_houses_alter_yandex.sql
--
-- Sources:
-- - decisions/Schema_YandexRealty_Recon.md sec 12.5 + 13.2
-- - YandexRealtyScraper_v1_Implementation_Plan Stage 1
--
-- Note: Idempotent — does NOT alter table schema (no ADD/DROP COLUMN).
-- Only updates COMMENT metadata and creates indexes with IF NOT EXISTS.
-- Safe to re-run; COMMENT ON COLUMN is always an overwrite (no-error on repeat).
BEGIN;
-- Update column comment to document the new source enum value
COMMENT ON COLUMN house_placement_history.source IS
'Source of history record: avito / avito_imv / cian / yandex_valuation';
-- Partial index for analytics queries filtered by source (mostly yandex_valuation)
CREATE INDEX IF NOT EXISTS hph_source_idx
ON house_placement_history (source);
-- Composite index for "all history for a house from a specific source"
CREATE INDEX IF NOT EXISTS hph_house_source_idx
ON house_placement_history (house_id, source, last_price_date DESC)
WHERE house_id IS NOT NULL;
COMMIT;