summaryrefslogtreecommitdiff
path: root/patchwork/migrations/0042_add_cover_model.py
diff options
context:
space:
mode:
Diffstat (limited to 'patchwork/migrations/0042_add_cover_model.py')
-rw-r--r--patchwork/migrations/0042_add_cover_model.py38
1 files changed, 28 insertions, 10 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