Skip to content

Commit 36adfc2

Browse files
committed
fix(attachments): Use dynamic retention for AddField, static 30d for AlterField
In migration 1060, use default_attachment_retention() for the initial AddField so existing rows get an expiry based on the environment's configured retention. Immediately follow with an AlterField to set the permanent db_default to a static NOW() + 30 days. Update migration 1061 to carry the same static 30-day expression instead of the old epoch sentinel.
1 parent 89d982c commit 36adfc2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/sentry/migrations/1060_eventattachment_date_expires.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
from django.db import migrations, models
88

99
from sentry.new_migrations.migrations import CheckedMigration
10+
from sentry.objectstore import default_attachment_retention
11+
12+
# Initial default applies to existing attachments. New rows will be written with
13+
# a runtime-defined default, so we follow-up with a static 30d default.
14+
_RETENTION_DAYS = default_attachment_retention()
1015

1116

1217
class Migration(CheckedMigration):
@@ -30,6 +35,17 @@ class Migration(CheckedMigration):
3035

3136
operations = [
3237
migrations.AddField(
38+
model_name="eventattachment",
39+
name="date_expires",
40+
field=models.DateTimeField(
41+
db_default=django.db.models.expressions.CombinedExpression(
42+
django.db.models.functions.datetime.Now(),
43+
"+",
44+
models.Value(datetime.timedelta(days=_RETENTION_DAYS)),
45+
),
46+
),
47+
),
48+
migrations.AlterField(
3349
model_name="eventattachment",
3450
name="date_expires",
3551
field=models.DateTimeField(

src/sentry/migrations/1061_eventattachment_date_expires_index.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Generated by Django 5.2.12 on 2026-04-01 12:13
22

33
import datetime
4+
5+
import django.db.models.expressions
6+
import django.db.models.functions.datetime
47
from django.db import migrations, models
58

69
from sentry.new_migrations.migrations import CheckedMigration
@@ -30,7 +33,11 @@ class Migration(CheckedMigration):
3033
model_name="eventattachment",
3134
name="date_expires",
3235
field=models.DateTimeField(
33-
db_default=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
36+
db_default=django.db.models.expressions.CombinedExpression(
37+
django.db.models.functions.datetime.Now(),
38+
"+",
39+
models.Value(datetime.timedelta(days=30)),
40+
),
3441
db_index=True,
3542
),
3643
),

0 commit comments

Comments
 (0)