-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
0493_pickle_to_json_sentry_activity.py
41 lines (31 loc) · 1.24 KB
/
0493_pickle_to_json_sentry_activity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Generated by Django 2.2.28 on 2023-05-19 17:25
import logging
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.utils import DatabaseError
from sentry.new_migrations.migrations import CheckedMigration
from sentry.utils.query import RangeQuerySetWrapperWithProgressBarApprox
def _backfill(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
cls = apps.get_model("sentry", "Activity")
for obj in RangeQuerySetWrapperWithProgressBarApprox(cls.objects.all()):
# load pickle, save json
try:
obj.save(update_fields=["data"])
except DatabaseError as e:
logging.warning("ignoring save error (row was likely deleted): %s", e)
class Migration(CheckedMigration):
# data migration: must be run out of band
is_post_deployment = 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"]},
),
]