[PATCH 5/6] Migration part 2: drop old fields

Daniel Axtens dja at axtens.net
Wed Sep 18 16:17:30 AEST 2019


Once you have run the live migration script, you can drop the old
fields.

There is a sanity check migration as well, to make sure that you
don't drop the tables while you have unmigrated data.

Once you have applied this, you can move on to applying the final
stuff about dropping the cover letter table.

This doesn't clean up the transition code, I figure we can do that
once we have all the fields migrated and can kill off the Patch
model entirely.

Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 patchwork/migrations/0039_sanity_check.py     | 27 +++++++++++++++++++
 .../migrations/0040_drop_old_diff_pull_url.py | 23 ++++++++++++++++
 patchwork/models.py                           |  2 --
 3 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 patchwork/migrations/0039_sanity_check.py
 create mode 100644 patchwork/migrations/0040_drop_old_diff_pull_url.py

diff --git a/patchwork/migrations/0039_sanity_check.py b/patchwork/migrations/0039_sanity_check.py
new file mode 100644
index 000000000000..e26b338f90b3
--- /dev/null
+++ b/patchwork/migrations/0039_sanity_check.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.24 on 2019-09-18 10:34
+from __future__ import unicode_literals
+
+from django.db import migrations
+from django.db.models import Q
+
+def sanity_check(apps, schema_editor):
+    Patch = apps.get_model("patchwork", "Patch")
+    db_alias = schema_editor.connection.alias
+    diffs = Q(old_diff__isnull=False, submission_ptr__new_diff__isnull=True)
+    pull_urls = Q(old_pull_url__isnull=False, submission_ptr__new_pull_url__isnull=True)
+    query = Patch.objects.using(db_alias).filter(diffs | pull_urls)
+    if query.exists():
+        raise Exception("It seems not all data has been migrated! bailing out")
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0038_submission_new_diff_pull_url'),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            sanity_check, migrations.RunPython.noop,
+        ),
+    ]
diff --git a/patchwork/migrations/0040_drop_old_diff_pull_url.py b/patchwork/migrations/0040_drop_old_diff_pull_url.py
new file mode 100644
index 000000000000..088544b09d31
--- /dev/null
+++ b/patchwork/migrations/0040_drop_old_diff_pull_url.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.24 on 2019-09-18 10:34
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0039_sanity_check'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='patch',
+            name='old_diff',
+        ),
+        migrations.RemoveField(
+            model_name='patch',
+            name='old_pull_url',
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index 31f459e1a126..a96018004f75 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -415,9 +415,7 @@ class CoverLetter(Submission):
 class Patch(Submission):
     # patch metadata
 
-    old_diff = models.TextField(null=True, blank=True, db_column='diff')
     commit_ref = models.CharField(max_length=255, null=True, blank=True)
-    old_pull_url = models.CharField(max_length=255, null=True, blank=True, db_column='pull_url')
     tags = models.ManyToManyField(Tag, through=PatchTag)
 
     # patchwork metadata
-- 
2.20.1



More information about the Patchwork mailing list