- 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
30 lines
1.2 KiB
PL/PgSQL
30 lines
1.2 KiB
PL/PgSQL
-- 023_offer_price_history.sql
|
|
-- Purpose: Per-listing price change history from Cian offerData.priceChanges
|
|
-- (and optionally Avito equivalent when available).
|
|
-- Dependencies:
|
|
-- - listings table (002_core_tables.sql)
|
|
-- Deploy order: Apply after 022.
|
|
--
|
|
-- Sources: Schema_Cian_SERP_Inventory sec 16.2, 20.2 (priceChanges array)
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE IF NOT EXISTS offer_price_history (
|
|
id bigserial PRIMARY KEY,
|
|
listing_id bigint NOT NULL REFERENCES listings(id) ON DELETE CASCADE,
|
|
change_time timestamptz NOT NULL, -- changeTime from Cian (ISO-8601)
|
|
price_rub numeric NOT NULL, -- priceData.price в рублях
|
|
diff_percent numeric(5,2), -- вычисленный % относительно предыдущей точки
|
|
source text, -- 'cian' / 'avito'
|
|
recorded_at timestamptz NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
-- Primary access pattern: get ordered history for a listing
|
|
CREATE INDEX IF NOT EXISTS oph_listing_time_idx
|
|
ON offer_price_history (listing_id, change_time DESC);
|
|
|
|
-- Source-level stats
|
|
CREATE INDEX IF NOT EXISTS oph_source_time_idx
|
|
ON offer_price_history (source, change_time DESC);
|
|
|
|
COMMIT;
|