Skip to content

feat: default billing invoices to schema level 2 - #4709

Merged
turip merged 1 commit into
mainfrom
feat/billing-invoice-schema-level-2
Jul 14, 2026
Merged

turip merged 1 commit into
mainfrom
feat/billing-invoice-schema-level-2

Conversation

@turip

@turip turip commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Summary

  • default newly written billing invoices to schema level 2 in application and Ent configuration
  • add one Atlas migration that updates the database defaults without eagerly migrating existing invoices
  • replace the lazy customer invoice migration function so deprecated detailed-line annotations and metadata are not copied
  • retain the unused detailed-line columns while marking them deprecated in Ent

Impact

New invoices use the schema-level-2 representation by default. Existing schema-level-1 invoices remain untouched until the existing customer-lock migration trigger runs.

The migration updates both the billing_invoices.schema_level default and the singleton write-schema-level record. Its function replacement preserves the current lazy migration behavior and discount copying, while leaving deprecated annotations and metadata behind.

Validation

  • make test-nocache
  • focused billing, charge adapter, schema migration, and migration up/down tests
  • focused go vet for billing and billing tests
  • Atlas schema diff, migration lint, and checksum validation

Atlas reports only the existing column-alignment warning for migration 20260709134600; the new migration has no diagnostics.

Summary by CodeRabbit

  • New Features

    • New invoices now use schema level 2 by default.
    • Added migration support to upgrade existing invoices and preserve eligible detailed invoice data.
  • Bug Fixes

    • Deprecated detailed-line annotations and metadata are now clearly identified and removed during migration.
  • Tests

    • Updated invoice processing and migration coverage for schema level 2 behavior.

Greptile Summary

This PR moves billing invoices to schema level 2 by default. The main changes are:

  • Application and Ent defaults now write new invoices at schema level 2.
  • A migration updates the database default and singleton write-schema-level row.
  • The lazy invoice migration stops copying deprecated detailed-line annotations and metadata.
  • Ent generated code reflects the deprecated detailed-line fields.

Confidence Score: 5/5

The changed flow looks mergeable after tightening one migration test.

  • The runtime default and database migration paths are consistent.
  • The lazy migration update matches the intended deprecated-field behavior.
  • One test can miss copied deprecated column values because the query no longer selects them.

test/billing/schemamigration_test.go

Important Files Changed

Filename Overview
openmeter/billing/adapter/schemalevel.go Changes the application fallback invoice write schema level from 1 to 2.
openmeter/ent/schema/billing.go Changes the Ent invoice schema-level default to 2.
pkg/framework/entutils/mixins.go Adds optional deprecation support for metadata and annotations mixins.
tools/migrate/migrations/20260714140423_set_billing_invoice_schema_level_2.up.sql Updates schema-level defaults and replaces the lazy migration function.
tools/migrate/migrations/20260714140423_set_billing_invoice_schema_level_2.down.sql Restores schema-level defaults and the previous lazy migration function.
test/billing/schemamigration_test.go Adds migration coverage for deprecated detailed-line fields, but the query does not select those fields.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/billing/schemamigration_test.go:249-253
**Deprecated Columns Stay Unchecked**

This query uses the default Ent column list, but the same PR marks `annotations` and `metadata` deprecated, so those columns are no longer selected by default. If the SQL function accidentally copies those values, this test still reads empty struct fields and passes without proving the database columns were cleared.

Reviews (1): Last reviewed commit: "feat: default billing invoices to schema..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@turip
turip requested a review from a team as a code owner July 14, 2026 14:20
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fd4b88ea-1e66-4c8c-840e-23dcbee2f141

📥 Commits

Reviewing files that changed from the base of the PR and between 9d0d3a4 and 9f2a634.

⛔ Files ignored due to path filters (8)
  • openmeter/ent/db/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeerundetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeerundetailedline/chargeflatfeerundetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedrundetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedrundetailedline/chargeusagebasedrundetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (9)
  • openmeter/billing/adapter/schemalevel.go
  • openmeter/billing/models/stddetailedline/mixin.go
  • openmeter/billing/service/invoiceupdate_test.go
  • openmeter/ent/schema/billing.go
  • pkg/framework/entutils/mixins.go
  • test/billing/schemamigration_test.go
  • test/billing/suite.go
  • tools/migrate/migrations/20260714140423_set_billing_invoice_schema_level_2.down.sql
  • tools/migrate/migrations/20260714140423_set_billing_invoice_schema_level_2.up.sql

📝 Walkthrough

Walkthrough

Invoice schema defaults now use level 2. Migration SQL backfills qualifying detailed invoice records per customer, while Ent mixins mark unsupported metadata and annotations as deprecated. Billing tests and migration verification are updated for the new schema level and data cleanup.

Changes

Invoice schema level 2

Layer / File(s) Summary
Schema level defaults and test setup
openmeter/billing/adapter/schemalevel.go, openmeter/ent/schema/billing.go, test/billing/suite.go, openmeter/billing/service/invoiceupdate_test.go
Default invoice write and persisted schema levels change from 1 to 2, and billing fixtures and suite setup use the new level.
Detailed-line deprecation metadata
pkg/framework/entutils/mixins.go, openmeter/billing/models/stddetailedline/mixin.go
Metadata and annotation mixins support deprecation reasons, which are configured for detailed invoice lines.
Invoice migration and verification
tools/migrate/migrations/20260714140423_set_billing_invoice_schema_level_2.*.sql, test/billing/schemamigration_test.go
Migration functions backfill level-2 detailed records and update invoice schema levels; tests verify migrated detailed lines have empty annotations and metadata.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MigrationCaller
  participant InvoiceMigrationFunction
  participant DetailedLineTables
  participant BillingInvoices
  MigrationCaller->>InvoiceMigrationFunction: migrate customer invoices to schema level 2
  InvoiceMigrationFunction->>DetailedLineTables: insert detailed lines and discounts
  InvoiceMigrationFunction->>BillingInvoices: update schema_level from 1 to 2
  BillingInvoices-->>MigrationCaller: return updated invoice count
Loading

Possibly related PRs

Suggested labels: area/billing, release-note/feature

Suggested reviewers: chrisgacsal, tothandras

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: billing invoices now default to schema level 2.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/billing-invoice-schema-level-2

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.

@turip turip added the release-note/feature Release note: Exciting New Features label Jul 14, 2026
Comment thread test/billing/schemamigration_test.go Resolved
@turip
turip enabled auto-merge (squash) July 14, 2026 14:26
@turip
turip merged commit 77289b4 into main Jul 14, 2026
28 of 29 checks passed
@turip
turip deleted the feat/billing-invoice-schema-level-2 branch July 14, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants