style: normalize python formatting gates
This commit is contained in:
@@ -7,7 +7,13 @@ from .generated_video_repository import SQLAlchemyGeneratedVideoRepository
|
||||
from .generation_task_repository import SQLAlchemyGenerationTaskRepository
|
||||
from .ingest_job_repository import SQLAlchemyIngestJobRepository
|
||||
from .project_repository import SQLAlchemyProjectRepository
|
||||
from .session import Base, build_engine, build_session_factory, ensure_database_exists, initialize_database
|
||||
from .session import (
|
||||
Base,
|
||||
build_engine,
|
||||
build_session_factory,
|
||||
ensure_database_exists,
|
||||
initialize_database,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
|
||||
@@ -29,7 +29,7 @@ class SQLAlchemyAssetRepository:
|
||||
project_id=asset.project_id,
|
||||
asset_library_id=asset.library_id,
|
||||
name=asset.name,
|
||||
file_type=asset.mime_type.split('/')[0] if '/' in asset.mime_type else asset.mime_type,
|
||||
file_type=(asset.mime_type.split("/")[0] if "/" in asset.mime_type else asset.mime_type),
|
||||
file_size=asset.file_size,
|
||||
file_url=asset.storage_key,
|
||||
thumbnail_url=asset.thumbnail_url,
|
||||
@@ -40,9 +40,9 @@ class SQLAlchemyAssetRepository:
|
||||
codec=asset.codec,
|
||||
status=asset.status.value,
|
||||
classification_status=asset.classification_status.value,
|
||||
classification_result=json.dumps(asset.metadata) if asset.metadata else None,
|
||||
classification_result=(json.dumps(asset.metadata) if asset.metadata else None),
|
||||
quality_score=asset.quality_score,
|
||||
uploaded_by_user_id=asset.uploaded_by_user_id or 'system',
|
||||
uploaded_by_user_id=asset.uploaded_by_user_id or "system",
|
||||
created_at=asset.created_at,
|
||||
updated_at=now,
|
||||
)
|
||||
@@ -80,11 +80,11 @@ class SQLAlchemyAssetRepository:
|
||||
except Exception:
|
||||
metadata = {}
|
||||
mime_type = model.file_type
|
||||
if '/' not in mime_type:
|
||||
if "/" not in mime_type:
|
||||
mime_type = {
|
||||
'video': 'video/mp4',
|
||||
'audio': 'audio/mpeg',
|
||||
'image': 'image/jpeg',
|
||||
"video": "video/mp4",
|
||||
"audio": "audio/mpeg",
|
||||
"image": "image/jpeg",
|
||||
}.get(mime_type, mime_type)
|
||||
return Asset(
|
||||
id=model.id,
|
||||
|
||||
@@ -55,5 +55,9 @@ class SQLAlchemyGeneratedVideoRepository:
|
||||
return [self.get(model.id) for model in models if self.get(model.id) is not None]
|
||||
|
||||
def list_by_generation_task(self, generation_task_id: str) -> list[GeneratedVideo]:
|
||||
models = self.session.query(GeneratedVideoModel).filter(GeneratedVideoModel.generation_task_id == generation_task_id).all()
|
||||
models = (
|
||||
self.session.query(GeneratedVideoModel)
|
||||
.filter(GeneratedVideoModel.generation_task_id == generation_task_id)
|
||||
.all()
|
||||
)
|
||||
return [self.get(model.id) for model in models if self.get(model.id) is not None]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, Float, String, Text, create_engine
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from datetime import datetime, timezone
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""项目管理 SQLAlchemy Repository 实现"""
|
||||
|
||||
import json
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from packages.domain import Milestone, Task, TaskIssue
|
||||
@@ -8,6 +10,7 @@ from packages.ports.project_management_repositories import (
|
||||
TaskIssueRepository,
|
||||
TaskRepository,
|
||||
)
|
||||
|
||||
from .models import MilestoneModel, TaskIssueModel, TaskModel
|
||||
|
||||
|
||||
@@ -59,7 +62,7 @@ class SQLAlchemyTaskRepository(TaskRepository):
|
||||
model = self._session.query(TaskModel).filter(TaskModel.id == task.id).first()
|
||||
if not model:
|
||||
raise ValueError(f"Task {task.id} not found")
|
||||
|
||||
|
||||
model.name = task.name
|
||||
model.description = task.description
|
||||
model.status = task.status.value
|
||||
@@ -73,7 +76,7 @@ class SQLAlchemyTaskRepository(TaskRepository):
|
||||
model.actual_end_date = task.actual_end_date
|
||||
model.tags_json = json.dumps(task.tags, ensure_ascii=False)
|
||||
model.updated_at = task.updated_at
|
||||
|
||||
|
||||
self._session.commit()
|
||||
return task
|
||||
|
||||
@@ -83,6 +86,7 @@ class SQLAlchemyTaskRepository(TaskRepository):
|
||||
|
||||
def _model_to_entity(self, model: TaskModel) -> Task:
|
||||
from packages.domain.project_management import TaskPriority, TaskStatus
|
||||
|
||||
return Task(
|
||||
id=model.id,
|
||||
project_id=model.project_id,
|
||||
@@ -141,14 +145,14 @@ class SQLAlchemyMilestoneRepository(MilestoneRepository):
|
||||
model = self._session.query(MilestoneModel).filter(MilestoneModel.id == milestone.id).first()
|
||||
if not model:
|
||||
raise ValueError(f"Milestone {milestone.id} not found")
|
||||
|
||||
|
||||
model.name = milestone.name
|
||||
model.description = milestone.description
|
||||
model.target_date = milestone.target_date
|
||||
model.completed = milestone.completed
|
||||
model.completed_at = milestone.completed_at
|
||||
model.updated_at = milestone.updated_at
|
||||
|
||||
|
||||
self._session.commit()
|
||||
return milestone
|
||||
|
||||
@@ -213,13 +217,13 @@ class SQLAlchemyTaskIssueRepository(TaskIssueRepository):
|
||||
model = self._session.query(TaskIssueModel).filter(TaskIssueModel.id == issue.id).first()
|
||||
if not model:
|
||||
raise ValueError(f"TaskIssue {issue.id} not found")
|
||||
|
||||
|
||||
model.title = issue.title
|
||||
model.description = issue.description
|
||||
model.resolved = issue.resolved
|
||||
model.resolved_at = issue.resolved_at
|
||||
model.updated_at = issue.updated_at
|
||||
|
||||
|
||||
self._session.commit()
|
||||
return issue
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from packages.adapters.sqlalchemy_impl.models import Base
|
||||
|
||||
|
||||
SCHEMA_INIT_LOCK_ID = 2026061501
|
||||
SessionLocal = None
|
||||
|
||||
@@ -77,5 +76,8 @@ def initialize_database(engine) -> None:
|
||||
Base.metadata.create_all(bind=connection)
|
||||
connection.commit()
|
||||
finally:
|
||||
connection.execute(text("SELECT pg_advisory_unlock(:lock_id)"), {"lock_id": SCHEMA_INIT_LOCK_ID})
|
||||
connection.execute(
|
||||
text("SELECT pg_advisory_unlock(:lock_id)"),
|
||||
{"lock_id": SCHEMA_INIT_LOCK_ID},
|
||||
)
|
||||
connection.commit()
|
||||
|
||||
Reference in New Issue
Block a user