3d3c2bcc57
Collapse the three data layers into one. app/db.py now exposes a single Base, a cached engine bound to app_database_url with SQLite WAL enabled, and get_engine/get_session_local/reset_db_caches/get_db_session. Delete app/auth_db.py, app/poo_db.py and app/models/base.py. All models (auth, config, public_ip, location, poo) inherit the one Base and register on a single metadata. Dependencies converge to a single get_db; all routes use it. Also update the alembic env.py files (app/location/poo) and tests that imported the removed modules so the suite stays green, and drop the obsolete test_legacy_style_location_db test whose flow (app reading a separate location DB) no longer exists. Location/poo Alembic chains, adopt scripts and adoption tests remain for M1-T04; config fields remain for M1-T05. pytest 109 passed; ruff clean (pre-existing only); WAL verified; single Base.metadata holds all seven tables.
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db import Base
|
|
|
|
|
|
class PublicIPState(Base):
|
|
__tablename__ = "public_ip_state"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
current_ipv4: Mapped[str] = mapped_column(String(45), nullable=False)
|
|
previous_ipv4: Mapped[str | None] = mapped_column(String(45), nullable=True)
|
|
first_seen_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
|
last_checked_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
|
last_changed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
last_check_status: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
last_check_error: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
last_provider: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
|
|
|
|
class PublicIPHistory(Base):
|
|
__tablename__ = "public_ip_history"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
ipv4: Mapped[str] = mapped_column(String(45), nullable=False)
|
|
observed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
|
change_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
provider: Mapped[str | None] = mapped_column(String(64), nullable=True) |