| """ |
| In-app notification models |
| """ |
| from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Text |
| from sqlalchemy.orm import relationship |
| from sqlalchemy.sql import func |
|
|
| from database import Base |
|
|
|
|
| class Notification(Base): |
| __tablename__ = "notifications" |
|
|
| id = Column(Integer, primary_key=True, index=True) |
| user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True) |
| kind = Column(String(20), nullable=False, default="info") |
| title = Column(String(150), nullable=False) |
| message = Column(Text, nullable=False) |
| link_path = Column(String(255), nullable=True) |
| entity_type = Column(String(50), nullable=True) |
| entity_id = Column(Integer, nullable=True) |
| is_read = Column(Boolean, default=False, nullable=False) |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) |
| read_at = Column(DateTime(timezone=True), nullable=True) |
|
|
| user = relationship("User", back_populates="notifications") |
|
|