Skip to content

Commit

Permalink
back to coalesce
Browse files Browse the repository at this point in the history
  • Loading branch information
wedamija committed Oct 18, 2024
1 parent 0193e90 commit e13d00e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ replays: 0004_index_together
sentry: 0777_add_related_name_to_dashboard_permissions
social_auth: 0002_default_auto_field
uptime: 0017_unique_on_timeout
workflow_engine: 0010_detector_state_unique_gruop
workflow_engine: 0010_detector_state_unique_group
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.1.1 on 2024-10-18 23:02
# Generated by Django 5.1.1 on 2024-10-18 23:09

import django.db.models.functions.comparison
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
Expand Down Expand Up @@ -28,9 +29,11 @@ class Migration(CheckedMigration):
migrations.AddConstraint(
model_name="detectorstate",
constraint=models.UniqueConstraint(
fields=("detector", "detector_group_key"),
models.F("detector"),
django.db.models.functions.comparison.Coalesce(
"detector_group_key", models.Value("")
),
name="detector_state_unique_group_key",
nulls_distinct=False,
),
),
]
6 changes: 4 additions & 2 deletions src/sentry/workflow_engine/models/detector_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import StrEnum

from django.db import models
from django.db.models import F, Value
from django.db.models.functions import Coalesce

from sentry.backup.scopes import RelocationScope
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model
Expand Down Expand Up @@ -29,8 +31,8 @@ class DetectorState(DefaultFieldsModel):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["detector", "detector_group_key"],
nulls_distinct=False,
F("detector"),
Coalesce("detector_group_key", Value("")),
name="detector_state_unique_group_key",
),
]

0 comments on commit e13d00e

Please sign in to comment.