Skip to content

Commit

Permalink
ref(hc): Make tombstone migration no-op. (#55286)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Story <[email protected]>
  • Loading branch information
corps and markstory authored Aug 28, 2023
1 parent 670319e commit 95f56de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 70 deletions.
40 changes: 3 additions & 37 deletions src/sentry/migrations/0536_backfill_tombstones.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
# Generated by Django 3.2.20 on 2023-08-01 20:51

from django.db import IntegrityError, migrations, transaction
from django.db.models import Max

from sentry.new_migrations.migrations import CheckedMigration
from sentry.utils.query import RangeQuerySetWrapperWithProgressBar


def backfill_tombstones(apps, schema_editor):
RegionTombstone = apps.get_model("sentry", "RegionTombstone")
ControlTombstone = apps.get_model("sentry", "ControlTombstone")

max_rt = RegionTombstone.objects.aggregate(Max("id"))["id__max"] or 0
max_ct = ControlTombstone.objects.aggregate(Max("id"))["id__max"] or 0

for rt in RangeQuerySetWrapperWithProgressBar(RegionTombstone.objects.filter(id__lte=max_rt)):
try:
with transaction.atomic("default"):
ControlTombstone.objects.create(
table_name=rt.table_name, object_identifier=rt.object_identifier
)
except IntegrityError:
pass

for ct in RangeQuerySetWrapperWithProgressBar(ControlTombstone.objects.filter(id__lte=max_ct)):
try:
with transaction.atomic("default"):
RegionTombstone.objects.create(
table_name=ct.table_name, object_identifier=ct.object_identifier
)
except IntegrityError:
pass


# This migration has been run in production SaaS to fix an optimization issue with tombstones.
# It is not necessary to run in other environments, and produces problems with the split db world.
class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production. For
# the most part, this should only be used for operations where it's safe to run the migration
Expand All @@ -50,10 +22,4 @@ class Migration(CheckedMigration):
("sentry", "0535_add_created_date_to_outbox_model"),
]

operations = [
migrations.RunPython(
backfill_tombstones,
migrations.RunPython.noop,
hints={"tables": ["sentry_controltombstone", "sentry_regiontombstone"]},
),
]
operations = []
33 changes: 0 additions & 33 deletions tests/sentry/migrations/test_0536_backfill_tombstones.py

This file was deleted.

0 comments on commit 95f56de

Please sign in to comment.