homelab_automation/app/models/schedule_run.py
Bruno Charest 817f8b4ee7
Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
feat: Implement Homelab Automation API v2, introducing a new dashboard, comprehensive backend models, and API routes.
2026-03-06 09:31:08 -05:00

32 lines
1.6 KiB
Python

from datetime import datetime
from typing import Optional
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, Float
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func
from .database import Base
class ScheduleRun(Base):
__tablename__ = "schedule_runs"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
schedule_id: Mapped[str] = mapped_column(String(50), ForeignKey("schedules.id", ondelete="CASCADE"), nullable=False)
task_id: Mapped[str] = mapped_column(String(50), ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True)
status: Mapped[str] = mapped_column(String(50), nullable=False)
started_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
completed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=True)
duration: Mapped[float] = mapped_column(Float, nullable=True)
hosts_impacted: Mapped[int] = mapped_column(Integer, default=0, nullable=True)
error_message: Mapped[str] = mapped_column(Text, nullable=True)
output: Mapped[str] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
schedule: Mapped["Schedule"] = relationship("Schedule", back_populates="runs")
task: Mapped["Task"] = relationship("Task", back_populates="schedule_runs")
def __repr__(self) -> str: # pragma: no cover - debug helper
return f"<ScheduleRun id={self.id} schedule_id={self.schedule_id} status={self.status}>"