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:
@@ -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",
|
||||
|
||||
27
backend/app/models/device.py
Normal file
27
backend/app/models/device.py
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user