-
make devstarts full stack (frontend:3000 + backend:8080) - http://localhost:3000/workspace/providers verifies API Key page
- Fork + feature branch:
git checkout -b 11-17-feat-option-disable-key
ui/app/workspace/providers/views/modelProviderKeysTableView.tsx:
<TableCell>
<Switch
checked={isKeyEnabled}
disabled={!hasUpdateProviderAccess}
onCheckedChange={(checked) => {
updateProvider({
...provider,
keys: provider.keys.map((k, i) =>
i === index ? { ...k, enabled: checked } : k
),
})
.unwrap()
.then(() => {
toast.success(`Key ${checked ? "enabled" : "disabled"} successfully`);
})
.catch((err) => {
toast.error("Failed to update key", { description: getErrorMessage(err) });
});
}}
/>
</TableCell>
→ This is a table for the API Key. I have done about the UI and the type of schema in front-end.
framework/configstore/tables/key.go:
type TableKey struct {
Enabled *bool `gorm:"default:true" json:"enabled,omitempty"`
}
if k.Enabled == nil {
enabled := true // DB default
k.Enabled = &enabled
}
(In functions of BeforeSave and AfterFind)
→ SQLite schema,no enabled column; migration needed.
core/bifrost.go:
// Skip disabled keys (default enabled when nil)
if k.Enabled != nil && !*k.Enabled {
continue
}
→ The logic of provider selector
The code in back-end seems that it could be able to set up as enabled or disabled for front-end.
However, the workflow and the codeRabbit on GitHub was kept telling me there were something better to improve(like: migration the data column manually, add log in files core/changelog.md and transports/changelog.md) for the issue in the project. Also, I got the message about the data should migrate manually so I have to write the code in framework/configstore/migrations.go.
if err := migrationAddPluginVersionColumn(ctx, db); err != nil {
return err
}
// migrationAddEnabledColumnToKeyTable adds the enabled column to the config_keys table
func migrationAddEnabledColumnToKeyTable(ctx context.Context, db *gorm.DB) error {
m := migrator.New(db, migrator.DefaultOptions, []*migrator.Migration{{
ID: "add_enabled_column_to_key_table",
Migrate: func(tx *gorm.DB) error {
tx = tx.WithContext(ctx)
mg := tx.Migrator()
// Check if column already exists
if !mg.HasColumn(&tables.TableKey{}, "enabled") {
// Add the column
if err := mg.AddColumn(&tables.TableKey{}, "enabled"); err != nil {
return fmt.Errorf("failed to add enabled column: %w", err)
}
}
// Set default = true for existing rows
if err := tx.Exec("UPDATE config_keys SET enabled = TRUE WHERE enabled IS NULL").Error; err != nil {
return fmt.Errorf("failed to backfill enabled column: %w", err)
}
return nil
},
Rollback: func(tx *gorm.DB) error {
tx = tx.WithContext(ctx)
mg := tx.Migrator()
if mg.HasColumn(&tables.TableKey{}, "enabled") {
if err := mg.DropColumn(&tables.TableKey{}, "enabled"); err != nil {
return fmt.Errorf("failed to drop enabled column: %w", err)
}
}
return nil
},
}})
if err := m.Migrate(); err != nil {
return fmt.Errorf("error running enabled column migration: %s", err.Error())
}
return nil
}
Conclusion:
Since working on this project that I have been followed Coderabbitai and with other contributors in something that I may miss in the whole progressing.
Top comments (0)