Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ releases: 0004_cleanup_failed_safe_deletes

replays: 0001_squashed_0007_organizationmember_replay_access

seer: 0029_add_agent_write_grant
seer: 0030_add_night_shift_run_schedule_id

sentry: 1146_add_gcp_service_account

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 5.2.14 on 2026-07-24 22:38

from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("seer", "0029_add_agent_write_grant"),
("sentry", "1146_add_gcp_service_account"),
]

operations = [
migrations.AddField(
model_name="seernightshiftrun",
name="schedule_id",
field=models.CharField(max_length=256, null=True),
),
migrations.AddField(
model_name="seernightshiftrun",
name="date_completed",
field=models.DateTimeField(null=True),
),
migrations.AddConstraint(
model_name="seernightshiftrun",
constraint=models.UniqueConstraint(
condition=models.Q(("schedule_id__isnull", False)),
fields=("organization", "workflow_config", "schedule_id"),
name="seer_nightshiftrun_unique_org_config_schedule",
),
),
]
18 changes: 15 additions & 3 deletions src/sentry/seer/models/night_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

@cell_silo_model
class SeerNightShiftRun(DefaultFieldsModel):
"""
Records each night shift invocation for an organization.
One row is created per org each time run_night_shift_for_org executes.
"""Records each night shift invocation for an organization.

Cron invocations create one row per organization, workflow config, and
schedule window. Manual invocations create one row per execution.
"""

__relocation_scope__ = RelocationScope.Excluded
Expand All @@ -21,6 +22,10 @@ class SeerNightShiftRun(DefaultFieldsModel):
workflow_config = FlexibleForeignKey(
"seer.SeerWorkflowConfig", on_delete=models.SET_NULL, null=True
)
# Cron-derived schedule window (currently YYYY-MM-DDTHH:MM); nullable for
# manual and historical runs, with standard capacity for future formats.
schedule_id = models.CharField(max_length=256, null=True)
date_completed = models.DateTimeField(null=True)
extras = models.JSONField(db_default={}, default=dict)

class Meta:
Expand All @@ -31,6 +36,13 @@ class Meta:
models.Index(fields=["date_added"]),
models.Index(fields=["workflow_config", "date_added"]),
]
constraints = [
models.UniqueConstraint(
fields=["organization", "workflow_config", "schedule_id"],
condition=models.Q(schedule_id__isnull=False),
name="seer_nightshiftrun_unique_org_config_schedule",
)
]

__repr__ = sane_repr("organization_id", "workflow_config_id", "date_added")

Expand Down
Loading
Loading