feat(migration): old submissions -> opus magnum app
This commit is contained in:
parent
5584e54b58
commit
b437210eb3
@ -205,7 +205,7 @@ class Migration(migrations.Migration):
|
|||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
related_name="items",
|
related_name="items",
|
||||||
to="submissions.steamcollection",
|
to="opus_magnum.steamcollection",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -160,7 +160,7 @@ class Migration(migrations.Migration):
|
|||||||
help_text="The puzzle this response is for",
|
help_text="The puzzle this response is for",
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
related_name="responses",
|
related_name="responses",
|
||||||
to="submissions.steamcollectionitem",
|
to="opus_magnum.steamcollectionitem",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -168,7 +168,7 @@ class Migration(migrations.Migration):
|
|||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
related_name="responses",
|
related_name="responses",
|
||||||
to="submissions.submission",
|
to="opus_magnum.submission",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -239,7 +239,7 @@ class Migration(migrations.Migration):
|
|||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
related_name="files",
|
related_name="files",
|
||||||
to="submissions.puzzleresponse",
|
to="opus_magnum.puzzleresponse",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -0,0 +1,67 @@
|
|||||||
|
# Data migration: Copy all data from submissions app tables to opus_magnum app tables
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_data_forward(apps, schema_editor):
|
||||||
|
"""Copy data from submissions_* tables to opus_magnum_* tables"""
|
||||||
|
# Use raw SQL to copy data while preserving all fields
|
||||||
|
with schema_editor.connection.cursor() as cursor:
|
||||||
|
# Copy SteamAPIKey
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_steamapikey
|
||||||
|
SELECT * FROM submissions_steamapikey
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Copy SteamCollection
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_steamcollection
|
||||||
|
SELECT * FROM submissions_steamcollection
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Copy SteamCollectionItem
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_steamcollectionitem
|
||||||
|
SELECT * FROM submissions_steamcollectionitem
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Copy Submission
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_submission
|
||||||
|
SELECT * FROM submissions_submission
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Copy PuzzleResponse
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_puzzleresponse
|
||||||
|
SELECT * FROM submissions_puzzleresponse
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Copy SubmissionFile
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO opus_magnum_submissionfile
|
||||||
|
SELECT * FROM submissions_submissionfile
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_data_backward(apps, schema_editor):
|
||||||
|
"""Delete all data from opus_magnum_* tables"""
|
||||||
|
with schema_editor.connection.cursor() as cursor:
|
||||||
|
# Delete in reverse order of foreign key dependencies
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_submissionfile")
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_puzzleresponse")
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_submission")
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_steamcollectionitem")
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_steamcollection")
|
||||||
|
cursor.execute("DELETE FROM opus_magnum_steamapikey")
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('opus_magnum', '0014_steamcollection_accepting_submissions'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_data_forward, migrate_data_backward),
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue
Block a user