mirror of
https://github.com/bellingcat/whisperbox-transcribe.git
synced 2026-06-08 03:28:35 +03:00
refactor: restructure project layout
This commit is contained in:
50
app/shared/db/models.py
Normal file
50
app/shared/db/models.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import JSON, Column, DateTime, Enum, ForeignKey, String, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import Mapped, declarative_mixin, declared_attr
|
||||
|
||||
from .dtos import ArtifactType, JobStatus, JobType
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
@declarative_mixin
|
||||
class WithStandardFields:
|
||||
"""Mixin that adds standard fields (id, created_at, updated_at)."""
|
||||
|
||||
@declared_attr
|
||||
def created_at(cls) -> Mapped[DateTime]:
|
||||
return Column(DateTime, server_default=func.now(), nullable=False)
|
||||
|
||||
@declared_attr
|
||||
def updated_at(cls) -> Mapped[Optional[DateTime]]:
|
||||
return Column(DateTime, onupdate=func.now())
|
||||
|
||||
@declared_attr
|
||||
def id(cls) -> Mapped[UUID]:
|
||||
return Column(
|
||||
UUID(as_uuid=True), primary_key=True, index=True, default=uuid.uuid4
|
||||
)
|
||||
|
||||
|
||||
class Job(Base, WithStandardFields):
|
||||
__tablename__ = "jobs"
|
||||
|
||||
# TODO: job config
|
||||
url = Column(String(length=2048))
|
||||
status = Column(Enum(JobStatus), nullable=False)
|
||||
type = Column(Enum(JobType), nullable=False)
|
||||
|
||||
|
||||
class Artifact(Base, WithStandardFields):
|
||||
__tablename__ = "artifacts"
|
||||
|
||||
job_id = Column(
|
||||
UUID(as_uuid=True), ForeignKey("jobs.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
|
||||
data = Column(JSON(none_as_null=True))
|
||||
type = Column(Enum(ArtifactType), nullable=False)
|
||||
Reference in New Issue
Block a user