gendesign/tradein-mvp/backend/data/sql/031_houses_alter_yandex.sql
lekss361 02b48b8d04
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 32s
fix(tradein-sql): rename dup 030, add trade_in_estimates geom, drop dup indexes (#500)
Close 3 SQL schema findings from 2026-05-24 trade-in audit.

- Rename 030_listings_alter_yandex.sql -> 033_*.sql (resolve dup prefix with 030_avito_imv_cache_key_unique.sql).
- New 034_trade_in_estimates_geom.sql: PostGIS geom column + GIST index + backfill + BEFORE INSERT/UPDATE trigger.
- New 035_drop_duplicate_indexes.sql: drop listing_sources_listing_idx2 (dup of 028) and houses_geom_idx2 (dup of 009).

All idempotent. Deploy script uses ls|sort + no tracking table — rename is safe because original 030 already applied (IF NOT EXISTS no-op on re-run as 033).
2026-05-24 10:04:40 +00:00

41 lines
2 KiB
PL/PgSQL

-- 031_houses_alter_yandex.sql
-- Purpose: Add Yandex Realty-specific columns to houses table (ЖК landing + valuation enrichment).
-- Dependencies:
-- - houses table: 009_houses.sql
-- - 020_houses_alter_cian.sql (prior Cian columns must exist; no FK dependency, column-level only)
-- Deploy order: Apply after 033_listings_alter_yandex.sql (renamed from duplicate-prefix 030 in PR feat/sql-rename-030-and-schema-debt)
--
-- Sources:
-- - decisions/Schema_YandexRealty_Recon.md sec 11.2 (Newbuilding ЖК landing fields)
-- - decisions/Schema_YandexRealty_Recon.md sec 13.1 (Yandex Valuation tool enrichment)
-- - YandexRealtyScraper_v1_Implementation_Plan Stage 1
--
-- Idempotent: all ALTER TABLE uses ADD COLUMN IF NOT EXISTS; all CREATE INDEX use IF NOT EXISTS.
BEGIN;
ALTER TABLE houses
-- Yandex Newbuilding (ЖК) landing
ADD COLUMN IF NOT EXISTS yandex_jk_id text, -- '1592987'
ADD COLUMN IF NOT EXISTS yandex_jk_slug text, -- 'tatlin'
ADD COLUMN IF NOT EXISTS commission_year int, -- 2023
ADD COLUMN IF NOT EXISTS commission_month text, -- 'июнь' (raw RU month)
ADD COLUMN IF NOT EXISTS total_area_ha numeric(6,2), -- 1.50
ADD COLUMN IF NOT EXISTS corpus_count int, -- 3 (parsed from "три башни")
-- Yandex Valuation tool enrichment
ADD COLUMN IF NOT EXISTS yandex_validated_at timestamptz, -- last enrichment timestamp
ADD COLUMN IF NOT EXISTS yandex_total_listings int, -- "N объектов" в истории дома
ADD COLUMN IF NOT EXISTS has_panorama boolean; -- Yandex Panorama 3D view available
-- Partial index on yandex_jk_id for fast lookup by Yandex newbuilding identifier
CREATE INDEX IF NOT EXISTS houses_yandex_jk_idx
ON houses (yandex_jk_id)
WHERE yandex_jk_id IS NOT NULL;
-- Partial index on commission_year for filtering by year of commissioning
CREATE INDEX IF NOT EXISTS houses_commission_year_idx
ON houses (commission_year)
WHERE commission_year IS NOT NULL;
COMMIT;