Files
agentic-mobile-control/packages/cloud-platform/cloud/db_models.py
T

78 lines
3.3 KiB
Python

from __future__ import annotations
from sqlalchemy import Integer, String, Text, text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class HostRow(Base):
__tablename__ = "host_registrations"
host_id: Mapped[str] = mapped_column(String, primary_key=True)
address: Mapped[str | None] = mapped_column(String, nullable=True)
last_seen_at: Mapped[str] = mapped_column(String, nullable=False)
class PooledDeviceRow(Base):
__tablename__ = "pooled_devices"
host_id: Mapped[str] = mapped_column(String, primary_key=True)
device_id: Mapped[str] = mapped_column(String, primary_key=True)
driver_type: Mapped[str] = mapped_column(String, nullable=False)
status: Mapped[str] = mapped_column(String, nullable=False)
capability_tags_json: Mapped[str] = mapped_column(Text, nullable=False)
synced_at: Mapped[str | None] = mapped_column(String, nullable=True)
class ScheduledTaskRow(Base):
__tablename__ = "scheduled_tasks"
id: Mapped[str] = mapped_column(String, primary_key=True)
goal: Mapped[str | None] = mapped_column(Text, nullable=True)
workflow_definition_id: Mapped[str | None] = mapped_column(String, nullable=True)
constraints_json: Mapped[str] = mapped_column(Text, nullable=False)
status: Mapped[str] = mapped_column(String, nullable=False)
assigned_device_id: Mapped[str | None] = mapped_column(String, nullable=True)
assigned_host_id: Mapped[str | None] = mapped_column(String, nullable=True)
attempt_count: Mapped[int] = mapped_column(
Integer,
nullable=False,
default=0,
server_default=text("0"),
)
lease_id: Mapped[str | None] = mapped_column(String, nullable=True)
lease_expires_at: Mapped[str | None] = mapped_column(String, nullable=True)
failure_reason: Mapped[str | None] = mapped_column(Text, nullable=True)
result_json: Mapped[str | None] = mapped_column(Text, nullable=True)
updated_at: Mapped[str | None] = mapped_column(String, nullable=True)
created_at: Mapped[str] = mapped_column(String, nullable=False)
class TaskAttemptRow(Base):
__tablename__ = "task_attempts"
task_id: Mapped[str] = mapped_column(String, primary_key=True)
attempt: Mapped[int] = mapped_column(Integer, primary_key=True)
lease_id: Mapped[str] = mapped_column(String, nullable=False)
host_id: Mapped[str] = mapped_column(String, nullable=False)
device_id: Mapped[str] = mapped_column(String, nullable=False)
status: Mapped[str] = mapped_column(String, nullable=False)
lease_expires_at: Mapped[str] = mapped_column(String, nullable=False)
created_at: Mapped[str] = mapped_column(String, nullable=False)
completed_at: Mapped[str | None] = mapped_column(String, nullable=True)
failure_reason: Mapped[str | None] = mapped_column(Text, nullable=True)
result_json: Mapped[str | None] = mapped_column(Text, nullable=True)
class PluginRow(Base):
__tablename__ = "plugins"
name: Mapped[str] = mapped_column(String, primary_key=True)
version: Mapped[str] = mapped_column(String, nullable=False)
entry_point_kind: Mapped[str] = mapped_column(String, nullable=False)
target: Mapped[str] = mapped_column(String, nullable=False)
wired: Mapped[int] = mapped_column(Integer, nullable=False)