Skip to content

Replacing validate uniqueness with db constraint on Sidecar model#4954

Open
serdarozerr wants to merge 2 commits intocloudfoundry:mainfrom
sap-contributions:feature/replace-validate-uniqueness-with-db-constrain-on-sidecar
Open

Replacing validate uniqueness with db constraint on Sidecar model#4954
serdarozerr wants to merge 2 commits intocloudfoundry:mainfrom
sap-contributions:feature/replace-validate-uniqueness-with-db-constrain-on-sidecar

Conversation

@serdarozerr
Copy link
Contributor

Replaces the Sequel validates_unique check with a DB-level unique index on (app_guid, name) for the sidecars table. The around_save hook catches UniqueConstraintViolation and converts it to ValidationFailed, making uniqueness enforcement race-condition safe.

Changes

  • Migration: Cleans duplicate rows, adds sidecars_app_guid_name_index unique constraint (idempotent, with guard check before adding)
  • Model: Removed validates_unique [:app_guid, :name], added around_save for DB-level enforcement with a user-friendly error message
  • Specs: Migration spec (constraint creation, duplicate cleanup, idempotency, rollback) + updated model uniqueness tests using around_save
  • 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 on columns app_guid and name. Unit testting added too
- sequel validate uniqueness removed from model and around save added instead
@serdarozerr serdarozerr changed the title Replacing validate uniqueness with db constraint on sidecar model Replacing validate uniqueness with db constraint on Sidecar model Mar 23, 2026
johha
johha previously approved these changes Mar 23, 2026
Copy link
Contributor

@johha johha left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants