reset opus-magnum sequence
This commit is contained in:
@@ -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),
|
||||
]
|
||||
Reference in New Issue
Block a user