gendesign/tradein-mvp/backend/data/sql/014_house_reviews.sql
lekss361 28ddf6ef17 feat(tradein): SQL migrations 009-018 — houses + listings extension + history + IMV cache
Closes Stage 1 of AvitoScraper_v2 plan.

- 009_houses.sql: CREATE TABLE houses (multi-source: avito/cian, geom trigger, 24 cols)
- 010_houses_alter.sql: + 15 cols (material_walls, parking_type, rating_distribution, raw_characteristics, ...)
- 011_listings_alter.sql: + 24 cols (house linking, kitchen_area_m2, owners_count, owners_at_least,
  metro_stations, detail_enriched_at, domoteka/Rosreestr badges, 8 partial indexes)
- 012_sellers.sql: CREATE TABLE sellers (Avito seller cache, no logos)
- 013_listings_alter_seller.sql: listings.seller_id_fk FK
- 014_house_reviews.sql: CREATE TABLE house_reviews (textSections main/pros/cons, no images)
- 015_scrape_runs.sql: CREATE TABLE scrape_runs (status CHECK enum, heartbeat, zombie partial idx)
- 016_listings_snapshots.sql: CREATE TABLE listings_snapshots (append-only, PK listing_id+date)
- 017_house_placement_history.sql: CREATE TABLE house_placement_history (removed_date from IMV only)
- 018_avito_imv_evaluations.sql: CREATE TABLE + cache_key col + imv_cache_key_idx (TTL 24h lookup)

All migrations: BEGIN/COMMIT, IF NOT EXISTS idempotent, PostGIS geom triggers reuse listings_set_geom().
Smoke tested locally: 7 new tables, 34 indexes, 14 listings columns verified.

Refs: decisions/Schema_Avito_Houses_Listings_History.md (sec 4.2, 4.3, 4.4, 6, 7, 13, 25, 29)
Refs: decisions/AvitoScraper_v2_Implementation_Plan.md Stage 1
2026-05-23 14:29:04 +03:00

57 lines
3.1 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 014_house_reviews.sql
-- CREATE TABLE house_reviews — отзывы жильцов на дома (из Houses Catalog)
--
-- Dependencies: 009_houses.sql (houses table — FK house_id)
-- Apply after: 013_listings_alter_seller.sql
-- Apply before: 015_scrape_runs.sql
--
-- Source: decisions/Schema_Avito_Houses_Listings_History.md sec 25 (NEW house_reviews table)
-- Note: author_avatar и images НЕ сохраняем (требование 2026-05-23 — без картинок).
--
-- Идемпотентно: безопасно запускать повторно.
BEGIN;
CREATE TABLE IF NOT EXISTS house_reviews (
id bigserial PRIMARY KEY,
house_id bigint NOT NULL REFERENCES houses(id) ON DELETE CASCADE,
source text NOT NULL DEFAULT 'avito',
ext_review_id bigint NOT NULL, -- value.id из Avito API
-- Автор (без аватара)
author_name text, -- "Мария"
-- author_avatar НЕ сохраняем (user req: без картинок)
-- Мета-данные отзыва
review_title text, -- "Новый, уютный, теплый..."
score int CHECK (score BETWEEN 1 AND 5),
model_experience text, -- "Живу в своей квартире" / "Часто там бываю"
rated_date date, -- parsed из "9 октября 2025"
-- Текст отзыва (три секции из textSections[])
text_main text, -- textSections[0].text если title=""
text_pros text, -- textSections где title="Преимущества"
text_cons text, -- textSections где title="Недостатки"
-- images НЕ сохраняем (user req: без картинок — raw_payload содержит URLs для retrofit)
raw_payload jsonb, -- полный объект из API для retrofit
scraped_at timestamptz NOT NULL DEFAULT NOW(),
UNIQUE (source, ext_review_id)
);
CREATE INDEX IF NOT EXISTS hr_house_idx ON house_reviews (house_id, rated_date DESC);
CREATE INDEX IF NOT EXISTS hr_source_ext_idx ON house_reviews (source, ext_review_id);
COMMENT ON TABLE house_reviews IS
'Отзывы жильцов на дома из Avito Houses Catalog. 1 запись на (source, ext_review_id). '
'Аватары и фото не сохраняются — используйте raw_payload для retrofit.';
COMMENT ON COLUMN house_reviews.model_experience IS
'Опыт автора: "Живу в своей квартире" / "Часто там бываю" / etc. (raw текст из Avito).';
COMMENT ON COLUMN house_reviews.text_pros IS
'Секция "Преимущества" из textSections. NULL если автор не заполнил.';
COMMENT ON COLUMN house_reviews.text_cons IS
'Секция "Недостатки" из textSections. NULL если автор не заполнил.';
COMMIT;