mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
refactor(api): split Provider into ProviderGroup and APIKey models
Restructure the provider management system by separating the monolithic Provider model into two distinct entities: - ProviderGroup: defines shared upstream configuration (type, base_url, google settings, models, status) - APIKey: represents individual credentials within a group (api_key, weight, status, auto_ban, ban settings) This change also updates: - Binding model to reference GroupID instead of RouteGroup string - All CRUD handlers for the new provider-group and api-key endpoints - Sync service to rebuild provider snapshots from joined tables - Model registry to aggregate capabilities across group/key pairs - Access handler to validate namespace existence and subset constraints - Migration importer to handle the new schema structure - All related tests to use the new model relationships BREAKING CHANGE: Provider API endpoints replaced with /provider-groups and /api-keys endpoints; Binding.RouteGroup replaced with Binding.GroupID
This commit is contained in:
@@ -58,22 +58,31 @@ func TestModelRegistry_RefreshAndRollback(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.Provider{}, &model.Binding{}, &model.Model{}); err != nil {
|
||||
if err := db.AutoMigrate(&model.ProviderGroup{}, &model.APIKey{}, &model.Binding{}, &model.Model{}); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
if err := db.Create(&model.Provider{
|
||||
Name: "p1",
|
||||
Type: "openai",
|
||||
Group: "rg",
|
||||
Models: "gpt-4o-mini",
|
||||
Status: "active",
|
||||
group := model.ProviderGroup{
|
||||
Name: "rg",
|
||||
Type: "openai",
|
||||
BaseURL: "https://api.openai.com/v1",
|
||||
Models: "gpt-4o-mini",
|
||||
Status: "active",
|
||||
}
|
||||
if err := db.Create(&group).Error; err != nil {
|
||||
t.Fatalf("create provider group: %v", err)
|
||||
}
|
||||
if err := db.Create(&model.APIKey{
|
||||
GroupID: group.ID,
|
||||
APIKey: "k",
|
||||
Status: "active",
|
||||
}).Error; err != nil {
|
||||
t.Fatalf("create provider: %v", err)
|
||||
t.Fatalf("create api key: %v", err)
|
||||
}
|
||||
if err := db.Create(&model.Binding{
|
||||
Namespace: "ns",
|
||||
PublicModel: "m",
|
||||
RouteGroup: "rg",
|
||||
GroupID: group.ID,
|
||||
Weight: 1,
|
||||
SelectorType: "exact",
|
||||
SelectorValue: "gpt-4o-mini",
|
||||
Status: "active",
|
||||
|
||||
Reference in New Issue
Block a user