Skip to content

Commit 588c6dc

Browse files
snigdhasandrewshie-sentry
authored andcommitted
fix(aci): Delete rows from GroupOpenPeriod (#92687)
Need to iterate over the rows because there's too many to simply `.all().delete()`
1 parent 102d015 commit 588c6dc

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ preprod: 0001_emerge_upload_models
2323

2424
replays: 0001_squashed_0005_drop_replay_index
2525

26-
sentry: 0915_add_user_email_unique_column
26+
sentry: 0916_delete_open_period_rows
2727

2828
social_auth: 0001_squashed_0002_default_auto_field
2929

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 5.2.1 on 2025-06-02 20:17
2+
3+
from django.db import migrations
4+
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
5+
from django.db.migrations.state import StateApps
6+
7+
from sentry.new_migrations.migrations import CheckedMigration
8+
from sentry.utils.query import RangeQuerySetWrapperWithProgressBarApprox
9+
10+
11+
def delete_open_periods(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
12+
GroupOpenPeriod = apps.get_model("sentry", "GroupOpenPeriod")
13+
14+
for open_period in RangeQuerySetWrapperWithProgressBarApprox(GroupOpenPeriod.objects.all()):
15+
open_period.delete()
16+
17+
18+
class Migration(CheckedMigration):
19+
# This flag is used to mark that a migration shouldn't be automatically run in production.
20+
# This should only be used for operations where it's safe to run the migration after your
21+
# code has deployed. So this should not be used for most operations that alter the schema
22+
# of a table.
23+
# Here are some things that make sense to mark as post deployment:
24+
# - Large data migrations. Typically we want these to be run manually so that they can be
25+
# monitored and not block the deploy for a long period of time while they run.
26+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
27+
# run this outside deployments so that we don't block them. Note that while adding an index
28+
# is a schema change, it's completely safe to run the operation after the code has deployed.
29+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
30+
31+
is_post_deployment = True
32+
33+
dependencies = [
34+
("sentry", "0915_add_user_email_unique_column"),
35+
]
36+
37+
operations = [
38+
migrations.RunPython(
39+
code=delete_open_periods,
40+
reverse_code=migrations.RunPython.noop,
41+
hints={"tables": ["sentry_groupopenperiod"]},
42+
),
43+
]

0 commit comments

Comments
 (0)