62 lines
3.1 KiB
Python
62 lines
3.1 KiB
Python
from datetime import date, datetime
|
|
from typing import Optional
|
|
from sqlalchemy import Date, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from .base import Base
|
|
from ..core.time_utils import utc_now
|
|
|
|
|
|
class Attachment(Base):
|
|
__tablename__ = "attachments"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
entity_type: Mapped[str] = mapped_column(String(60), nullable=False)
|
|
entity_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
original_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
stored_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
mime_type: Mapped[str] = mapped_column(String(120), nullable=False)
|
|
size_bytes: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
uploaded_by_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
|
uploaded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, nullable=False)
|
|
|
|
|
|
class Notification(Base):
|
|
__tablename__ = "notifications"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
type: Mapped[str] = mapped_column(String(60), nullable=False)
|
|
severity: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
message: Mapped[str] = mapped_column(Text, nullable=False)
|
|
entity_type: Mapped[str] = mapped_column(String(60), nullable=False)
|
|
entity_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
due_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
|
target_role: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
|
target_user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
|
dedupe_key: Mapped[str] = mapped_column(String(200), unique=True, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, nullable=False)
|
|
|
|
|
|
class NotificationRead(Base):
|
|
__tablename__ = "notification_reads"
|
|
__table_args__ = (
|
|
UniqueConstraint("notification_id", "user_id", name="uq_notification_user_read"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
notification_id: Mapped[int] = mapped_column(ForeignKey("notifications.id"), nullable=False)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
|
read_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, nullable=False)
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
entity_type: Mapped[str] = mapped_column(String(60), nullable=False)
|
|
entity_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
action: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
changes_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
by_user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
|
at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, nullable=False)
|