cf7c29639c
Backend: config/db/security/logging core, SQLAlchemy models (Server, Credential, UpdateJob, UpdateLog, AuditLog, User), services (winrm, ssh, cau, audit, job_runner), REST API (auth, servers, updates, audit), Socket.io WebSocket layer. Frontend: Vue 3 + TS + Pinia + Tailwind, Views (Dashboard, Servers, Updates, Audit, Login), axios + socket.io-client, nginx prod config.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""Update job + streamed log line models."""
|
|
|
|
import enum
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class JobStatus(str, enum.Enum):
|
|
PENDING = "pending"
|
|
RUNNING = "running"
|
|
SUCCESS = "success"
|
|
FAILED = "failed"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class JobType(str, enum.Enum):
|
|
WINDOWS_UPDATE = "windows_update"
|
|
LINUX_UPDATE = "linux_update"
|
|
CAU_RUN = "cau_run"
|
|
HEALTH_CHECK = "health_check"
|
|
|
|
|
|
class UpdateJob(Base):
|
|
__tablename__ = "update_jobs"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
server_id: Mapped[int] = mapped_column(ForeignKey("servers.id"), index=True)
|
|
server: Mapped["Server"] = relationship(back_populates="jobs", lazy="selectin") # noqa: F821
|
|
|
|
type: Mapped[JobType] = mapped_column(Enum(JobType))
|
|
status: Mapped[JobStatus] = mapped_column(Enum(JobStatus), default=JobStatus.PENDING, index=True)
|
|
progress_percent: Mapped[int] = mapped_column(Integer, default=0)
|
|
current_phase: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
|
|
started_by: Mapped[str] = mapped_column(String(255)) # username
|
|
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
error: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(UTC)
|
|
)
|
|
|
|
logs: Mapped[list["UpdateLog"]] = relationship(
|
|
back_populates="job", cascade="all, delete-orphan", order_by="UpdateLog.id"
|
|
)
|
|
|
|
|
|
class UpdateLog(Base):
|
|
__tablename__ = "update_logs"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
job_id: Mapped[int] = mapped_column(ForeignKey("update_jobs.id"), index=True)
|
|
job: Mapped[UpdateJob] = relationship(back_populates="logs")
|
|
|
|
timestamp: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(UTC)
|
|
)
|
|
level: Mapped[str] = mapped_column(String(20), default="info")
|
|
line: Mapped[str] = mapped_column(Text)
|