2025-06-22 21:16:55 +00:00
|
|
|
import os
|
2025-06-03 20:00:30 +00:00
|
|
|
from sqlmodel import create_engine, SQLModel
|
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
2025-06-30 22:57:41 +00:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
2025-06-03 20:00:30 +00:00
|
|
|
|
2026-02-10 22:38:52 +00:00
|
|
|
DATABASE_URL = os.getenv("DB_CONNECTION_STRING", "sqlite:///data/wrongmove.db")
|
2025-06-22 21:16:55 +00:00
|
|
|
|
2025-06-03 20:00:30 +00:00
|
|
|
|
2025-06-30 23:22:12 +00:00
|
|
|
debug = os.getenv("ENV", "dev") == "dev"
|
2025-06-30 22:57:41 +00:00
|
|
|
engine = create_engine(DATABASE_URL, echo=debug) # `echo=True` for debug logs
|
2025-06-03 20:00:30 +00:00
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
|
|
|
|
|
Refactor backend for cleaner error handling, DRY, and type safety
- Extract rate limiter DRY: consolidate 3 duplicated check/respond paths
into _check_counter and _enforce_limit helpers, add proper type annotations
- Replace bare Exception raises with FloorplanDownloadError and
RightmoveApiError; narrow catch clauses to specific exception types;
fix Step base class to inherit from ABC
- Consolidate MAX_OCR_WORKERS into config/scraper_config.py; extract
_find_tenure_value helper to deduplicate tenure parsing
- Extract _build_poi_distances_lookup from stream endpoint to reduce nesting
- Fix csv_exporter: optional decisions.json, NaN instead of -1 sentinels,
guard against division by zero on missing square meters
- Fix notifications.py broken list[Surface]() constructor, database.py
stale comments and missing type annotation, auth.py type:ignore,
ui_exporter.py stale TODO
- Fix 3 pre-existing test failures: mock cache layer in streaming tests,
bypass rate limiter for test isolation, fix cache invalidation test to
account for two-pattern scan loop
2026-02-10 22:19:24 +00:00
|
|
|
def init_db() -> None:
|
2025-06-03 20:00:30 +00:00
|
|
|
"""Create all tables (only for development; use migrations in production)."""
|
|
|
|
|
SQLModel.metadata.create_all(engine)
|