summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-04-26 14:17:57 +0100
committerStephen Finucane <stephen@that.guru>2020-04-26 16:06:45 +0100
commitc7d6e18f33146d5564a8be5f4c859113d4c34dbe (patch)
tree1135d4381d4f742062ff9ce4088f87934eccc801
parent10b6162807ed76b1b56c0a57c9e55e02e88daad1 (diff)
downloadpatchwork-c7d6e18f33146d5564a8be5f4c859113d4c34dbe.tar
patchwork-c7d6e18f33146d5564a8be5f4c859113d4c34dbe.tar.gz
migrations: Resolve issues with other DB backends for 0042, 0043
0042 was using MySQL-specific SQL to delete entries in the 'patchwork_comment' table that were associated with entries in the 'patchwork_coverletter' table, while 0043 only considered MySQL and PostgrSQL when attempting to copy fields from 'patchwork_patch' to 'patchwork_submission'. Both issues are resolved. Signed-off-by: Stephen Finucane <stephen@that.guru>
-rw-r--r--patchwork/migrations/0042_add_cover_model.py38
-rw-r--r--patchwork/migrations/0043_merge_patch_submission.py32
2 files changed, 59 insertions, 11 deletions
diff --git a/patchwork/migrations/0042_add_cover_model.py b/patchwork/migrations/0042_add_cover_model.py
index 53196c1..3f4e034 100644
--- a/patchwork/migrations/0042_add_cover_model.py
+++ b/patchwork/migrations/0042_add_cover_model.py
@@ -1,10 +1,36 @@
import datetime
-from django.db import migrations, models
+from django.db import connection, migrations, models
import django.db.models.deletion
import patchwork.models
+def delete_coverletter_comments(apps, schema_editor):
+ if connection.vendor == 'mysql':
+ schema_editor.execute(
+ """
+ DELETE patchwork_comment FROM
+ patchwork_comment
+ INNER JOIN patchwork_coverletter
+ ON patchwork_coverletter.submission_ptr_id = patchwork_comment.submission_id
+ """, # noqa
+ )
+ elif connection.vendor == 'postgresql':
+ schema_editor.execute(
+ """
+ DELETE
+ FROM patchwork_comment
+ USING patchwork_coverletter
+ WHERE patchwork_coverletter.submission_ptr_id = patchwork_comment.submission_id
+ """, # noqa
+ )
+ else:
+ CoverLetter = apps.get_model('patchwork', 'CoverLetter')
+
+ for cover in CoverLetter.objects.all():
+ cover.comments.all().delete()
+
+
class Migration(migrations.Migration):
dependencies = [
@@ -175,15 +201,7 @@ class Migration(migrations.Migration):
# remove all the old 'CoverLetter'-related entries from the 'Comment'
# table
- migrations.RunSQL(
- """
- DELETE patchwork_comment FROM
- patchwork_comment
- INNER JOIN patchwork_coverletter
- ON patchwork_coverletter.submission_ptr_id = patchwork_comment.submission_id
- """, # noqa
- None
- ),
+ migrations.RunPython(delete_coverletter_comments, None, atomic=False),
# delete the old 'CoverLetter' model
diff --git a/patchwork/migrations/0043_merge_patch_submission.py b/patchwork/migrations/0043_merge_patch_submission.py
index 25e741d..d351892 100644
--- a/patchwork/migrations/0043_merge_patch_submission.py
+++ b/patchwork/migrations/0043_merge_patch_submission.py
@@ -42,11 +42,41 @@ def migrate_data(apps, schema_editor):
""" # noqa
)
else:
- raise Exception('DB not supported')
+ schema_editor.execute(
+ """
+ UPDATE patchwork_submission
+ SET (
+ archived, commit_ref, delegate_id, diff, hash, number,
+ pull_url, related_id, series_id, state_id
+ ) = (
+ SELECT
+ patchwork_patch.archived2,
+ patchwork_patch.commit_ref2,
+ patchwork_patch.delegate2_id,
+ patchwork_patch.diff2,
+ patchwork_patch.hash2,
+ patchwork_patch.number2,
+ patchwork_patch.pull_url2,
+ patchwork_patch.related2_id,
+ patchwork_patch.series2_id,
+ patchwork_patch.state2_id
+ FROM patchwork_patch
+ WHERE patchwork_patch.submission_ptr_id = patchwork_submission.id
+ )
+ WHERE
+ EXISTS (
+ SELECT *
+ FROM patchwork_patch
+ WHERE patchwork_patch.submission_ptr_id = patchwork_submission.id
+ )
+ """ # noqa
+ )
class Migration(migrations.Migration):
+ atomic = False
+
dependencies = [
('patchwork', '0042_add_cover_model'),
]