sentry icon indicating copy to clipboard operation
sentry copied to clipboard

feat(workflow_engine): Add unique index to ensure `DetectorState` is unique per detector/group_key

Open wedamija opened this issue 1 year ago • 2 comments

We don't want to allow there to be multiple state rows for the same detector and group key, so enforcing this at the db level.

We use the coalesce here since Postgres treats nulls as unique values, and so we'd end up allowing duplicate rows when we have a null group_key without it.

wedamija avatar Oct 18 '24 22:10 wedamija

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py ()

--
-- Create constraint detector_state_unique_group_key on model detectorstate
--
CREATE UNIQUE INDEX CONCURRENTLY "detector_state_unique_group_key" ON "workflow_engine_detectorstate" ("detector_id", (COALESCE("detector_group_key", '')));

github-actions[bot] avatar Oct 18 '24 23:10 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:white_check_mark: All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #79388   +/-   ##
=======================================
  Coverage   78.33%   78.33%           
=======================================
  Files        7132     7133    +1     
  Lines      315113   315192   +79     
  Branches    51510    51511    +1     
=======================================
+ Hits       246842   246915   +73     
- Misses      61801    61805    +4     
- Partials     6470     6472    +2     

codecov[bot] avatar Oct 19 '24 05:10 codecov[bot]

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

github-actions[bot] avatar Oct 21 '24 17:10 github-actions[bot]

Bundle Report

Changes will increase total bundle size by 10.74kB (0.03%) :arrow_up:. This is within the configured threshold :white_check_mark:

Detailed changes
Bundle name Size Change
app-webpack-bundle-array-push 30.97MB 10.74kB (0.03%) :arrow_up:

codecov[bot] avatar Oct 21 '24 17:10 codecov[bot]