From f75a1b0338f003181c47eb541b314887662ae27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gremaud?= Date: Fri, 23 Oct 2026 21:26:22 +0200 Subject: [PATCH] reset opus-magnum sequence --- .../migrations/0019_reset_sequences.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 polylan_submitter/opus_magnum/migrations/0019_reset_sequences.py diff --git a/polylan_submitter/opus_magnum/migrations/0019_reset_sequences.py b/polylan_submitter/opus_magnum/migrations/0019_reset_sequences.py new file mode 100644 index 0000000..cc31c5b --- /dev/null +++ b/polylan_submitter/opus_magnum/migrations/0019_reset_sequences.py @@ -0,0 +1,33 @@ +# 0015 copied rows with their ids via raw INSERT ... SELECT *, which doesn't +# bump postgres sequences -> new inserts collide on the pkey. Resync them. + +from django.core.management.color import no_style +from django.db import migrations + +MODEL_NAMES = [ + "SteamAPIKey", + "SteamCollection", + "SteamCollectionItem", + "Submission", + "PuzzleResponse", + "SubmissionFile", +] + + +def reset_sequences(apps, schema_editor): + connection = schema_editor.connection + models = [apps.get_model("opus_magnum", name) for name in MODEL_NAMES] + statements = connection.ops.sequence_reset_sql(no_style(), models) + with connection.cursor() as cursor: + for sql in statements: + cursor.execute(sql) + + +class Migration(migrations.Migration): + dependencies = [ + ("opus_magnum", "0018_event_required"), + ] + + operations = [ + migrations.RunPython(reset_sequences, migrations.RunPython.noop), + ]