mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
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.
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
"""``AutomationTrigger`` table — one row per (automation, trigger-instance) pair."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import (
|
|
TIMESTAMP,
|
|
Boolean,
|
|
Column,
|
|
Enum as SQLAlchemyEnum,
|
|
ForeignKey,
|
|
Integer,
|
|
)
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
|
|
from app.db import BaseModel, TimestampMixin
|
|
|
|
from ..enums.trigger_type import TriggerType
|
|
|
|
|
|
class AutomationTrigger(BaseModel, TimestampMixin):
|
|
"""One trigger attached to an automation.
|
|
|
|
An automation may have multiple triggers — e.g. a ``schedule`` trigger
|
|
for the autonomous path and a ``manual`` trigger backing the UI's
|
|
"Run now" affordance. Each trigger's ``config`` is validated against
|
|
the registered ``TriggerDefinition.config_schema`` for its ``type``.
|
|
"""
|
|
|
|
__tablename__ = "automation_triggers"
|
|
|
|
automation_id = Column(
|
|
Integer,
|
|
ForeignKey("automations.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
type = Column(
|
|
SQLAlchemyEnum(TriggerType, name="automation_trigger_type"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
config = Column(JSONB, nullable=False)
|
|
|
|
enabled = Column(
|
|
Boolean,
|
|
nullable=False,
|
|
default=True,
|
|
server_default="true",
|
|
index=True,
|
|
)
|
|
|
|
last_fired_at = Column(
|
|
TIMESTAMP(timezone=True),
|
|
nullable=True,
|
|
)
|