Skip to content

chore: flattening model columns#591

Merged
zijiren233 merged 2 commits into
labring:mainfrom
zijiren233:model-embed2
May 25, 2026
Merged

chore: flattening model columns#591
zijiren233 merged 2 commits into
labring:mainfrom
zijiren233:model-embed2

Conversation

@zijiren233
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.UsageContext and AsyncUsageInfo.Price/Usage/UsageContext from serializer:fastjson;type:text to gorm:"embedded" column layouts.
  • Remove the standalone Log.ServiceTier plumbing and rely on UsageContext.ServiceTier instead (propagated through record/batch APIs and tests).
  • Expand CSV log export to include resolution, native_resolution, and quality, 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 thread core/model/async_usage.go
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 thread core/model/async_usage.go
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 thread core/model/log.go
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"`
@zijiren233 zijiren233 merged commit faea49f into labring:main May 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants