2026-05-27 11:45:04 +02:00
|
|
|
"""``automation_runs`` table — immutable per-fire execution record."""
|
feat(automation): add SQLAlchemy models for the three v1 tables
Three enums (one file each) plus three models (one file each), all
under app/automations/persistence/. The module imports from app.db
only (Base/BaseModel/TimestampMixin and FK targets searchspaces.id /
user.id); no business-logic imports.
Enums:
- AutomationStatus: active | paused | archived
- RunStatus: pending | running | succeeded | failed | cancelled
| timed_out
- TriggerType: schedule | manual (Phase-2/3 add webhook | event)
Models:
- Automation: search_space-scoped, created_by_user_id (SET NULL),
name + description, status enum, definition JSONB, version int,
updated_at with onupdate.
- AutomationTrigger: FK → automations (CASCADE), type enum, config
JSONB, enabled bool, last_fired_at. Webhook secret_hash is omitted
until Phase 2.
- AutomationRun: FK → automations (CASCADE), nullable trigger_id
(SET NULL — null = manual via UI), status enum,
definition_snapshot for immutable history, trigger_payload /
resolved_inputs / step_results / output / artifacts / error JSONB
columns, started_at / finished_at timestamps, agent_session_id for
linking to the LangGraph trace. cost_usd column omitted until at
least one v1 capability records token-level cost.
Verified: Base.metadata exposes all three table names; columns and
enums introspect as documented; no linter errors.
2026-05-26 22:42:50 +02:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import (
|
|
|
|
|
TIMESTAMP,
|
|
|
|
|
Column,
|
|
|
|
|
Enum as SQLAlchemyEnum,
|
|
|
|
|
ForeignKey,
|
|
|
|
|
Integer,
|
|
|
|
|
)
|
|
|
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
|
|
|
|
|
|
|
|
from app.db import BaseModel, TimestampMixin
|
|
|
|
|
|
|
|
|
|
from ..enums.run_status import RunStatus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AutomationRun(BaseModel, TimestampMixin):
|
|
|
|
|
__tablename__ = "automation_runs"
|
|
|
|
|
|
|
|
|
|
automation_id = Column(
|
|
|
|
|
Integer,
|
|
|
|
|
ForeignKey("automations.id", ondelete="CASCADE"),
|
|
|
|
|
nullable=False,
|
|
|
|
|
index=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
trigger_id = Column(
|
|
|
|
|
Integer,
|
|
|
|
|
ForeignKey("automation_triggers.id", ondelete="SET NULL"),
|
|
|
|
|
nullable=True,
|
|
|
|
|
index=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
status = Column(
|
|
|
|
|
SQLAlchemyEnum(RunStatus, name="automation_run_status"),
|
|
|
|
|
nullable=False,
|
|
|
|
|
default=RunStatus.PENDING,
|
|
|
|
|
server_default=RunStatus.PENDING.value,
|
|
|
|
|
index=True,
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-26 23:01:22 +02:00
|
|
|
# locked at fire time so historical runs always show the exact code path
|
feat(automation): add SQLAlchemy models for the three v1 tables
Three enums (one file each) plus three models (one file each), all
under app/automations/persistence/. The module imports from app.db
only (Base/BaseModel/TimestampMixin and FK targets searchspaces.id /
user.id); no business-logic imports.
Enums:
- AutomationStatus: active | paused | archived
- RunStatus: pending | running | succeeded | failed | cancelled
| timed_out
- TriggerType: schedule | manual (Phase-2/3 add webhook | event)
Models:
- Automation: search_space-scoped, created_by_user_id (SET NULL),
name + description, status enum, definition JSONB, version int,
updated_at with onupdate.
- AutomationTrigger: FK → automations (CASCADE), type enum, config
JSONB, enabled bool, last_fired_at. Webhook secret_hash is omitted
until Phase 2.
- AutomationRun: FK → automations (CASCADE), nullable trigger_id
(SET NULL — null = manual via UI), status enum,
definition_snapshot for immutable history, trigger_payload /
resolved_inputs / step_results / output / artifacts / error JSONB
columns, started_at / finished_at timestamps, agent_session_id for
linking to the LangGraph trace. cost_usd column omitted until at
least one v1 capability records token-level cost.
Verified: Base.metadata exposes all three table names; columns and
enums introspect as documented; no linter errors.
2026-05-26 22:42:50 +02:00
|
|
|
definition_snapshot = Column(JSONB, nullable=False)
|
|
|
|
|
|
|
|
|
|
trigger_payload = Column(JSONB, nullable=True)
|
|
|
|
|
resolved_inputs = Column(JSONB, nullable=False, server_default="{}")
|
2026-05-27 11:45:04 +02:00
|
|
|
# one entry per executed step; agent_task entries carry their own
|
|
|
|
|
# `agent_session_id` (LangGraph thread reference) inside this JSONB
|
feat(automation): add SQLAlchemy models for the three v1 tables
Three enums (one file each) plus three models (one file each), all
under app/automations/persistence/. The module imports from app.db
only (Base/BaseModel/TimestampMixin and FK targets searchspaces.id /
user.id); no business-logic imports.
Enums:
- AutomationStatus: active | paused | archived
- RunStatus: pending | running | succeeded | failed | cancelled
| timed_out
- TriggerType: schedule | manual (Phase-2/3 add webhook | event)
Models:
- Automation: search_space-scoped, created_by_user_id (SET NULL),
name + description, status enum, definition JSONB, version int,
updated_at with onupdate.
- AutomationTrigger: FK → automations (CASCADE), type enum, config
JSONB, enabled bool, last_fired_at. Webhook secret_hash is omitted
until Phase 2.
- AutomationRun: FK → automations (CASCADE), nullable trigger_id
(SET NULL — null = manual via UI), status enum,
definition_snapshot for immutable history, trigger_payload /
resolved_inputs / step_results / output / artifacts / error JSONB
columns, started_at / finished_at timestamps, agent_session_id for
linking to the LangGraph trace. cost_usd column omitted until at
least one v1 capability records token-level cost.
Verified: Base.metadata exposes all three table names; columns and
enums introspect as documented; no linter errors.
2026-05-26 22:42:50 +02:00
|
|
|
step_results = Column(JSONB, nullable=False, server_default="[]")
|
|
|
|
|
output = Column(JSONB, nullable=True)
|
|
|
|
|
artifacts = Column(JSONB, nullable=False, server_default="[]")
|
|
|
|
|
error = Column(JSONB, nullable=True)
|
|
|
|
|
|
|
|
|
|
started_at = Column(TIMESTAMP(timezone=True), nullable=True)
|
|
|
|
|
finished_at = Column(TIMESTAMP(timezone=True), nullable=True)
|