feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies #445
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#445
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/tradein-cian-migrations"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Stage 1 / Wave 1 of CianScraper v1 — schema foundation для 4 Cian sources (SERP/detail/newbuilding/valuation) + cross-source matching.
Migrations
019_listings_alter_cian.sql020_houses_alter_cian.sql021_management_companies.sql022_agents_table.sql023_offer_price_history.sql024_houses_price_dynamics.sql025_house_reliability_checks.sql026_external_valuations.sql027_cian_session_cookies.sql028_matching_tables.sqlConstraints
BEGIN;/COMMIT;CREATE TABLE IF NOT EXISTS,ADD COLUMN IF NOT EXISTS,CREATE INDEX IF NOT EXISTSDeviations from spec
020addsmanagement_company_idas plainbigint(no FK);021adds FK viaALTER TABLE houses ADD CONSTRAINT. Keeps each file idempotent without cross-file dependencies.024_houses_price_dynamicsuses simpler shape (price_per_sqm + UNIQUE(house_id, month_date, source)) vs vault doc's multi-dimension form. Sufficient for Stage 1 scope; extensible later.021 management_companies.ext_idtyped asbigintper task spec; UNIQUE(ext_source, ext_id, name) для completeness.Refs
decisions/CianScraper_v1_Implementation_Plan.mdStage 1decisions/Schema_Cian_SERP_Inventory.md(sec 16, 20.3, 25, 26)decisions/Cross_Source_Matching_Strategy.md(sec 2)Next waves (blocked by this merge)
cian_state_parser.py+ ScrapedLot extensioncian.pySERP refactorTest plan
- 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 2Merged via deep-code-reviewer — verdict APPROVE.
Deep review summary
Status: APPROVE
Files reviewed: 10 (all P0 — SQL DDL in
tradein-mvp/backend/data/sql/)Lines: +501 / -0
Merge commit:
23e6cbcFindings — none blocking
Idempotency: All 10 files wrapped in BEGIN/COMMIT, use CREATE TABLE IF NOT EXISTS / ADD COLUMN IF NOT EXISTS / CREATE INDEX IF NOT EXISTS / CREATE EXTENSION IF NOT EXISTS. Re-running any single file is safe. Re-running ALL files in order (alphabetical sort via
ls -1 ... | sortindeploy.yml:234) is safe.Ordering: Auto-apply via deploy.yml uses sort → 019→020→021→…→028 matches dependency chain. 020 adds
management_company_idas plain bigint; 021 createsmanagement_companiesthenALTER TABLE houses ADD CONSTRAINT … FK. Drop-create pattern (DROP CONSTRAINT IF EXISTSbeforeADD CONSTRAINT) makes 021 re-runnable.Security: pgcrypto extension created in 027.
cian_session_cookies.cookies_encryptedisbytea(encrypted blob viapgp_sym_encrypt). Encryption key in.env.runtime(per file header). No hardcoded secrets in SQL.Conventions: All files follow
NN_topic.sqlnaming, all usetimestamptz(not bare timestamp), numeric precision appropriate (numeric(7,2)for area,numeric(3,2)for ceiling,bigintfor prices,realfor confidence 0-1).GIN indexes: Correctly placed on jsonb columns where querying expected (
advantages,banks,builders,metro_stations). BTree on scalar lookups. Partial indexes (WHERE col IS NOT NULL) reduce index size on sparse cols.Deviation verification (3 items from PR body)
020 plain bigint + 021 FK ALTER: Verified independently re-runnable. 020 adds
management_company_id bigintwithout FK; 021 createsmanagement_companies, then drops+adds FK constraint. No chicken-and-egg.024 simpler shape: Confirmed —
(house_id, month_date, source)UNIQUE is sufficient for Stage 1. Spec form (room_count, prices_type, period, month_date) preserves Cian realtyValuation multi-dimensional chart. Follow-up needed before Stage 6 newbuilding scraper — add migration 029 extending dimensions.021 ext_id as bigint: Consistent with
cian_internal_house_id bigintfrom Schema_Cian_SERP_Inventory sec 16.5. Cian internally uses numeric IDs.Forward-compat concerns (non-blocking, follow-up tracked)
house_sources/listing_sourcesmissing per-sourceprice_rub/area_m2/raw_payload/last_seen_at(spec sec 2.2)external_valuationssimpler form (no sale/rent split, no chart_change_pct/dir)management_companiesUNIQUE (ext_source, name, ext_id) allows duplicates when ext_id IS NULLhouses.cadastral_numberreferenced by Tier-0 matching algorithm but not added by any migrationcad_buildings.kadastr_numcadastral_numberinlistings(019) semantically overlaps with existingkadastr_num(002)house_reliability_checksno UNIQUE (house_id, source) vs specAnti-regression cross-check
views_total/views_today/metro_stations/house_source/house_ext_id/sale_typeon listings — 019 re-adds viaADD COLUMN IF NOT EXISTS(no error, idempotent). Types match (jsonb, int, text). Cosmetic duplication only.houses.UNIQUE (source, ext_house_id)from 009 still present — Cross_Source_Matching_Strategy sec 2.1 says it should be dropped to enable multi-source viahouse_sources. New design works without dropping it sincehouse_sourcesis the link layer; existing constraint just enforces 1 row per (source, ext_id) in master table. Cleanup deferred to Stage 8.Follow-up issues recommended
house_sources/listing_sourceswithprice_rub/area_m2/raw_payload/last_seen_at/ext_urlper spec sec 2.2 — blocks Stage 8 matching serviceexternal_valuationswith sale/rent split + chart_change_pct/dir + filters_hash + external_house_id — blocks Stage 7 Cian Valuation scraperhouses_price_dynamicswith room_count/prices_type/period dimensions — blocks Stage 6 newbuilding scraper full chart savelistings.cadastral_number(019) withlistings.kadastr_num(002) — pick one canonical column nameAll follow-ups are independent of this PR and trackable separately.