Repository navigation
fix: repair rebased migrations - #4400
Conversation
📝 WalkthroughWalkthroughThis PR adds a single repair migration that backfills schema changes across multiple tables: tax code columns for charges, identity keys for ledger deduplication, metadata flags for charge runs, and a new ledger breakage records table. The down migration is a documented no-op to prevent accidentally dropping valid schema in healthy environments. ChangesSchema Backfill and Ledger Repair
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tools/migrate/migrations/20260520130000_repair_rebased_migrations.up.sql (2)
61-61: ⚡ Quick winConsider formatting the view definition for readability.
The entire view definition is on a single line, which makes it tough to review and maintain. Breaking it into multiple lines would help future developers quickly spot which columns are being selected from each table.
📖 Example formatting
CREATE VIEW "charges_search_v1s" AS SELECT "id", "namespace", "metadata", "created_at", "updated_at", "deleted_at", "name", "description", "annotations", "customer_id", "service_period_from", "service_period_to", "billing_period_from", "billing_period_to", "full_service_period_from", "full_service_period_to", "status", "unique_reference_id", "currency", "managed_by", "subscription_id", "subscription_phase_id", "subscription_item_id", "advance_after", "tax_code_id", "tax_behavior", 'credit_purchase' AS "type" FROM "charge_credit_purchases" UNION ALL SELECT "id", "namespace", "metadata", "created_at", "updated_at", "deleted_at", "name", "description", "annotations", "customer_id", "service_period_from", "service_period_to", "billing_period_from", "billing_period_to", "full_service_period_from", "full_service_period_to", "status", "unique_reference_id", "currency", "managed_by", "subscription_id", "subscription_phase_id", "subscription_item_id", "advance_after", "tax_code_id", "tax_behavior", 'flat_fee' AS "type" FROM "charge_flat_fees" UNION ALL SELECT "id", "namespace", "metadata", "created_at", "updated_at", "deleted_at", "name", "description", "annotations", "customer_id", "service_period_from", "service_period_to", "billing_period_from", "billing_period_to", "full_service_period_from", "full_service_period_to", "status", "unique_reference_id", "currency", "managed_by", "subscription_id", "subscription_phase_id", "subscription_item_id", "advance_after", "tax_code_id", "tax_behavior", 'usage_based' AS "type" FROM "charge_usage_based";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/migrate/migrations/20260520130000_repair_rebased_migrations.up.sql` at line 61, The view definition is on one long line making it unreadable; reformat the SQL in this migration by breaking the CREATE VIEW/SELECT statement into multiple lines: put column lists each on their own lines, place the FROM clauses on separate lines, and separate each UNION ALL block for the three SELECTs (the SELECT from "charge_credit_purchases", the SELECT from "charge_flat_fees", and the SELECT from "charge_usage_based"); preserve the exact column order and keep the literal type aliases ('credit_purchase' AS "type", 'flat_fee' AS "type", 'usage_based' AS "type") unchanged so the view semantics remain identical.
127-127: ⚡ Quick winRemove the redundant unique index on id.
The
idcolumn is already the PRIMARY KEY (line 123), which automatically creates a unique index. Creating an additional unique index here is redundant and wastes storage space.🔧 Suggested fix
CREATE INDEX IF NOT EXISTS "ledgerbreakagerecord_annotations" ON "ledger_breakage_records" USING gin ("annotations"); -CREATE UNIQUE INDEX IF NOT EXISTS "ledgerbreakagerecord_id" ON "ledger_breakage_records" ("id"); CREATE INDEX IF NOT EXISTS "ledgerbreakagerecord_namespace" ON "ledger_breakage_records" ("namespace");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/migrate/migrations/20260520130000_repair_rebased_migrations.up.sql` at line 127, Remove the redundant unique index creation for the id column: delete the CREATE UNIQUE INDEX statement that defines "ledgerbreakagerecord_id" on "ledger_breakage_records" ("id"); the table already has id as PRIMARY KEY (see the existing PRIMARY KEY declaration), so drop this extra index line to avoid duplicate indexing and wasted storage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tools/migrate/migrations/20260520130000_repair_rebased_migrations.up.sql`:
- Line 61: The view definition is on one long line making it unreadable;
reformat the SQL in this migration by breaking the CREATE VIEW/SELECT statement
into multiple lines: put column lists each on their own lines, place the FROM
clauses on separate lines, and separate each UNION ALL block for the three
SELECTs (the SELECT from "charge_credit_purchases", the SELECT from
"charge_flat_fees", and the SELECT from "charge_usage_based"); preserve the
exact column order and keep the literal type aliases ('credit_purchase' AS
"type", 'flat_fee' AS "type", 'usage_based' AS "type") unchanged so the view
semantics remain identical.
- Line 127: Remove the redundant unique index creation for the id column: delete
the CREATE UNIQUE INDEX statement that defines "ledgerbreakagerecord_id" on
"ledger_breakage_records" ("id"); the table already has id as PRIMARY KEY (see
the existing PRIMARY KEY declaration), so drop this extra index line to avoid
duplicate indexing and wasted storage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 27665dde-4fc2-40b8-8702-e7d658ba27c2
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (2)
tools/migrate/migrations/20260520130000_repair_rebased_migrations.down.sqltools/migrate/migrations/20260520130000_repair_rebased_migrations.up.sql
|
thank you! |
Summary
Testing
Summary by CodeRabbit
New Features
Bug Fixes