Repository navigation
refactor(ledger): add compatible credit filter storage - #5172
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: openmeterio/openmeter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (15)
📒 Files selected for processing (12)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
5739632 to
8304389
Compare
8304389 to
ade3099
Compare
| // ChargeCreditPurchase is the predicate function for chargecreditpurchase builders. | ||
| type ChargeCreditPurchase func(*sql.Selector) | ||
|
|
||
| // ChargeCreditPurchaseOrErr calls the predicate only if the error is not nit. |
There was a problem hiding this comment.
The new comment says the error is “not nit” rather than “not nil,” so it does not accurately describe the helper. The same typo appears on LedgerSubAccountRouteOrErr at line 400. This violates the repository requirement that comments and docstrings clearly explain behavior and must be corrected before merging.
| // ChargeCreditPurchaseOrErr calls the predicate only if the error is not nit. | |
| // ChargeCreditPurchaseOrErr calls the predicate only if the error is not nil. |
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/ent/db/predicate/predicate.go
Line: 203
Comment:
**Predicate comment has typo**
The new comment says the error is “not nit” rather than “not nil,” so it does not accurately describe the helper. The same typo appears on `LedgerSubAccountRouteOrErr` at line 400. This violates the repository requirement that comments and docstrings clearly explain behavior and must be corrected before merging.
```suggestion
// ChargeCreditPurchaseOrErr calls the predicate only if the error is not nil.
```
**Context Used:** AGENTS.md ([source](https://github.com/openmeterio/openmeter/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| type plain Filters | ||
| return json.Marshal(plain(filters)) |
There was a problem hiding this comment.
The v1 codec aliases the full Filters domain type for both encoding and decoding. If a future restriction field is added to Filters, it will automatically be written and accepted with schema_version: 1, while older v1 readers will reject it as unknown. This breaks mixed-version compatibility and the documented requirement that v1 reject unknown restriction fields. Keep a dedicated feature-only v1 payload so extending the domain type cannot silently change the v1 wire format.
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/ledger/crediteligibility/storage.go
Line: 16-17
Comment:
**V1 format is not frozen**
The v1 codec aliases the full `Filters` domain type for both encoding and decoding. If a future restriction field is added to `Filters`, it will automatically be written and accepted with `schema_version: 1`, while older v1 readers will reject it as unknown. This breaks mixed-version compatibility and the documented requirement that v1 reject unknown restriction fields. Keep a dedicated feature-only v1 payload so extending the domain type cannot silently change the v1 wire format.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Introduces nullable, versioned JSON storage for credit filters on grants and ledger routes. Writers populate both representations; readers continue using the existing feature columns. Feature validation and normalization move into
ledger/crediteligibilitywithout changing their behavior.Stack: this PR → #5173 → #5174. The follow-up drafts have not yet been rebased onto this revision. Merge and deploy in order. Deploy this release to every API instance and worker before applying step 2's backfill. Routing keys, feature matching, and the external API stay unchanged.
Validation: PostgreSQL account, credit-purchase, and legacy-lineage tests; JSON round-trip and unknown-restriction tests; scoped lint.
Legacy lineage storage and its existing feature reads and writes remain unchanged.
The persisted
Filterstype carriesVersiondirectly. Its JSON codec currently supports only v1, preserves the selected version through normalization and JSON round trips, and rejects missing or unsupported versions. Both new-row writers explicitly select v1.The migration and dual-write behavior appear operationally safe, but the repository-required predicate documentation correction remains blocking and the v1 codec should retain an explicit frozen payload.
Fix with agent prompt
Summary
This PR introduces nullable, versioned JSON storage for credit filters while retaining legacy feature columns for reads and dual writes during the staged rollout.
ledger/crediteligibility.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR W[Credit purchase or route writer] --> N[Normalize feature filters] N --> J[Write versioned filters JSONB] N --> L[Write legacy feature column] R[Current readers] --> L F[Future staged readers] --> JReviews (6) · Last reviewed commit: "refactor(ledger): simplify filter JSON e..."
Summary by CodeRabbit
New Features
Compatibility
Documentation