gendesign/tradein-mvp/backend/data/sql/012_sellers.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

41 lines
2.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.

-- 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;