This commit is contained in:
2026-08-15 23:53:13 +08:00
parent e5b88fcf6c
commit c4b114762b
5 changed files with 288 additions and 12 deletions
+43
View File
@@ -118,6 +118,9 @@ func (r *initializationRepo) SaveConfigurationJSON(ctx context.Context, raw json
nextAdmin.Email.Secret = value.Email.Secret
}
}
if err := refreshDatabaseSources(nextData); err != nil {
return err
}
nextAdmin.ConfigPath = currentAdmin.ConfigPath
dataRaw, err := protojson.MarshalOptions{UseProtoNames: true}.Marshal(nextData)
if err != nil {
@@ -151,6 +154,46 @@ func cloneDataConfig(value *conf.Data) *conf.Data {
return proto.Clone(value).(*conf.Data)
}
func refreshDatabaseSources(value *conf.Data) error {
if value == nil {
return nil
}
if err := refreshDatabaseSource(value.Database); err != nil {
return err
}
for _, database := range value.DatabaseList {
if database == nil || database.Disable {
continue
}
if err := refreshDatabaseSource(database); err != nil {
return err
}
}
return nil
}
func refreshDatabaseSource(database *conf.Data_Database) error {
if database == nil {
return nil
}
hasStructuredConfig := database.Host != "" || database.Port != "" || database.User != "" ||
database.Password != "" || database.Name != "" || database.Config != "" || database.Path != ""
if !hasStructuredConfig {
// A source-only configuration is an intentional escape hatch for custom
// driver DSNs; do not reinterpret it as the structured form.
return nil
}
previousSource := database.Source
database.Source = ""
source, err := databaseDSN(database, "")
if err != nil {
database.Source = previousSource
return err
}
database.Source = source
return nil
}
func durationString(value *durationpb.Duration) string {
if value == nil {
return "0s"