Skip to content

Commit 5b3ad90

Browse files
authored
fix(aci): Change open period range boundary to inclusive (#93535)
Some issues have the same regression/resolution time in our db and the range boundary today would reject those as valid start/end times for open periods. Updating the boundary to be inclusive on both ends should fix this and allow an open period to start at the same time that the previous one ends.
1 parent 5910a26 commit 5b3ad90

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ preprod: 0005_add_git_commit
2525

2626
replays: 0001_squashed_0005_drop_replay_index
2727

28-
sentry: 0929_no_pickle_authenticator
28+
sentry: 0930_make_open_period_range_boundary_inclusive
2929

3030
social_auth: 0001_squashed_0002_default_auto_field
3131

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Generated by Django 5.2.1 on 2025-06-13 22:49
2+
3+
import django.contrib.postgres.constraints
4+
from django.contrib.postgres.fields.ranges import RangeBoundary, RangeOperators
5+
from django.db import migrations, models
6+
7+
import sentry.models.groupopenperiod
8+
from sentry.new_migrations.migrations import CheckedMigration
9+
from sentry.new_migrations.monkey.special import SafeRunSQL
10+
11+
12+
class Migration(CheckedMigration):
13+
# This flag is used to mark that a migration shouldn't be automatically run in production.
14+
# This should only be used for operations where it's safe to run the migration after your
15+
# code has deployed. So this should not be used for most operations that alter the schema
16+
# of a table.
17+
# Here are some things that make sense to mark as post deployment:
18+
# - Large data migrations. Typically we want these to be run manually so that they can be
19+
# monitored and not block the deploy for a long period of time while they run.
20+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
21+
# run this outside deployments so that we don't block them. Note that while adding an index
22+
# is a schema change, it's completely safe to run the operation after the code has deployed.
23+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
24+
25+
is_post_deployment = True
26+
27+
dependencies = [
28+
("sentry", "0929_no_pickle_authenticator"),
29+
]
30+
31+
operations = [
32+
migrations.SeparateDatabaseAndState(
33+
database_operations=[
34+
SafeRunSQL(
35+
"""\
36+
ALTER TABLE "sentry_groupopenperiod" ADD CONSTRAINT "exclude_overlapping_date_start_end" EXCLUDE USING GIST ("group_id" WITH =, (TSTZRANGE("date_started", "date_ended", '[]')) WITH &&);
37+
""",
38+
reverse_sql="ALTER TABLE sentry_groupopenperiod DROP CONSTRAINT IF EXISTS exclude_overlapping_date_start_end;",
39+
hints={"tables": ["sentry_groupopenperiod"]},
40+
),
41+
],
42+
state_operations=[
43+
migrations.AddConstraint(
44+
model_name="groupopenperiod",
45+
constraint=django.contrib.postgres.constraints.ExclusionConstraint(
46+
expressions=[
47+
(models.F("group"), RangeOperators.EQUAL),
48+
(
49+
sentry.models.groupopenperiod.TsTzRange(
50+
"date_started",
51+
"date_ended",
52+
RangeBoundary(inclusive_lower=True, inclusive_upper=True),
53+
),
54+
RangeOperators.OVERLAPS,
55+
),
56+
],
57+
name="exclude_overlapping_date_start_end",
58+
),
59+
),
60+
],
61+
),
62+
migrations.RemoveConstraint(
63+
model_name="groupopenperiod",
64+
name="exclude_overlapping_start_end",
65+
),
66+
]

src/sentry/models/groupopenperiod.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ class Meta:
5858

5959
constraints = (
6060
ExclusionConstraint(
61-
name="exclude_overlapping_start_end",
61+
name="exclude_overlapping_date_start_end",
6262
expressions=[
6363
(models.F("group"), RangeOperators.EQUAL),
6464
(
65-
TsTzRange("date_started", "date_ended", RangeBoundary()),
65+
TsTzRange(
66+
"date_started",
67+
"date_ended",
68+
RangeBoundary(inclusive_lower=True, inclusive_upper=True),
69+
),
6670
RangeOperators.OVERLAPS,
6771
),
6872
],

0 commit comments

Comments
 (0)