- Replace default=datetime.utcnow with server_default=func.now() across all 16 models (17 columns) for consistent, timezone-aware timestamps from PostgreSQL - Upgrade DateTime columns to DateTime(timezone=True) for timestamptz storage - Configure SQLAlchemy engine pool: pool_size=20, max_overflow=10, pool_recycle=3600, pool_pre_ping=True - Remove unused datetime imports from model files
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Notification model — in-app notifications for user actions."""
|
|
|
|
import uuid
|
|
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, Index, func
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Notification(Base):
|
|
"""
|
|
In-app notification for alerting users when they need to act.
|
|
|
|
Types include: test_assigned, validation_needed, test_rejected,
|
|
test_validated, test_state_changed, etc.
|
|
"""
|
|
__tablename__ = "notifications"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
|
type = Column(String, nullable=False)
|
|
title = Column(String, nullable=False)
|
|
message = Column(Text, nullable=True)
|
|
entity_type = Column(String, nullable=True)
|
|
entity_id = Column(UUID(as_uuid=True), nullable=True)
|
|
read = Column(Boolean, default=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Relationships
|
|
user = relationship("User")
|
|
|
|
__table_args__ = (
|
|
Index("ix_notifications_user_id", "user_id"),
|
|
Index("ix_notifications_read", "read"),
|
|
Index("ix_notifications_created_at", "created_at"),
|
|
)
|