e4e2595e70
- adapters: SQLAlchemy implementations for all 4 repositories (Project, AssetLibrary, Asset, IngestJob) - models: SQLAlchemy ORM models with proper schema - database: connection config and session management - tests: SQLAlchemy repository integration test (in-memory SQLite) - all 7 integration tests passing
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
from sqlalchemy.orm import Session
|
|
|
|
from packages.domain import IngestJob, IngestJobStatus
|
|
from packages.adapters.sqlalchemy_impl.models import IngestJobModel
|
|
|
|
|
|
class SQLAlchemyIngestJobRepository:
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def create(self, job: IngestJob) -> IngestJob:
|
|
model = IngestJobModel(
|
|
id=job.id,
|
|
workspace_id=job.workspace_id,
|
|
project_id=job.project_id,
|
|
library_id=job.library_id,
|
|
storage_key=job.storage_key,
|
|
status=job.status.value,
|
|
error_message=job.error_message,
|
|
result_asset_id=job.result_asset_id,
|
|
created_at=job.created_at,
|
|
updated_at=job.updated_at,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
return job
|
|
|
|
def get(self, job_id: str) -> IngestJob | None:
|
|
model = self.session.query(IngestJobModel).filter(IngestJobModel.id == job_id).first()
|
|
if model is None:
|
|
return None
|
|
return IngestJob(
|
|
id=model.id,
|
|
workspace_id=model.workspace_id,
|
|
project_id=model.project_id,
|
|
library_id=model.library_id,
|
|
storage_key=model.storage_key,
|
|
status=IngestJobStatus(model.status),
|
|
error_message=model.error_message,
|
|
result_asset_id=model.result_asset_id,
|
|
created_at=model.created_at,
|
|
updated_at=model.updated_at,
|
|
)
|
|
|
|
def update(self, job: IngestJob) -> IngestJob:
|
|
model = self.session.query(IngestJobModel).filter(IngestJobModel.id == job.id).first()
|
|
if model is None:
|
|
raise ValueError(f"IngestJob {job.id} not found")
|
|
model.status = job.status.value
|
|
model.error_message = job.error_message
|
|
model.result_asset_id = job.result_asset_id
|
|
model.updated_at = job.updated_at
|
|
self.session.commit()
|
|
return job
|