Skip to content

Commit 3642446

Browse files
authored
migration(shared-views): Add migration to delete default views (#90853)
As part of the shared views feature launch, we would like to remove all of the default views that have been created before, as this pollutes the "All View" page with a lot of duplicate entries. The default views to be deleted have the following conditions: 1. The name of the view is "Prioritized" 2. The query of the view is `is:unresolved issue.priority:[high, medium]` 3. ~This view is the org member's _only_ view~
1 parent ace1f48 commit 3642446

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ remote_subscriptions: 0003_drop_remote_subscription
2121

2222
replays: 0004_index_together
2323

24-
sentry: 0880_orgauthtoken_bigint
24+
sentry: 0881_delete_single_prioritized_groupsearchviews
2525

2626
social_auth: 0002_default_auto_field
2727

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Generated by Django 5.1.7 on 2025-05-02 17:28
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+
from django.db.models import Q
7+
8+
from sentry.new_migrations.migrations import CheckedMigration
9+
from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
10+
11+
12+
def delete_single_prioritized_groupsearchviews(
13+
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
14+
) -> None:
15+
GroupSearchView = apps.get_model("sentry", "GroupSearchView")
16+
17+
target_query_set = GroupSearchView.objects.filter(
18+
Q(name="Prioritized") & Q(query="is:unresolved issue.priority:[high, medium]")
19+
)
20+
21+
for gsv in RangeQuerySetWrapperWithProgressBar(target_query_set):
22+
gsv.delete()
23+
24+
25+
class Migration(CheckedMigration):
26+
# This flag is used to mark that a migration shouldn't be automatically run in production.
27+
# This should only be used for operations where it's safe to run the migration after your
28+
# code has deployed. So this should not be used for most operations that alter the schema
29+
# of a table.
30+
# Here are some things that make sense to mark as post deployment:
31+
# - Large data migrations. Typically we want these to be run manually so that they can be
32+
# monitored and not block the deploy for a long period of time while they run.
33+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
34+
# run this outside deployments so that we don't block them. Note that while adding an index
35+
# is a schema change, it's completely safe to run the operation after the code has deployed.
36+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
37+
38+
is_post_deployment = True
39+
40+
dependencies = [
41+
("sentry", "0880_orgauthtoken_bigint"),
42+
]
43+
44+
operations = [
45+
migrations.RunPython(
46+
delete_single_prioritized_groupsearchviews,
47+
reverse_code=migrations.RunPython.noop,
48+
hints={"tables": ["sentry_groupsearchview"]},
49+
),
50+
]

0 commit comments

Comments
 (0)