Skip to content

fix(billing): include plans without products in plan listings - #1834

Merged
rohilsurana merged 3 commits into
mainfrom
fix/list-plans-without-products
Aug 4, 2026
Merged

fix(billing): include plans without products in plan listings#1834
rohilsurana merged 3 commits into
mainfrom
fix/list-plans-without-products

Conversation

@rohilsurana

@rohilsurana rohilsurana commented Aug 3, 2026

Copy link
Copy Markdown
Member

What

BillingPlanRepository.ListWithProducts INNER JOINed billing_products on plan.id = ANY(product.plan_ids), so any plan with no products was dropped from the result. UpsertPlans allows creating a plan with an empty product set, so such plans can exist. This switches the join to a LEFT JOIN so those plans are returned.

  • INNER JOIN -> LEFT JOIN in ListWithProducts.
  • The product columns on PlanProductRow become pointers, because a left join leaves them null for a plan with no products. getProduct dereferences them.
  • The row loop skips appending a product when product_id is null, and always stores the accumulated plan back into the map (this also fixes a latent store-back bug where a multi-product plan could lose products after the first).
  • plan_deleted_at was selected from the product table by mistake, so a plan could report its product's deletion time as its own. It now comes from the plans table.

Why

This affects both FrontierService.ListPlans and, once #1830 lands, AdminService.ListAllPlans. An admin listing (and the future BillingPlan reconcile export) must be able to see every plan, including a misconfigured one with no products, so it can be reported or fixed.

Testing

  • go build ./..., go vet, and golangci-lint are clean.
  • The SQL change needs a live Postgres, so it is not exercised by unit tests. A repository test that creates a product-less plan and asserts it is listed should follow (the harness exists in billing_product_repository_test.go).

Closes #1832.

@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview Aug 4, 2026 6:20am

@coderabbitai

coderabbitai Bot commented Aug 3, 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 Plus

Run ID: e57af394-faad-4939-bb54-2522441b0a52

📥 Commits

Reviewing files that changed from the base of the PR and between fade520 and 81de944.

📒 Files selected for processing (2)
  • internal/store/postgres/billing_plan_repository.go
  • internal/store/postgres/null_converters.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/store/postgres/billing_plan_repository.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Billing plans without an associated product are now retained and displayed correctly.
    • Plan deletion information is preserved accurately when retrieving billing plans.
    • Products are only included when valid product details are available.

Walkthrough

Changes

Billing plan listing

Layer / File(s) Summary
Nullable product mapping
internal/store/postgres/billing_plan_repository.go, internal/store/postgres/null_converters.go
PlanProductRow now represents nullable product fields with pointers. getProduct converts nullable values to zero values.
Productless plan query handling
internal/store/postgres/billing_plan_repository.go
ListWithProducts uses a left join, selects the plan deletion timestamp, and retains plans without products. It appends products only when a product ID exists.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • #1831: Both changes update ListWithProducts and product-column mapping, including the source of plan_deleted_at.

Suggested reviewers: anujk14, amangit07

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements the LEFT JOIN and nullable product handling, but it does not include the required Postgres integration test for a product-less plan. Add a Postgres integration test that verifies ListPlans and ListAllPlans return a plan with no products.
✅ Passed checks (1 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed All changes support product-less plan listing and nullable product-row handling required by issue #1832.

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.

@coveralls

coveralls commented Aug 3, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30882789189

Coverage decreased (-0.01%) to 47.537%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: 28 uncovered changes across 1 file (0 of 28 lines covered, 0.0%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
internal/store/postgres/billing_plan_repository.go 28 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
internal/store/postgres/billing_plan_repository.go 1 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 39262
Covered Lines: 18664
Line Coverage: 47.54%
Coverage Strength: 15.41 hits per line

💛 - Coveralls

@rohilsurana
rohilsurana marked this pull request as ready for review August 4, 2026 06:08
@AmanGIT07
AmanGIT07 requested a review from anujk14 August 4, 2026 06:09
@rohilsurana
rohilsurana enabled auto-merge (squash) August 4, 2026 06:11
Comment thread internal/store/postgres/billing_plan_repository.go Outdated
@rohilsurana
rohilsurana merged commit ad5e9a5 into main Aug 4, 2026
8 checks passed
@rohilsurana
rohilsurana deleted the fix/list-plans-without-products branch August 4, 2026 06:25
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.

bug(billing): ListAllPlans and ListPlans omit plans that have no products

3 participants