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
41 lines
2.1 KiB
PL/PgSQL
41 lines
2.1 KiB
PL/PgSQL
-- 012_sellers.sql
|
||
-- CREATE TABLE sellers — кэш продавцов с Avito (компании и частные лица)
|
||
--
|
||
-- Dependencies: 002_core_tables.sql (listings table exists — FK будет в 013)
|
||
-- Apply after: 011_listings_alter.sql
|
||
-- Apply before: 013_listings_alter_seller.sql
|
||
--
|
||
-- Source: decisions/Schema_Avito_Houses_Listings_History.md sec 25 (NEW sellers table)
|
||
-- Note: logos НЕ сохраняем (требование 2026-05-23 — без картинок).
|
||
--
|
||
-- Идемпотентно: безопасно запускать повторно.
|
||
|
||
BEGIN;
|
||
|
||
CREATE TABLE IF NOT EXISTS sellers (
|
||
id bigserial PRIMARY KEY,
|
||
source text NOT NULL, -- 'avito' / 'cian'
|
||
ext_seller_id text, -- из seller.url ("/brands/domrf66")
|
||
|
||
name text NOT NULL, -- "Самолёт Плюс Екатеринбург"
|
||
seller_type text, -- "Компания" / "Частное лицо"
|
||
on_platform_since text, -- "На Авито с июля 2012" (raw text, не дата)
|
||
profile_url text, -- "/brands/domrf66"
|
||
-- logos НЕ сохраняем (user req: без картинок)
|
||
|
||
raw_payload jsonb,
|
||
first_seen_at timestamptz NOT NULL DEFAULT NOW(),
|
||
last_seen_at timestamptz NOT NULL DEFAULT NOW(),
|
||
|
||
UNIQUE (source, ext_seller_id)
|
||
);
|
||
|
||
CREATE INDEX IF NOT EXISTS sellers_source_idx ON sellers (source, ext_seller_id);
|
||
|
||
COMMENT ON TABLE sellers IS
|
||
'Кэш продавцов Avito (компании + частные лица). 1 запись на (source, ext_seller_id). '
|
||
'Logos не сохраняются. Связь с listings через sellers.id (FK в 013_listings_alter_seller.sql).';
|
||
COMMENT ON COLUMN sellers.on_platform_since IS
|
||
'Raw текст из Avito (напр. "На Авито с июля 2012"). Не парсим в дату — слишком вариативно.';
|
||
|
||
COMMIT;
|