- 019: ALTER listings (windows_view_type, wcs counts, ceiling_height,
repair_type, views, living_area, bedrooms, balconies, loggias,
description_minhash, cadastral_number, phones, bargain_allowed,
sale_type, house_source/ext_id, metro_stations)
- 020: ALTER houses (BTI: series_name, entrances, flat_count, is_emergency,
heat/gas/overlap types; Cian: cian_internal_house_id,
management_company_id, transport_accessibility_rate,
advantages/banks/builders/houses_by_turn jsonb + GIN indexes)
- 021: CREATE management_companies + FK to houses.management_company_id
- 022: CREATE agents table + agent_id_fk on listings
- 023: CREATE offer_price_history (per-listing price change timeline)
- 024: CREATE houses_price_dynamics (monthly price/sqm series)
- 025: CREATE house_reliability_checks (наш.дом.рф checks)
- 026: CREATE external_valuations (unified Avito IMV + Cian Valuation cache)
- 027: CREATE EXTENSION pgcrypto + cian_session_cookies (encrypted)
- 028: CREATE house_sources, listing_sources, house_address_aliases
+ address_fingerprint/canonical/merged_into alters
Refs: decisions/CianScraper_v1_Implementation_Plan.md Stage 1
decisions/Schema_Cian_SERP_Inventory.md sec 16, 20.3, 26
decisions/Cross_Source_Matching_Strategy.md sec 2
38 lines
1.4 KiB
PL/PgSQL
38 lines
1.4 KiB
PL/PgSQL
-- 022_agents_table.sql
|
|
-- Purpose: Create agents table for Cian seller/agent profiles; link to listings.
|
|
-- Dependencies:
|
|
-- - listings table (002_core_tables.sql / 011_listings_alter.sql)
|
|
-- Deploy order: Apply after 021.
|
|
--
|
|
-- Sources: Schema_Cian_SERP_Inventory sec 20.3 (offerData.agent structure)
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE IF NOT EXISTS agents (
|
|
id bigserial PRIMARY KEY,
|
|
ext_source text NOT NULL, -- 'cian' / 'avito'
|
|
ext_agent_id text NOT NULL, -- Cian cianUserId (as text for flexibility)
|
|
company_name text, -- 'Новосёл' (агентство)
|
|
is_pro boolean, -- PRO подписка
|
|
skills jsonb, -- [{id, name, parentName}, ...]
|
|
account_type text, -- specialist/agent/agency
|
|
created_at timestamptz NOT NULL DEFAULT NOW(),
|
|
UNIQUE (ext_source, ext_agent_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS agents_source_ext_idx
|
|
ON agents (ext_source, ext_agent_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS agents_company_idx
|
|
ON agents (company_name)
|
|
WHERE company_name IS NOT NULL;
|
|
|
|
-- Link listings to agent profiles
|
|
ALTER TABLE listings
|
|
ADD COLUMN IF NOT EXISTS agent_id_fk bigint REFERENCES agents(id) ON DELETE SET NULL;
|
|
|
|
CREATE INDEX IF NOT EXISTS listings_agent_idx
|
|
ON listings (agent_id_fk)
|
|
WHERE agent_id_fk IS NOT NULL;
|
|
|
|
COMMIT;
|