Skip to content

Replacing validate uniqueness with db constraint on RevisionSidecar model - #4950

Merged
philippthun merged 5 commits into
cloudfoundry:mainfrom
sap-contributions:feature/replace-validate-uniqueness-with-db-constrain-on-revision-sidecar
Apr 8, 2026
Merged

Replacing validate uniqueness with db constraint on RevisionSidecar model#4950
philippthun merged 5 commits into
cloudfoundry:mainfrom
sap-contributions:feature/replace-validate-uniqueness-with-db-constrain-on-revision-sidecar

Conversation

@serdarozerr

Copy link
Copy Markdown
Contributor

Adds a database-level unique constraint on (revision_guid, name) in the revision_sidecars table to prevent duplicate sidecar names per revision.

Changes

  • Migration to add the unique constraint, with deduplication of existing data
  • around_save in RevisionSidecarModel to convert UniqueConstraintViolation into a ValidationFailed with a user-friendly message
  • Removed validates_unique from the model since the DB constraint now handles it
  • Tests for the migration (up, down, and constraint enforcement)
  • Tests for the around_save behavior
  • 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

- DB migration added for new uniqueness constraint. Tests for the new migration is added too.
- around_save method added into RevisionSidecarModel to catch new constraint and augment it with message. Sequel:validate_uniqueness removed from the model
@serdarozerr
serdarozerr marked this pull request as ready for review March 23, 2026 12:34
@serdarozerr serdarozerr changed the title Unique constraint on revision_guid and name for RevisionSidecarModel Replacing validate uniqueness with db constraint on RevisionSidecar model Mar 23, 2026
johha
johha previously approved these changes Mar 23, 2026
johha
johha previously approved these changes Mar 26, 2026
Comment thread spec/migrations/20260320141005_add_unique_constraint_to_revision_sidecars_spec.rb Outdated
let!(:revision) { VCAP::CloudController::RevisionModel.make(:app) }

it 'remove dublicates, add constraint and revert migration' do
# =========================================================================================

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we don't use this kind of comments in other places (or we should not use them) as it makes reading harder from my point of view. A single line comment is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have followed the previous similar migration and this comment style has been used.

@philippthun
philippthun merged commit e055785 into cloudfoundry:main Apr 8, 2026
16 checks passed
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Apr 8, 2026
Changes in cloud_controller_ng:

- Replacing validate uniqueness with db constraint on RevisionProcessCommand model
    PR: cloudfoundry/cloud_controller_ng#4956
    Author: serdar özer <serdar.oezer@sap.com>

- Replacing validate uniqueness with db constraint on RevisionSidecar model
    PR: cloudfoundry/cloud_controller_ng#4950
    Author: serdar özer <serdar.oezer@sap.com>

- Replacing validate uniqueness with db constraint on Sidecar model
    PR: cloudfoundry/cloud_controller_ng#4954
    Author: serdar özer <serdar.oezer@sap.com>

Dependency updates in cloud_controller_ng:

- build(deps): bump addressable from 2.8.8 to 2.9.0 in /docs/v3
    PR: cloudfoundry/cloud_controller_ng#4998
    Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants