feat: Add agent configuration and cleanup scripts for database migrations

This commit is contained in:
wizardchen
2025-11-05 23:18:44 +08:00
parent ae9d0778e9
commit 4fa3adbf3b
126 changed files with 22506 additions and 629 deletions
+18 -1
View File
@@ -64,9 +64,10 @@ func (r *modelRepository) List(
// Update updates a model
func (r *modelRepository) Update(ctx context.Context, m *types.Model) error {
// Use Select to explicitly update all fields, including zero values like false
return r.db.WithContext(ctx).Debug().Model(&types.Model{}).Where(
"id = ? AND tenant_id = ?", m.ID, m.TenantID,
).Updates(m).Error
).Select("*").Updates(m).Error
}
// Delete deletes a model
@@ -75,3 +76,19 @@ func (r *modelRepository) Delete(ctx context.Context, tenantID uint, id string)
"id = ? AND tenant_id = ?", id, tenantID,
).Delete(&types.Model{}).Error
}
// ClearDefaultByType clears the default flag for all models of a specific type
// This is a batch operation that updates all matching records in one query
func (r *modelRepository) ClearDefaultByType(ctx context.Context, tenantID uint, modelType types.ModelType, excludeID string) error {
query := r.db.WithContext(ctx).Model(&types.Model{}).Where(
"tenant_id = ? AND type = ? AND is_default = ?", tenantID, modelType, true,
)
// If excludeID is provided, exclude that model from the update
if excludeID != "" {
query = query.Where("id != ?", excludeID)
}
// Batch update: set is_default to false for all matching records
return query.Update("is_default", false).Error
}