gendesign/tradein-mvp/backend/data/sql/032_yandex_history.sql
lekss361 65c2824507 feat(tradein): SQL migrations 030-032 — Yandex schema extensions
- 030_listings_alter_yandex.sql: 7 cols (yandex_offer_id, views_total_yandex,
  publish_date_relative, sale_type_text, agency_name/founded_year/objects_count)
  + 2 partial indexes (yandex_offer_id, agency_name)
- 031_houses_alter_yandex.sql: 9 cols (yandex_jk_id/slug, commission_year/month,
  total_area_ha, corpus_count, yandex_validated_at, yandex_total_listings,
  has_panorama) + 2 partial indexes (yandex_jk_id, commission_year)
- 032_yandex_history.sql: enables source='yandex_valuation' on existing
  house_placement_history + 2 indexes (hph_source_idx, hph_house_source_idx)

Foundation for YandexRealtyScraper v1 (Stages 2-9 follow on subsequent PRs).
Note: numbered 030-032 because 029 was already used by PR #448 (matching/
valuation/dynamics extensions). All BEGIN/COMMIT, ADD COLUMN IF NOT EXISTS,
nullable, idempotent.
2026-05-23 15:53:11 +03: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;