gendesign/tradein-mvp/backend/data/sql/040_houses_extend.sql
lekss361 d019b5327e feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1)
Multi-Source Integration Phase 1.1 thin-delta migrations. Gap audit showed
80%+ of planned schema already in 014/017/020/026/028/029/030/031 —
this PR adds only the missing pieces:

- 040 houses_extend: complex_id + avito_validated_at + cian_validated_at
- 041 house_sources_noop: COMMENT aliases for ext_source/ext_id/matched_method
- 042 listing_sources_price_divergence_idx: partial index for /search
- 043 house_reviews_extend: likes column
- 044 external_valuations_link: house_id/listing_id FKs + low/high price band
- 045 house_placement_history_extend: source_confidence + notes + 3-col UNIQUE
- 046 views: v_price_divergence + v_cross_source_health + v_data_quality

All BEGIN/COMMIT, IF NOT EXISTS, FK ON DELETE CASCADE.
Idempotent — safe re-apply on prod.

Refs Master Plan sec 1, 4-8 + Cross_Source_Matching sec 2-4.
2026-05-23 16:22:58 +03:00

26 lines
1.2 KiB
PL/PgSQL

-- 040_houses_extend.sql
-- Purpose: Add complex_id FK placeholder + per-source enrichment timestamps to houses.
-- Most planned columns (address_fingerprint, cadastral_number, commission_year/month,
-- corpus_count, total_area_ha, has_panorama, yandex_jk_id/slug, yandex_validated_at,
-- cian_internal_house_id) already added in earlier migrations (028/029/020/031).
-- Dependencies: 009_houses.sql (houses table)
-- Apply after: 032_yandex_history.sql
BEGIN;
ALTER TABLE houses
ADD COLUMN IF NOT EXISTS complex_id bigint,
ADD COLUMN IF NOT EXISTS avito_validated_at timestamptz,
ADD COLUMN IF NOT EXISTS cian_validated_at timestamptz;
CREATE INDEX IF NOT EXISTS houses_complex_id_idx
ON houses (complex_id) WHERE complex_id IS NOT NULL;
COMMENT ON COLUMN houses.complex_id IS
'FK placeholder for future complexes (ЖК-level) table. NULL until ЖК aggregation introduced.';
COMMENT ON COLUMN houses.avito_validated_at IS
'Timestamp of last enrichment from Avito Houses Catalog (mirror of yandex_validated_at semantics).';
COMMENT ON COLUMN houses.cian_validated_at IS
'Timestamp of last enrichment from Cian newbuilding/BTI (mirror of yandex_validated_at semantics).';
COMMIT;