gendesign/tradein-mvp/backend/data/sql
lekss361 e5fb209ced feat(tradein): scraper_settings -- live-config request delay for Yandex scrapers + admin triggers
Backend foundation for the Yandex admin scraper page (UI follows in next PR).

scraper_settings (mig 053):
- New table source PK + request_delay_sec numeric(5,2) + updated_at + description
- Seeded with row 'yandex' = 5.0s (umbrella key for all 4 Yandex scrapers)

scraper_settings.py (new):
- get_scraper_delay(source) -> float, with 60s in-process cache + DB fallback
- Yandex sub-scrapers (yandex_detail / yandex_newbuilding / yandex_valuation)
  resolve to umbrella 'yandex' key via _KEY_ALIASES
- invalidate_cache(source | None) for admin PUT side-effect
- Deferred SessionLocal import (_open_session helper) for unit-test compat

4 Yandex scrapers wired to load delay at __init__:
- yandex_realty.py / yandex_detail.py / yandex_newbuilding.py / yandex_valuation.py
- Class default bumped to 5.0; instance value overridden via get_scraper_delay(self.name)

admin.py -- 5 new endpoints:
- GET    /scraper-settings           list[ScraperSetting]
- PUT    /scraper-settings/{source}  upsert + invalidate_cache
- POST   /scrape/yandex-detail       offer_url= -> detail snapshot
- POST   /scrape/yandex-newbuilding  slug=, id=, city=ekaterinburg -> JK snapshot
- POST   /scrape/yandex-valuation    address=, offer_category=, offer_type=, page= -> house meta

Tests: 10 + 4 = 14 new unit tests (loader cache/alias/error paths + scraper wiring).
Ruff clean.
2026-05-23 18:22:27 +03:00
..
001_trade_in_estimates.sql feat: add tradein-mvp subproject (Trade-In Estimator под /trade-in) 2026-05-21 00:25:39 +03:00
002_core_tables.sql feat: add tradein-mvp subproject (Trade-In Estimator под /trade-in) 2026-05-21 00:25:39 +03:00
003_seed_deals.sql fix(tradein): убрать TRUNCATE из seed — деплой больше не wipe-ит данные 2026-05-21 13:19:24 +03:00
004_extend_trade_in_estimates.sql feat: add tradein-mvp subproject (Trade-In Estimator под /trade-in) 2026-05-21 00:25:39 +03:00
005_geocode_tracking.sql feat(tradein): geocode-missing для deals (#4 завершение) 2026-05-21 20:04:19 +03:00
006_cad_buildings.sql feat(tradein): кадастр зданий как источник house_metadata (#393) 2026-05-22 10:54:42 +05:00
007_estimate_photos.sql feat(tradein): backend загрузки фото квартиры (#394) 2026-05-22 11:05:35 +05:00
008_crm_fields.sql feat(tradein): CRM-поля в форме оценки (#395) 2026-05-22 11:15:15 +05:00
009_houses.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
010_houses_alter.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
011_listings_alter.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
012_sellers.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
013_listings_alter_seller.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
014_house_reviews.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
015_scrape_runs.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
016_listings_snapshots.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
017_house_placement_history.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
018_avito_imv_evaluations.sql feat(tradein): SQL migrations 009-018 — houses + listings extension + IMV cache (#440) 2026-05-23 11:41:44 +00:00
019_listings_alter_cian.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
020_houses_alter_cian.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
021_management_companies.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
022_agents_table.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
023_offer_price_history.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
024_houses_price_dynamics.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
025_house_reliability_checks.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
026_external_valuations.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
027_cian_session_cookies.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
028_matching_tables.sql feat(tradein): SQL migrations 019-028 — Cian schema + matching + cookies 2026-05-23 15:14:49 +03:00
029_extend_matching_valuation_dynamics.sql feat(tradein): SQL migration 029 — extend matching/valuation/dynamics tables (PR #445 follow-up) (#448) 2026-05-23 12:35:03 +00:00
030_avito_imv_cache_key_unique.sql fix(tradein): 030 — UNIQUE constraint on avito_imv_evaluations.cache_key (unblocks PR #452) (#454) 2026-05-23 13:04:21 +00:00
030_listings_alter_yandex.sql feat(tradein): SQL migrations 030-032 — Yandex schema (listings/houses/history) (#453) 2026-05-23 13:00:54 +00:00
031_houses_alter_yandex.sql feat(tradein): SQL migrations 030-032 — Yandex schema (listings/houses/history) (#453) 2026-05-23 13:00:54 +00:00
032_yandex_history.sql feat(tradein): SQL migrations 030-032 — Yandex schema (listings/houses/history) (#453) 2026-05-23 13:00:54 +00:00
040_houses_extend.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
041_house_sources_noop.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
042_listing_sources_price_divergence_idx.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
043_house_reviews_extend.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
044_external_valuations_link.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
045_house_placement_history_extend.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
046_views.sql feat(tradein): SQL 040-046 — matching schema delta (Phase 1.1) (#464) 2026-05-23 13:30:22 +00:00
050_search_optimization.sql feat(tradein): search matview + indexes (Phase 3.1) (#469) 2026-05-23 14:01:18 +00:00
051_scrape_runs_extend.sql feat(tradein): city sweep — auto ЕКБ pipeline (#477) 2026-05-23 14:38:07 +00:00
052_scrape_schedules.sql feat(tradein): in-app scheduler — UI-managed schedule (replaces SSH crontab) (#482) 2026-05-23 14:54:25 +00:00
053_scraper_settings.sql feat(tradein): scraper_settings -- live-config request delay for Yandex scrapers + admin triggers 2026-05-23 18:22:27 +03:00