Bruno Charest c3cd7c2621
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 initial Homelab Automation API v2 with new models, routes, and core architecture, including a SQLAlchemy model refactoring script.
2026-03-03 20:18:22 -05:00

37 lines
1.5 KiB
Python

from __future__ import annotations
from datetime import datetime
from typing import Optional
from sqlalchemy import DateTime, ForeignKey, Integer, JSON, String, Text, Index
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from .database import Base
class Alert(Base):
__tablename__ = "alerts"
__table_args__ = (
Index("idx_alerts_created_at", "created_at"),
Index("idx_alerts_user_id", "user_id"),
Index("idx_alerts_category", "category"),
Index("idx_alerts_read_at", "read_at"),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
category: Mapped[str] = mapped_column(String(50), nullable=False)
level: Mapped[str] = mapped_column(String(20), nullable=True)
title: Mapped[str] = mapped_column(String(255), nullable=True)
message: Mapped[str] = mapped_column(Text, nullable=False)
source: Mapped[str] = mapped_column(String(50), nullable=True)
details: Mapped[dict] = mapped_column(JSON, nullable=True)
read_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
def __repr__(self) -> str:
return f"<Alert id={self.id} category={self.category} user_id={self.user_id} read={self.read_at is not None}>"