Merge Workstream G: device pairing + ingestion + live broadcast

Resolved conflict in main.py: combined both workstreams' router imports
and registrations (device_router from G, inventory_router from C).
143/143 backend tests pass after cleaning stray pollution from an
earlier parallel workstream run against the shared test DB.
This commit is contained in:
Indiana
2026-07-24 14:57:10 +00:00
6 changed files with 780 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
from app.models.auth_session import AuthSession
from app.models.contact_session import ContactSession
from app.models.device import Device
from app.models.entity import Entity
from app.models.entity_sighting import EntitySighting
from app.models.event import Event
@@ -13,6 +14,7 @@ __all__ = [
"User",
"AuthSession",
"ContactSession",
"Device",
"Entity",
"EntitySighting",
"Event",

View File

@@ -0,0 +1,27 @@
import uuid
from datetime import datetime, timezone
from sqlalchemy import DateTime, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column
from app.db import Base
class Device(Base):
"""A paired hardware sensor node (ESP32-P4 etc.), belonging to exactly
one user. Authenticates telemetry via a bearer token whose hash — never
the raw value — is stored here, identical convention to
`AuthSession.token_hash` (see `app/models/auth_session.py`)."""
__tablename__ = "devices"
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"), index=True)
name: Mapped[str] = mapped_column(String(64))
token_hash: Mapped[str] = mapped_column(String(64), unique=True, index=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
last_seen_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), nullable=True
)