Skip to content

Commit

Permalink
fix: aiproxy sql constraint conv to hook (#5219)
Browse files Browse the repository at this point in the history
* fix: constraint conv to hook

* fix: conv json serializer to fastjson

* fix: conv json serializer to fastjson
  • Loading branch information
zijiren233 authored Nov 20, 2024
1 parent f5569ff commit af26adb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions service/aiproxy/model/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ type Channel struct {
TestAt time.Time `json:"test_at"`
BalanceUpdatedAt time.Time `json:"balance_updated_at"`
ModelMapping map[string]string `gorm:"serializer:fastjson;type:text" json:"model_mapping"`
Config ChannelConfig `gorm:"serializer:json;type:text" json:"config"`
Config ChannelConfig `gorm:"serializer:fastjson;type:text" json:"config"`
Other string `json:"other"`
Key string `gorm:"type:text;index" json:"key"`
Name string `gorm:"index" json:"name"`
BaseURL string `gorm:"index" json:"base_url"`
Models []string `gorm:"serializer:json;type:text" json:"models"`
Models []string `gorm:"serializer:fastjson;type:text" json:"models"`
Balance float64 `json:"balance"`
ResponseDuration int64 `gorm:"index" json:"response_duration"`
ID int `gorm:"primaryKey" json:"id"`
Expand Down
16 changes: 10 additions & 6 deletions service/aiproxy/model/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ const (
type Group struct {
CreatedAt time.Time `json:"created_at"`
AccessedAt time.Time `json:"accessed_at"`
ID string `gorm:"primaryKey" json:"id"`
Tokens []*Token `gorm:"foreignKey:GroupID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
Status int `gorm:"default:1;index" json:"status"`
UsedAmount float64 `gorm:"index" json:"used_amount"`
QPM int64 `gorm:"index" json:"qpm"`
RequestCount int `gorm:"index" json:"request_count"`
ID string `gorm:"primaryKey" json:"id"`
Tokens []*Token `gorm:"foreignKey:GroupID" json:"-"`
Status int `gorm:"default:1;index" json:"status"`
UsedAmount float64 `gorm:"index" json:"used_amount"`
QPM int64 `gorm:"index" json:"qpm"`
RequestCount int `gorm:"index" json:"request_count"`
}

func (g *Group) AfterDelete(tx *gorm.DB) (err error) {
return tx.Model(&Token{}).Where("group_id = ?", g.ID).Delete(&Token{}).Error
}

func (g *Group) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion service/aiproxy/model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Token struct {
Name EmptyNullString `gorm:"index;uniqueIndex:idx_group_name;not null" json:"name"`
GroupID string `gorm:"index;uniqueIndex:idx_group_name" json:"group"`
Subnet string `json:"subnet"`
Models []string `gorm:"serializer:json;type:text" json:"models"`
Models []string `gorm:"serializer:fastjson;type:text" json:"models"`
Status int `gorm:"default:1;index" json:"status"`
ID int `gorm:"primaryKey" json:"id"`
Quota float64 `json:"quota"`
Expand Down

0 comments on commit af26adb

Please sign in to comment.