Repository navigation
fix(policy): make obligation trigger uniqueness client-aware #3114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
elizabethhealy
merged 5 commits into
main
from
dspx-2237-obligation-trigger-unique-client-aware
Mar 9, 2026
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
66cc2b9
make obligation trigger uniqueness client-aware
elizabethhealy e757315
update tests
elizabethhealy e74f151
regen the erd
elizabethhealy 8e4a2b0
regen again on clean db
elizabethhealy 9bd4f04
Merge branch 'main' into dspx-2237-obligation-trigger-unique-client-a…
elizabethhealy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...db/migrations/20260306000000_make_obligation_trigger_uniqueness_client_aware.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Make Obligation Trigger Uniqueness Client-Aware | ||
|
|
||
| This migration updates uniqueness semantics for `obligation_triggers` after the | ||
| introduction of optional `client_id` scoping. | ||
|
|
||
| ## Why | ||
|
|
||
| The previous unique constraint only considered: | ||
|
|
||
| - `obligation_value_id` | ||
| - `action_id` | ||
| - `attribute_value_id` | ||
|
|
||
| That prevented creating multiple triggers for different PEP clients when all | ||
| other fields were the same. | ||
|
|
||
| ## Changes | ||
|
|
||
| 1. Drop the existing table-level unique constraint on: | ||
| - `(obligation_value_id, action_id, attribute_value_id)` | ||
| - Includes handling historical truncated constraint names in Postgres. | ||
| 2. Add partial unique index for unscoped triggers: | ||
| - `(obligation_value_id, action_id, attribute_value_id)` where `client_id IS NULL` | ||
| 3. Add partial unique index for client-scoped triggers: | ||
| - `(obligation_value_id, action_id, attribute_value_id, client_id)` where `client_id IS NOT NULL` | ||
|
|
||
| ## Resulting Behavior | ||
|
|
||
| - Allows one unscoped trigger per obligation/action/attribute tuple. | ||
| - Allows one scoped trigger per unique `client_id` for the same tuple. | ||
| - Prevents duplicate scoped triggers for the same `client_id`. |
30 changes: 30 additions & 0 deletions
30
...e/policy/db/migrations/20260306000000_make_obligation_trigger_uniqueness_client_aware.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
| -- Make trigger uniqueness aware of optional client_id scoping. | ||
| ALTER TABLE IF EXISTS obligation_triggers | ||
| DROP CONSTRAINT IF EXISTS obligation_triggers_obligation_value_id_action_id_attribute_value_id_key; | ||
|
|
||
| ALTER TABLE IF EXISTS obligation_triggers | ||
| DROP CONSTRAINT IF EXISTS obligation_triggers_obligation_value_id_action_id_attribute_key; | ||
|
|
||
| ALTER TABLE IF EXISTS obligation_triggers | ||
| DROP CONSTRAINT IF EXISTS obligation_triggers_obligation_value_id_action_id_attribute_val; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS obligation_triggers_unscoped_unique_idx | ||
| ON obligation_triggers (obligation_value_id, action_id, attribute_value_id) | ||
| WHERE client_id IS NULL; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS obligation_triggers_scoped_unique_idx | ||
| ON obligation_triggers (obligation_value_id, action_id, attribute_value_id, client_id) | ||
| WHERE client_id IS NOT NULL; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| DROP INDEX IF EXISTS obligation_triggers_scoped_unique_idx; | ||
| DROP INDEX IF EXISTS obligation_triggers_unscoped_unique_idx; | ||
|
|
||
| ALTER TABLE IF EXISTS obligation_triggers | ||
| ADD CONSTRAINT obligation_triggers_obligation_value_id_action_id_attribute_key | ||
| UNIQUE (obligation_value_id, action_id, attribute_value_id); | ||
| -- +goose StatementEnd |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.