fix: populate payment_mode in organization search results#1491
fix: populate payment_mode in organization search results#1491rohilsurana merged 9 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a computed Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
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 (1)
internal/store/postgres/org_billing_repository.go (1)
299-302: Normalizeprovider_idbefore classification to avoid whitespace edge cases.
provider_id = ''misses values like' ', which would currently be treated aspostpaid. Consider trimming + nullifying before the CASE check.♻️ Suggested SQL expression hardening
- goqu.L(fmt.Sprintf( - "CASE WHEN %s.provider_id IS NULL OR %s.provider_id = '' THEN 'prepaid' ELSE 'postpaid' END", - TABLE_BILLING_CUSTOMERS, TABLE_BILLING_CUSTOMERS, - )).As(COLUMN_PAYMENT_MODE), + goqu.L(fmt.Sprintf( + "CASE WHEN NULLIF(BTRIM(%s.provider_id), '') IS NULL THEN 'prepaid' ELSE 'postpaid' END", + TABLE_BILLING_CUSTOMERS, + )).As(COLUMN_PAYMENT_MODE),
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4faa3096-b11e-42dd-9b86-08d017088a09
📒 Files selected for processing (1)
internal/store/postgres/org_billing_repository.go
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/store/postgres/org_billing_repository_test.go (1)
29-44:⚠️ Potential issue | 🟡 MinorMissing targeted regression cases for
payment_modefilter/group-by.The updated expectations include
payment_mode, but there is no explicit test case for filtering bypayment_modeor grouping bypayment_mode. Given this PR’s scope, those two scenarios should be asserted directly.Suggested additions
+ { + name: "query with payment_mode filter", + rqlQuery: &rql.Query{ + Filters: []rql.Filter{{Name: "payment_mode", Operator: "eq", Value: "postpaid"}}, + Limit: 10, Offset: 0, + }, + // wantSQL / wantParameters for payment_mode predicate + wantErr: false, + }, ... + { + name: "group by payment_mode", + rqlQuery: &rql.Query{GroupBy: []string{"payment_mode"}}, + // wantSQL / wantParameters for GROUP BY "payment_mode" + wantErr: false, + },Also applies to: 147-164
🧹 Nitpick comments (1)
internal/store/postgres/org_billing_repository_test.go (1)
24-106: Consider reducing duplicated full SQL literals in test cases.These long repeated SQL strings are hard to maintain and easy to desync when query internals change. A shared base SQL fragment/helper would keep these tests easier to update and less error-prone.
Also applies to: 152-161
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 65ab0b83-b0df-423f-b1a5-9f8b69cbaa60
📒 Files selected for processing (1)
internal/store/postgres/org_billing_repository_test.go
Pull Request Test Coverage Report for Build 23790959167Details
💛 - Coveralls |
Compute payment_mode as a derived column in the org billing search query based on billing_customers.provider_id: orgs without a billing provider are "prepaid", orgs with one are "postpaid". The field was defined in proto and wired through all layers but never selected in the SQL query, so it always returned empty.
Postpaid if billing_customers.credit_min is defined and positive (customer has a credit limit), prepaid otherwise.
Add a GENERATED ALWAYS STORED column on billing_customers that derives payment_mode from credit_min (negative = postpaid, else prepaid). The query now reads the column directly instead of computing it inline.
d91103d to
5f56f8b
Compare
Summary
payment_modeas a derived SQL column frombilling_customers.provider_id— no schema migration neededWhat changed
internal/store/postgres/org_billing_repository.go:COLUMN_PAYMENT_MODEconstantCASEexpression ingetSubQuery()that derives payment mode frombilling_customers.provider_id:provider_id IS NULLor empty →"prepaid"(offline/no billing provider)provider_idpresent →"postpaid"(registered with Stripe/billing provider)payment_modeto data query selects, supported filters, and group-by keysContext
The
payment_modefield was added to the proto contract and wired through all Go layers (handler, service model, repository struct) in #877 but the SQL query never selected it, so it always returned empty.Test plan
go build ./...passes/admin/v1beta1/organizations/search—payment_modefield returns"prepaid"or"postpaid"for each orgpayment_modeworks