-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdocument.py
More file actions
124 lines (101 loc) · 3.89 KB
/
document.py
File metadata and controls
124 lines (101 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from datetime import datetime
from typing import Any
from uuid import UUID, uuid4
from pydantic import model_serializer
from sqlmodel import Field, SQLModel
from app.core.util import now
from app.models.doc_transformation_job import TransformationStatus
class DocumentBase(SQLModel):
"""Base model for documents with common fields."""
fname: str = Field(
description="The original filename of the document",
sa_column_kwargs={"comment": "Original filename of the document"},
)
# Foreign keys
project_id: int = Field(
description="The ID of the project to which the document belongs",
foreign_key="project.id",
nullable=False,
ondelete="CASCADE",
sa_column_kwargs={"comment": "Reference to the project"},
)
class Document(DocumentBase, table=True):
"""Database model for documents."""
id: UUID = Field(
default_factory=uuid4,
primary_key=True,
description="The unique identifier of the document",
sa_column_kwargs={"comment": "Unique identifier for the document"},
)
object_store_url: str = Field(
sa_column_kwargs={"comment": "Cloud storage URL for the document"},
)
is_deleted: bool = Field(
default=False,
sa_column_kwargs={"comment": "Soft delete flag"},
)
file_size: int | None = Field(
default=None,
description="The size of the document in bytes",
sa_column_kwargs={"comment": "Size of the document in bytes"},
)
# Foreign keys
source_document_id: UUID | None = Field(
default=None,
foreign_key="document.id",
nullable=True,
sa_column_kwargs={
"comment": "Reference to source document if this is a transformation"
},
)
# Timestamps
inserted_at: datetime = Field(
default_factory=now,
description="The timestamp when the document was inserted",
sa_column_kwargs={"comment": "Timestamp when the document was uploaded"},
)
updated_at: datetime = Field(
default_factory=now,
description="The timestamp when the document was last updated",
sa_column_kwargs={"comment": "Timestamp when the document was last updated"},
)
deleted_at: datetime | None = Field(
default=None,
sa_column_kwargs={"comment": "Timestamp when the document was deleted"},
)
class DocumentPublic(DocumentBase):
id: UUID = Field(description="The unique identifier of the document")
signed_url: str | None = Field(
default=None, description="A signed URL for accessing the document"
)
inserted_at: datetime = Field(
description="The timestamp when the document was inserted"
)
updated_at: datetime = Field(
description="The timestamp when the document was last updated"
)
class TransformedDocumentPublic(DocumentPublic):
source_document_id: UUID | None = Field(
default=None,
description="The ID of the source document if this document is a transformation",
)
class TransformationJobInfo(SQLModel):
message: str
job_id: UUID = Field(description="The unique identifier of the transformation job")
status: TransformationStatus
transformer: str = Field(description="The name of the transformer used")
status_check_url: str = Field(
description="The URL to check the status of the transformation job"
)
class DocumentUploadResponse(DocumentPublic):
signed_url: str = Field(description="A signed URL for accessing the document")
transformation_job: TransformationJobInfo | None = None
class DocTransformationJobPublic(SQLModel):
job_id: UUID
source_document_id: UUID
status: TransformationStatus
transformed_document: TransformedDocumentPublic | None = None
error_message: str | None = None
class DocTransformationJobsPublic(SQLModel):
jobs: list[DocTransformationJobPublic]
jobs_not_found: list[UUID]