chore: flattening model columns#591
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR flattens previously JSON-serialized model fields into dedicated DB columns (via GORM embedded) so usage context and async-usage data can be stored/queryable as first-class columns, and updates log export to include the expanded usage context fields.
Changes:
- Convert
Log.UsageContextandAsyncUsageInfo.Price/Usage/UsageContextfromserializer:fastjson;type:texttogorm:"embedded"column layouts. - Remove the standalone
Log.ServiceTierplumbing and rely onUsageContext.ServiceTierinstead (propagated through record/batch APIs and tests). - Expand CSV log export to include
resolution,native_resolution, andquality, with new unit test coverage.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| core/model/usage.go | Adds GORM column sizing metadata for flattened UsageContext fields. |
| core/model/log.go | Stores UsageContext as embedded columns; removes standalone ServiceTier field/param usage. |
| core/model/log_test.go | Updates tests for new RecordConsumeLog signature and ServiceTier location. |
| core/model/batch.go | Removes serviceTier parameter when batching log persistence. |
| core/model/async_usage.go | Flattens async usage info storage and adds update helper for selected fields. |
| core/controller/log_export.go | Exports full usage context fields into CSV output. |
| core/controller/log_export_test.go | Adds CSV parsing helpers + test asserting usage context columns are exported. |
| core/common/consume/record.go | Updates batch log recording call to match new signature. |
| core/go.sum | Adds missing kin-openapi go.mod checksum entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+40
to
56
| Price Price `gorm:"embedded" json:"price"` | ||
| UpstreamID string `gorm:"type:varchar(256);index" json:"upstream_id"` | ||
| Status AsyncUsageStatus `gorm:"index;default:1" json:"status"` | ||
| Usage Usage `gorm:"embedded" json:"usage"` | ||
| UsageContext UsageContext `gorm:"embedded" json:"usage_context,omitempty"` | ||
| DisableResolutionFuzzyMatch bool ` json:"disable_resolution_fuzzy_match,omitempty"` | ||
| Amount Amount `gorm:"embedded" json:"amount,omitempty"` | ||
| Error string `gorm:"type:text" json:"error,omitempty"` | ||
| RetryCount int ` json:"retry_count"` | ||
| BalanceConsumed bool ` json:"balance_consumed"` | ||
| ProcessingToken string `gorm:"size:64;index" json:"-"` | ||
| NextPollAt time.Time `gorm:"index" json:"next_poll_at"` | ||
| CreatedAt time.Time ` json:"created_at"` | ||
| UpdatedAt time.Time ` json:"updated_at"` | ||
| } | ||
|
|
||
| func CreateAsyncUsageInfo(info *AsyncUsageInfo) error { |
Comment on lines
+270
to
+280
| var namer schema.Namer = schema.NamingStrategy{IdentifierMaxLength: 64} | ||
| if LogDB != nil && LogDB.NamingStrategy != nil { | ||
| namer = LogDB.NamingStrategy | ||
| } | ||
|
|
||
| var schemaCache sync.Map | ||
|
|
||
| s, err := schema.Parse(&AsyncUsageInfo{}, &schemaCache, namer) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("parse async usage schema: %w", err) | ||
| } |
Comment on lines
69
to
72
| Price Price `gorm:"embedded" json:"price,omitempty"` | ||
| Usage Usage `gorm:"embedded" json:"usage,omitempty"` | ||
| UsageContext UsageContext `gorm:"serializer:fastjson;type:text" json:"usage_context,omitempty"` | ||
| UsageContext UsageContext `gorm:"embedded" json:"usage_context,omitempty"` | ||
| Amount Amount `gorm:"embedded" json:"amount,omitempty"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.