fix(migrations): correct listCollections cursor parsing, add processing_failed+cancelled to status enum
Previous migrations used async-for on a dict (Atlas returns firstBatch, not async cursor) — silently failed. New migration reads firstBatch correctly and sets the complete status list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8a1440201e
commit
43ef3a6cd8
1 changed files with 47 additions and 0 deletions
|
|
@ -0,0 +1,47 @@
|
|||
"""Replace status enum in $jsonSchema validator with the full current list."""
|
||||
from app.migrations.migrator import Migration
|
||||
|
||||
ALL_STATUSES = [
|
||||
"created", "ingesting", "ai_processing",
|
||||
"pending_qc", "approved_english", "approved_source",
|
||||
"rejected", "qc_feedback",
|
||||
"translating", "tts_generating", "tts_failed",
|
||||
"rendering_video", "render_failed", "rendering_qc",
|
||||
"pending_final_review", "completed",
|
||||
"processing_failed", "cancelled",
|
||||
]
|
||||
|
||||
|
||||
class Migration(Migration):
|
||||
version = "2026-04-30-000002"
|
||||
description = "Fix status enum in jobs $jsonSchema validator (add processing_failed + cancelled)"
|
||||
|
||||
async def up(self) -> None:
|
||||
db = self.db
|
||||
|
||||
result = await db.command("listCollections", filter={"name": "jobs"})
|
||||
batch = result.get("cursor", {}).get("firstBatch", [])
|
||||
if not batch:
|
||||
return
|
||||
|
||||
existing_validator = batch[0].get("options", {}).get("validator")
|
||||
if not existing_validator:
|
||||
return
|
||||
|
||||
schema = existing_validator.get("$jsonSchema", {})
|
||||
status_prop = schema.get("properties", {}).get("status")
|
||||
if not status_prop:
|
||||
return
|
||||
|
||||
status_prop["enum"] = ALL_STATUSES
|
||||
|
||||
await db.command(
|
||||
"collMod",
|
||||
"jobs",
|
||||
validator=existing_validator,
|
||||
validationLevel="moderate",
|
||||
validationAction="error",
|
||||
)
|
||||
|
||||
async def down(self) -> None:
|
||||
pass
|
||||
Loading…
Add table
Reference in a new issue