- 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
45 lines
1.8 KiB
PL/PgSQL
45 lines
1.8 KiB
PL/PgSQL
-- 021_management_companies.sql
|
||
-- Purpose: Create management_companies table for ТСЖ/УК data from Cian Valuation Calculator.
|
||
-- Also adds FK constraint to houses.management_company_id (column added in 020).
|
||
-- Dependencies:
|
||
-- - 020_houses_alter_cian.sql must be applied first (adds management_company_id column to houses)
|
||
-- Deploy order: Apply after 020.
|
||
--
|
||
-- Sources: Schema_Cian_SERP_Inventory sec 26.3
|
||
|
||
BEGIN;
|
||
|
||
CREATE TABLE IF NOT EXISTS management_companies (
|
||
id bigserial PRIMARY KEY,
|
||
name text NOT NULL, -- 'ТСЖ "УЧИТЕЛЕЙ, 18"'
|
||
phones text[], -- array of phone strings
|
||
email text,
|
||
opening_hours text, -- raw string or serialised schedule
|
||
chief_name text, -- ФИО руководителя
|
||
ext_source text NOT NULL DEFAULT 'cian',
|
||
ext_id bigint, -- Cian's internal management company ID if available
|
||
created_at timestamptz NOT NULL DEFAULT NOW(),
|
||
UNIQUE (ext_source, name, ext_id)
|
||
);
|
||
|
||
-- ext_source + ext_id for dedup when Cian provides numeric ID
|
||
CREATE INDEX IF NOT EXISTS mc_ext_source_id_idx
|
||
ON management_companies (ext_source, ext_id)
|
||
WHERE ext_id IS NOT NULL;
|
||
|
||
-- Text search on company name
|
||
CREATE INDEX IF NOT EXISTS mc_name_idx
|
||
ON management_companies (name);
|
||
|
||
-- Add FK from houses.management_company_id to this table
|
||
-- Column management_company_id was added in 020_houses_alter_cian.sql as plain bigint
|
||
ALTER TABLE houses
|
||
DROP CONSTRAINT IF EXISTS houses_management_company_id_fkey;
|
||
|
||
ALTER TABLE houses
|
||
ADD CONSTRAINT houses_management_company_id_fkey
|
||
FOREIGN KEY (management_company_id)
|
||
REFERENCES management_companies (id)
|
||
ON DELETE SET NULL;
|
||
|
||
COMMIT;
|