From e5236d33a9d6804eb77a057d1cf197747ae2bef2 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 3 Jun 2026 18:04:47 +0200 Subject: [PATCH] refactor: move Notification model into notifications module --- surfsense_backend/app/db.py | 55 +------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/surfsense_backend/app/db.py b/surfsense_backend/app/db.py index 5be10427f..e49bdaaee 100644 --- a/surfsense_backend/app/db.py +++ b/surfsense_backend/app/db.py @@ -2060,60 +2060,6 @@ class Log(BaseModel, TimestampMixin): search_space = relationship("SearchSpace", back_populates="logs") -class Notification(BaseModel, TimestampMixin): - __tablename__ = "notifications" - __table_args__ = ( - # Composite index for unread-count queries that filter by - # (user_id, read, type) and order by created_at. - Index( - "ix_notifications_user_read_type_created", - "user_id", - "read", - "type", - "created_at", - ), - # Covers the common list query: user_id + search_space_id + created_at DESC - Index( - "ix_notifications_user_space_created", - "user_id", - "search_space_id", - "created_at", - ), - ) - - user_id = Column( - UUID(as_uuid=True), - ForeignKey("user.id", ondelete="CASCADE"), - nullable=False, - index=True, - ) - search_space_id = Column( - Integer, - ForeignKey("searchspaces.id", ondelete="CASCADE"), - nullable=True, - index=True, - ) - type = Column( - String(50), nullable=False, index=True - ) # 'connector_indexing', 'document_processing', etc. - title = Column(String(200), nullable=False) - message = Column(Text, nullable=False) - read = Column( - Boolean, nullable=False, default=False, server_default=text("false"), index=True - ) - notification_metadata = Column("metadata", JSONB, nullable=True, default={}) - updated_at = Column( - TIMESTAMP(timezone=True), - nullable=True, - default=lambda: datetime.now(UTC), - onupdate=lambda: datetime.now(UTC), - index=True, - ) - - user = relationship("User", back_populates="notifications") - search_space = relationship("SearchSpace", back_populates="notifications") - - class UserIncentiveTask(BaseModel, TimestampMixin): """ Tracks completed incentive tasks for users. @@ -2937,6 +2883,7 @@ from app.automations.persistence import ( # noqa: E402, F401 AutomationTrigger, ) from app.file_storage.persistence import DocumentFile # noqa: E402, F401 +from app.notifications.persistence import Notification # noqa: E402, F401 engine = create_async_engine( DATABASE_URL,