Skip to content

Add unique constraint for sidecar process types#4632

Merged
johha merged 1 commit intomainfrom
sidecar-process-types-unique-index
Nov 3, 2025
Merged

Add unique constraint for sidecar process types#4632
johha merged 1 commit intomainfrom
sidecar-process-types-unique-index

Conversation

@johha
Copy link
Copy Markdown
Contributor

@johha johha commented Oct 30, 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.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

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.
@johha johha marked this pull request as ready for review October 31, 2025 07:17
@johha johha requested a review from a team October 31, 2025 11:02
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}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to print different error messages for "revision" sidecars? (I guess not...)

Copy link
Copy Markdown
Contributor Author

@johha johha Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@johha johha merged commit 2f7dbde into main Nov 3, 2025
16 checks passed
@johha johha deleted the sidecar-process-types-unique-index branch November 3, 2025 07:08
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants