From d948b769ba8e205fd8816f2221ed224a8fcd3329 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 26 Jun 2026 18:20:28 +0200 Subject: [PATCH] refactor(db): rename search_space to workspace in satellite ORM models (Phase 2 Wave B) Flip search_space_id -> workspace_id and the workspace relationship/back_populates in the automations, file_storage, notifications, and podcasts persistence models, and drop the Phase 1 Column("workspace_id", ...) shim. Full SQLAlchemy mapper configuration now passes (db.py + satellites consistent). --- .../app/automations/persistence/models/automation.py | 5 ++--- surfsense_backend/app/file_storage/persistence/models.py | 3 +-- surfsense_backend/app/notifications/persistence/models.py | 5 ++--- surfsense_backend/app/podcasts/persistence/models.py | 5 ++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/surfsense_backend/app/automations/persistence/models/automation.py b/surfsense_backend/app/automations/persistence/models/automation.py index 76ba5e2e6..486a1ecea 100644 --- a/surfsense_backend/app/automations/persistence/models/automation.py +++ b/surfsense_backend/app/automations/persistence/models/automation.py @@ -24,8 +24,7 @@ from ..enums.automation_status import AutomationStatus class Automation(BaseModel, TimestampMixin): __tablename__ = "automations" - search_space_id = Column( - "workspace_id", + workspace_id = Column( Integer, ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, @@ -66,7 +65,7 @@ class Automation(BaseModel, TimestampMixin): index=True, ) - search_space = relationship("SearchSpace", back_populates="automations") + workspace = relationship("Workspace", back_populates="automations") created_by = relationship("User", back_populates="automations") triggers = relationship( "AutomationTrigger", diff --git a/surfsense_backend/app/file_storage/persistence/models.py b/surfsense_backend/app/file_storage/persistence/models.py index bc6cef07f..e16774f12 100644 --- a/surfsense_backend/app/file_storage/persistence/models.py +++ b/surfsense_backend/app/file_storage/persistence/models.py @@ -29,8 +29,7 @@ class DocumentFile(BaseModel, TimestampMixin): nullable=False, index=True, ) - search_space_id = Column( - "workspace_id", + workspace_id = Column( Integer, ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, diff --git a/surfsense_backend/app/notifications/persistence/models.py b/surfsense_backend/app/notifications/persistence/models.py index d75a9d8dc..ac5028207 100644 --- a/surfsense_backend/app/notifications/persistence/models.py +++ b/surfsense_backend/app/notifications/persistence/models.py @@ -47,8 +47,7 @@ class Notification(BaseModel, TimestampMixin): nullable=False, index=True, ) - search_space_id = Column( - "workspace_id", + workspace_id = Column( Integer, ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=True, @@ -70,4 +69,4 @@ class Notification(BaseModel, TimestampMixin): ) user = relationship("User", back_populates="notifications") - search_space = relationship("SearchSpace", back_populates="notifications") + workspace = relationship("Workspace", back_populates="notifications") diff --git a/surfsense_backend/app/podcasts/persistence/models.py b/surfsense_backend/app/podcasts/persistence/models.py index 559998d4e..2c7e2a6c2 100644 --- a/surfsense_backend/app/podcasts/persistence/models.py +++ b/surfsense_backend/app/podcasts/persistence/models.py @@ -68,13 +68,12 @@ class Podcast(BaseModel, TimestampMixin): # Legacy local audio path; retained for back-compat until cutover. file_location = Column(Text, nullable=True) - search_space_id = Column( - "workspace_id", + workspace_id = Column( Integer, ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, ) - search_space = relationship("SearchSpace", back_populates="podcasts") + workspace = relationship("Workspace", back_populates="podcasts") thread_id = Column( Integer,