Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zane-ld-app
Copy link

@zane-ld-app zane-ld-app bot commented Sep 17, 2025

Summary

  • Replace try-catch approach with explicit existence check before creating BillingEmailHistory records
  • Eliminates recurring constraint violation errors that appear every 15 minutes in the logs
  • Maintains the same functionality of preventing duplicate billing notification emails

Problem

The application was experiencing frequent unique constraint violations on the email_history_active_workspace_type_idx index, occurring approximately every 15 minutes. These errors appeared in the logs as:

ERROR: duplicate key value violates unique constraint "email_history_active_workspace_type_idx" (SQLSTATE 23505)

The previous code attempted to create a BillingEmailHistory record and then caught the constraint violation error, but this approach still generated error logs even when the constraint violation was properly handled.

Solution

Changed the approach to:

  1. First check if an active BillingEmailHistory already exists for the workspace and email type
  2. Only create a new record if none exists
  3. Remove the error handling for constraint violations since they won't occur anymore

This prevents the constraint violation from happening in the first place, eliminating the error logs while maintaining the same business logic.

Test plan

  • Verify the application compiles successfully
  • Test that billing notifications are still sent appropriately
  • Confirm that duplicate billing notifications are still prevented
  • Monitor logs to ensure constraint violation errors no longer appear

🤖 Generated with Claude Code

Replace try-catch approach with explicit existence check before creating
BillingEmailHistory records to prevent unique constraint violations.

This eliminates the recurring constraint violation errors that appear
every 15 minutes in the logs while maintaining the same functionality
of preventing duplicate billing notification emails.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2025

⚠️ No Changeset found

Latest commit: d1811f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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