Browse Source

ref: reintroduce pickle migrations which have not yet been run (#51407)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
335d27b715

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0491_remove_orgmemmap_unique_constraints
+sentry: 0493_pickle_to_json_sentry_activity
 social_auth: 0001_initial

+ 39 - 0
src/sentry/migrations/0492_pickle_to_json_sentry_groupedmessage.py

@@ -0,0 +1,39 @@
+# Generated by Django 2.2.28 on 2023-05-19 17:25
+import logging
+
+from django.db import migrations
+from django.db.utils import DatabaseError
+
+from sentry.new_migrations.migrations import CheckedMigration
+from sentry.utils.query import RangeQuerySetWrapperWithProgressBarApprox
+
+
+def _backfill(apps, schema_editor):
+    cls = apps.get_model("sentry", "Group")
+
+    for obj in RangeQuerySetWrapperWithProgressBarApprox(cls.objects.all()):
+        # load pickle, save json
+        try:
+            obj.save(update_fields=["data"])
+        except DatabaseError as e:
+            logging.warning(f"ignoring save error (row was likely deleted): {e}")
+
+
+class Migration(CheckedMigration):
+    # data migration: must be run out of band
+    is_dangerous = True
+
+    # data migration: run outside of a transaction
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0491_remove_orgmemmap_unique_constraints"),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            _backfill,
+            migrations.RunPython.noop,
+            hints={"tables": ["sentry_groupedmessage"]},
+        ),
+    ]

+ 34 - 0
src/sentry/migrations/0493_pickle_to_json_sentry_activity.py

@@ -0,0 +1,34 @@
+# Generated by Django 2.2.28 on 2023-05-19 17:25
+
+from django.db import migrations
+
+from sentry.new_migrations.migrations import CheckedMigration
+from sentry.utils.query import RangeQuerySetWrapperWithProgressBarApprox
+
+
+def _backfill(apps, schema_editor):
+    cls = apps.get_model("sentry", "Activity")
+
+    for obj in RangeQuerySetWrapperWithProgressBarApprox(cls.objects.all()):
+        # load pickle, save json
+        obj.save(update_fields=["data"])
+
+
+class Migration(CheckedMigration):
+    # data migration: must be run out of band
+    is_dangerous = True
+
+    # data migration: run outside of a transaction
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0492_pickle_to_json_sentry_groupedmessage"),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            _backfill,
+            migrations.RunPython.noop,
+            hints={"tables": ["sentry_activity"]},
+        ),
+    ]