Skip to content

FINERACT-248: Prevent duplicate SMS campaign names#5439

Open
nickus wants to merge 1 commit intoapache:developfrom
nickus:FINERACT-248-prevent-duplicate-sms-campaign-names
Open

FINERACT-248: Prevent duplicate SMS campaign names#5439
nickus wants to merge 1 commit intoapache:developfrom
nickus:FINERACT-248-prevent-duplicate-sms-campaign-names

Conversation

@nickus
Copy link

@nickus nickus commented Feb 3, 2026

Summary

Add validation to check for duplicate campaign names before creating or updating SMS campaigns. This provides a user-friendly error message instead of relying on database constraint violations.

Changes

  • Add existsByCampaignName() and existsByCampaignNameAndIdNot() methods to SmsCampaignRepository
  • Validate campaign name uniqueness in create() method before saving
  • Validate campaign name uniqueness in update() method when name changes
  • Add SmsCampaignNameAlreadyExistsException for clear error messages

Test plan

  • Integration tests added for:
    • Creating a campaign with a duplicate name should fail with appropriate error
    • Creating campaigns with unique names should succeed

Add validation to check for duplicate campaign names before creating or
updating SMS campaigns. This provides a user-friendly error message instead
of relying on database constraint violations.

Changes:
- Add existsByCampaignName() and existsByCampaignNameAndIdNot() to repository
- Validate campaign name uniqueness in create() method
- Validate campaign name uniqueness in update() when name changes
- Add SmsCampaignNameAlreadyExistsException for clear error messages
- Add integration tests for duplicate name validation
- Update CampaignsHelper with methods for testing specific campaign names
@nickus nickus force-pushed the FINERACT-248-prevent-duplicate-sms-campaign-names branch from bc4e52c to a8a8b7a Compare February 3, 2026 22:10
Comment on lines +113 to +115
if (this.smsCampaignRepository.existsByCampaignName(campaignName)) {
throw new SmsCampaignNameAlreadyExistsException(campaignName);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the default isolation level we use is read_committed, meaning only committed things will be revealed by this check. It not guarantees anything.
2 transactions concurrently writing the same campaign name is possible.

If you wanna prevent it, ensure having a unique key on the DB level. This is good for a best-effort check but it's not bullet-proof,.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, there is already a unique key on the DB level. You might see further I catch DataIntegrityViolationException and throw the same exception.

see realCause.getMessage().contains("campaign_name_UNIQUE")

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