"""WebSocket replay buffer (F-014): every broadcast event gets a seq id the clients resume from. Written and read with raw SQL in services/ws_bus.py (hot path, no ORM). The model exists so the table is part of the Alembic-managed schema. - sqlite_autoincrement: ids must never be reused after old rows are pruned, or a client's cursor could skip events. - created_at is a UTCDateTime; ws_bus writes it with core.timeutil.to_db_str() so the raw-SQL text matches what the type stores (prune compares the text). """ from sqlalchemy import Column, Integer, String, Text from core.timeutil import UTCDateTime from database import Base class SyncEvent(Base): __tablename__ = "sync_events" __table_args__ = {"sqlite_autoincrement": True} id = Column(Integer, primary_key=True) event_type = Column(String, nullable=False) payload = Column(Text, nullable=False) target_user_ids = Column(Text, nullable=True) # JSON list; NULL = not addressed to users target_device_ids = Column(Text, nullable=True) # JSON list of devices (plan 3.1a); NULL = none created_at = Column(UTCDateTime, nullable=False, index=True)