gendesign/tradein-mvp/scripts/probe-migration-028.py
lekss361 70e45ce5e9 feat(tradein-scripts): scrapers, probes, Phase C improvements
New scripts:
- avito-playwright-sweep.py — Playwright-based Avito sweep (bypasses Qrator)
- backfill-yandex-addresses-ekb.py — fill street-only listings.address с house number
- local-sweep-ekb-{cian,yandex,}.py — full ЕКБ sweep through residential IP
- probe-* — quick diagnostics (region leak, migration status, parser filter, db counts)
- inspect-{houses,search}-html.py — Avito DOM structure analysis
- test-playwright.py — minimal Playwright smoke

Phase C script updates (backfill-house-imv.py):
- Pipe avito_imv module logs to avito-raw.log file (env AVITO_LOG_PATH override)
- Clamp rooms=0 (studio) → 1 — Avito IMV API rejects rooms=0 with HTTP 400
2026-05-24 22:49:20 +03:00

74 lines
2.3 KiB
Python

"""Проверка состояния миграции 028_matching_tables.sql на прод tradein-postgres."""
from __future__ import annotations
import os
import psycopg
dsn = os.environ["DATABASE_URL"].replace("postgresql+psycopg://", "postgresql://")
conn = psycopg.connect(dsn)
cur = conn.cursor()
EXPECTED_COLUMNS = [
("houses", "address_fingerprint"),
("listings", "canonical"),
("listings", "merged_into"),
]
EXPECTED_INDEXES = [
"houses_addr_fp_idx",
"listings_merged_into_idx",
"house_sources_house_idx",
"house_sources_low_conf_idx",
"listing_sources_listing_idx",
"listing_sources_low_conf_idx",
"listing_sources_scraped_idx",
"haa_house_idx",
"haa_fingerprint_idx",
]
EXPECTED_TABLES = ["house_sources", "listing_sources", "house_address_aliases"]
print("=== Columns ===")
for tbl, col in EXPECTED_COLUMNS:
cur.execute(
"SELECT 1 FROM information_schema.columns WHERE table_name=%s AND column_name=%s",
(tbl, col),
)
status = "" if cur.fetchone() else "✗ MISSING"
print(f" {tbl}.{col:<25} {status}")
print("\n=== Tables ===")
for tbl in EXPECTED_TABLES:
cur.execute(
"SELECT 1 FROM information_schema.tables WHERE table_name=%s AND table_schema='public'",
(tbl,),
)
status = "" if cur.fetchone() else "✗ MISSING"
print(f" {tbl:<30} {status}")
print("\n=== Indexes ===")
for idx in EXPECTED_INDEXES:
cur.execute(
"SELECT 1 FROM pg_indexes WHERE indexname=%s",
(idx,),
)
status = "" if cur.fetchone() else "✗ MISSING"
print(f" {idx:<35} {status}")
# Проверим есть ли активные транзакции/locks от deploy которые ещё висят
print("\n=== Active transactions (locks on relevant tables) ===")
cur.execute(
"""
SELECT pid, usename, application_name, state, wait_event_type, wait_event,
query_start, substring(query, 1, 80) AS query_head
FROM pg_stat_activity
WHERE state IS DISTINCT FROM 'idle'
AND pid != pg_backend_pid()
ORDER BY query_start NULLS LAST
"""
)
rows = cur.fetchall()
if not rows:
print(" (none — clean)")
else:
for r in rows:
print(f" pid={r[0]} user={r[1]} app={r[2]} state={r[3]} wait={r[4]}/{r[5]} started={r[6]}")
print(f" query: {r[7]!r}")