38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import uuid
|
|
|
|
import django.db.models.deletion
|
|
from django.db import migrations, models
|
|
|
|
|
|
def delete_existing_submissions(apps, schema_editor):
|
|
"""Submissions predate Scope and can't be backfilled with one; wipe them."""
|
|
Submission = apps.get_model("submissions", "Submission")
|
|
Submission.objects.all().delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
# Deleting existing submissions (which cascades to their files/crops) fires
|
|
# deferred FK triggers on postgres; altering the same table right after in
|
|
# the same transaction hits "pending trigger events", so run non-atomically.
|
|
atomic = False
|
|
|
|
dependencies = [
|
|
("submissions", "0006_scope"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(delete_existing_submissions, migrations.RunPython.noop),
|
|
migrations.AddField(
|
|
model_name="submission",
|
|
name="scope",
|
|
field=models.ForeignKey(
|
|
default=uuid.uuid4,
|
|
help_text="The match this submission's score is for.",
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
related_name="submissions",
|
|
to="submissions.scope",
|
|
),
|
|
preserve_default=False,
|
|
),
|
|
]
|