SurfSense/surfsense_backend/app/file_storage/persistence/models.py
CREDO23 c6d4e5df7c refactor(db): rename searchspaces table to workspaces
Phase 1 (rename DB) commit 1i: rename the SearchSpace table to workspaces
and flip all 24 inbound FK target strings (20 in db.py + the 4 satellite
models), plus the raw-SQL searchspaces references in the obsidian and
google-unification integration fixtures.

This completes the ORM half of Phase 1. The SearchSpace class name,
relationship/back_populates attribute names, and the /searchspaces API
route URLs are intentionally left for Phase 2.

Verified: unit 2375 passed/1 skip, integration 346 passed (baseline
parity); create_all builds every table with the workspaces name and all
FKs resolving to workspaces.id.
2026-06-26 13:27:16 +02:00

67 lines
1.8 KiB
Python

"""``document_files`` table: durable blobs associated with a document."""
from __future__ import annotations
from sqlalchemy import (
BigInteger,
Column,
Enum as SQLAlchemyEnum,
ForeignKey,
Integer,
String,
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.db import BaseModel, TimestampMixin
from .enums import DocumentFileKind
class DocumentFile(BaseModel, TimestampMixin):
"""One stored file for a document (its original upload, or a derived copy)."""
__tablename__ = "document_files"
document_id = Column(
Integer,
ForeignKey("documents.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
search_space_id = Column(
"workspace_id",
Integer,
ForeignKey("workspaces.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
kind = Column(
SQLAlchemyEnum(
DocumentFileKind,
name="document_file_kind",
values_callable=lambda x: [e.value for e in x],
),
nullable=False,
default=DocumentFileKind.ORIGINAL,
server_default=DocumentFileKind.ORIGINAL.value,
index=True,
)
# Where the bytes live: the backend that stored them and its object key.
storage_backend = Column(String(32), nullable=False)
storage_key = Column(String, nullable=False)
original_filename = Column(String, nullable=False)
mime_type = Column(String, nullable=True)
size_bytes = Column(BigInteger, nullable=False)
checksum_sha256 = Column(String(64), nullable=True)
created_by_id = Column(
UUID(as_uuid=True),
ForeignKey("user.id", ondelete="SET NULL"),
nullable=True,
index=True,
)
document = relationship("Document", back_populates="files")