Add unique constraint for sidecar process types#4632
Merged
Conversation
Adds a database-level unique constraint to the `sidecar_process_types` and `revision_sidecar_process_types` tables on the `(sidecar_guid, type)` and `(revision_sidecar_guid, type)` columns, respectively. This prevents duplicate process type entries for a given sidecar, which could previously occur under concurrent requests. The migration handles de-duplicating any existing records before applying the new unique index. Additionally, the corresponding models have been updated to gracefully handle the `UniqueConstraintViolation` and raise a user-friendly validation error. The previous application-level validates_unique check, which was susceptible to race conditions, has been replaced.
jochenehret
approved these changes
Oct 31, 2025
| rescue Sequel::UniqueConstraintViolation => e | ||
| raise e unless e.message.include?('revision_sidecar_process_types_revision_sidecar_guid_type_index') | ||
|
|
||
| errors.add(%i[revision_sidecar_guid type], "Sidecar is already associated with process type #{type}") |
Contributor
There was a problem hiding this comment.
Would it make sense to print different error messages for "revision" sidecars? (I guess not...)
Contributor
Author
There was a problem hiding this comment.
It's the same error message as before (see deleted line 13). As the user might be unaware of revisions I'd rather keep it out
ari-wg-gitbot
added a commit
to cloudfoundry/capi-release
that referenced
this pull request
Nov 3, 2025
Changes in cloud_controller_ng:
- Add unique index for route bindings
PR: cloudfoundry/cloud_controller_ng#4629
Author: Johannes Haass <johannes.haass@sap.com>
- Add unique constraint for sidecar process types
PR: cloudfoundry/cloud_controller_ng#4632
Author: Johannes Haass <johannes.haass@sap.com>
sethboyles
pushed a commit
to atanas-attodorov-wq/cloud_controller_ng
that referenced
this pull request
Dec 11, 2025
Adds a database-level unique constraint to the `sidecar_process_types` and `revision_sidecar_process_types` tables on the `(sidecar_guid, type)` and `(revision_sidecar_guid, type)` columns, respectively. This prevents duplicate process type entries for a given sidecar, which could previously occur under concurrent requests. The migration handles de-duplicating any existing records before applying the new unique index. Additionally, the corresponding models have been updated to gracefully handle the `UniqueConstraintViolation` and raise a user-friendly validation error. The previous application-level validates_unique check, which was susceptible to race conditions, has been replaced.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a database-level unique constraint to the
sidecar_process_typesandrevision_sidecar_process_typestables on the(sidecar_guid, type)and(revision_sidecar_guid, type)columns, respectively.This prevents duplicate process type entries for a given sidecar, which could previously occur under concurrent requests.
The migration handles de-duplicating any existing records before applying the new unique index. Additionally, the corresponding models have been updated to gracefully handle the
UniqueConstraintViolationand raise a user-friendly validation error. The previous application-level validates_unique check, which was susceptible to race conditions, has been replaced.I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
mainbranchI have run all the unit tests using
bundle exec rakeI have run CF Acceptance Tests