Skip to content

chore: invoke bulk invoice schema migration#4729

Draft
turip wants to merge 2 commits into
mainfrom
feat/invoke-bulk-invoice-schema-level-2-migration
Draft

chore: invoke bulk invoice schema migration#4729
turip wants to merge 2 commits into
mainfrom
feat/invoke-bulk-invoice-schema-level-2-migration

Conversation

@turip

@turip turip commented Jul 16, 2026

Copy link
Copy Markdown
Member

Overview

Invoke the set-based multi-customer invoice migration function for existing schema-level-1 invoices.

This PR is stacked on top of #4727, which introduces om_func_migrate_customer_invoices_to_schema_level_2_bulk(TEXT[]).

Changes

  • Lock all existing billing customer-lock rows for the duration of the migration.
  • Materialize the distinct locked customers that still have schema-level-1 invoices in a transaction-local temporary table.
  • Pass the complete customer-ID array to the bulk migration function in a single call.
  • Keep the migration irreversible because migrated invoice storage cannot be safely reconstructed as schema level 1.

This layer intentionally contains no detailed-line copying logic or explicit ANALYZE. The temporary table is dropped automatically when the transaction commits.

Validation

  • atlas migrate --env local lint --latest 1
  • atlas migrate validate --env local
  • git diff --check

Greptile Summary

This PR migrates existing invoices to schema level 2 in one transaction. The main changes are:

  • Locks existing billing customer-lock rows during migration.
  • Materializes affected customer IDs in a temporary table.
  • Calls the bulk invoice migration function once with the complete array.
  • Marks the migration as irreversible.

Confidence Score: 5/5

No additional merge-blocking issue requires a separate code change.

  • No distinct production failure was found beyond the issue already identified for this migration path.

Important Files Changed

Filename Overview
tools/migrate/migrations/20260717062142_migrate_invoices_to_schema_level_2.up.sql Adds the transactional lock, temporary customer set, and bulk migration call.
tools/migrate/migrations/20260717062142_migrate_invoices_to_schema_level_2.down.sql Documents that migrated invoice data cannot be restored safely.
tools/migrate/migrations/atlas.sum Registers the new forward migration checksum.

Reviews (3): Last reviewed commit: "chore: invoke bulk invoice schema migrat..." | Re-trigger Greptile

Context used:

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 41cb7b64-0b61-4f5f-9837-ce668bb8385a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/invoke-bulk-invoice-schema-level-2-migration

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.

Comment on lines +10 to +13
SELECT DISTINCT l.customer_id::TEXT
FROM billing_customer_locks l
JOIN billing_invoices i
ON i.namespace = l.namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Missing Lock Rows Skip Invoices

The inner join excludes every schema-level-1 invoice whose customer has no billing_customer_locks row. Because these rows are created lazily and invoices predate the lock table, an untouched historical customer can be omitted, leaving its invoices at schema level 1 after this irreversible migration.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tools/migrate/migrations/20260716150457_migrate_invoices_to_schema_level_2.up.sql
Line: 10-13

Comment:
**Missing Lock Rows Skip Invoices**

The inner join excludes every schema-level-1 invoice whose customer has no `billing_customer_locks` row. Because these rows are created lazily and invoices predate the lock table, an untouched historical customer can be omitted, leaving its invoices at schema level 1 after this irreversible migration.

**Context Used:** AGENTS.md ([source](https://app.greptile.com/openmeter/github/openmeterio/openmeter/-/custom-context?memory=eb020e3b-8e3b-45ea-a8b7-4006b2b2065b))

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

@turip
turip force-pushed the feat/invoke-bulk-invoice-schema-level-2-migration branch from 331f0ae to 308c9d8 Compare July 16, 2026 15:17
@turip
turip force-pushed the feat/bulk-invoice-schema-level-2-function branch from 17c8e28 to 840a665 Compare July 17, 2026 04:20
@turip
turip force-pushed the feat/invoke-bulk-invoice-schema-level-2-migration branch from 308c9d8 to a6d5217 Compare July 17, 2026 04:22
Base automatically changed from feat/bulk-invoice-schema-level-2-function to main July 17, 2026 12:54
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.

1 participant