fix queue

This commit is contained in:
javad committed 2026-09-11 18:04:51 +03:30
1 parent 049cc41afc
commit 9a1c99cbd3
14 files changed
+237 -32

No files matched your search

@@ -8,10 +8,12 @@ from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError
from django.db import connection, transaction
from django.db.models import F
from apps.accounts.models import User
from apps.core.models import ProductionSeedState
from apps.core.production_seed import sha256_file
from apps.tickets.models import Ticket
class Command(BaseCommand):
@@ -82,6 +84,27 @@ class Command(BaseCommand):
# the authoritative SQLite snapshot; schema/migration history remains.
call_command("flush", interactive=False, verbosity=0)
call_command("loaddata", str(bundle_dir / "data.json.gz"), verbosity=1)
# Old SQLite snapshots may predate unit-scoped queues. A
# category already belongs to exactly one unit, so it is a
# deterministic and safe source for repairing those rows.
repaired = []
for ticket in Ticket.objects.filter(
owning_unit__isnull=True,
category__unit__isnull=False,
).select_related("category"):
ticket.owning_unit_id = ticket.category.unit_id
repaired.append(ticket)
if repaired:
Ticket.objects.bulk_update(repaired, ["owning_unit"])
Ticket.objects.filter(
assigned_unit__isnull=True,
owning_unit__isnull=False,
).update(assigned_unit_id=F("owning_unit_id"))
if Ticket.objects.filter(owning_unit__isnull=True).exists():
raise CommandError(
"Seed contains tickets without an organizational unit; "
"assign their categories to units before exporting again."
)
media_root.mkdir(parents=True, exist_ok=True)
for source in sorted(staged_media.rglob("*")):
if not source.is_file():