Skip to content

feat: enforce gathering invoice uniqueness - #3772

Merged
turip merged 2 commits into
mainfrom
feat/enforce-gathering-invoice-uniqueness
Jan 13, 2026
Merged

turip merged 2 commits into
mainfrom
feat/enforce-gathering-invoice-uniqueness

Conversation

@turip

@turip turip commented Jan 13, 2026 •

Copy link
Copy Markdown
Member

Overview

Let's mandate on a db schema level that there can be only one gathering invoice per customer per currency. The code have already enforced it, but let's have this constraint in the db too. (validated all of our deployments that this is true)

Summary by CodeRabbit

  • Bug Fixes
    • Added database constraint to prevent duplicate gathering invoices for the same customer and currency, enhancing data integrity.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a partial unique index on the BillingInvoice table to enforce database-level uniqueness of gathering invoices per customer and currency. The change includes the schema definition and corresponding up/down migration scripts.

Changes

Cohort / File(s) Summary
Schema Definition
openmeter/ent/schema/billing.go
Adds unique index on (namespace, customer_id, currency) with conditions for non-deleted rows where status = 'gathering'
Database Migrations
tools/migrate/migrations/20260113121259_gathering-invoice-unique.up.sql, tools/migrate/migrations/20260113121259_gathering-invoice-unique.down.sql
Up migration creates the partial unique index; down migration drops it

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • openmeterio/openmeter#3512: Also modifies BillingInvoice indexes in the schema, adding timestamp-related non-unique indexes alongside these gathering invoice uniqueness constraints.

Suggested reviewers

  • chrisgacsal
  • hekike
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'enforce gathering invoice uniqueness' clearly and concisely describes the main change: adding a database constraint to ensure only one gathering invoice exists per customer per currency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/enforce-gathering-invoice-uniqueness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@turip turip added release-note/misc Miscellaneous changes area/billing labels Jan 13, 2026
@turip
turip marked this pull request as ready for review January 13, 2026 12:46
@turip
turip requested a review from a team as a code owner January 13, 2026 12:46
turip added 2 commits January 13, 2026 13:46
We already have this implicitly, but let's make this a db constraint
too.
@turip
turip force-pushed the feat/enforce-gathering-invoice-uniqueness branch from 2fa1473 to 62e1052 Compare January 13, 2026 12:46
@turip
turip enabled auto-merge (squash) January 13, 2026 12:46
@turip
turip merged commit 0531000 into main Jan 13, 2026
24 checks passed
@turip
turip deleted the feat/enforce-gathering-invoice-uniqueness branch January 13, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants