gendesign/tradein-mvp/backend/data/sql/014_house_reviews.sql
lekss361 a2147872ed
All checks were successful
Deploy Trade-In / build-backend (push) Successful in 23s
Deploy Trade-In / deploy (push) Successful in 27s
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440)
2026-05-23 11:41:44 +00: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;