fix(loader): disable config file rewrite during startup
Some checks failed
CI / build-and-test (push) Failing after -32m45s
Some checks failed
CI / build-and-test (push) Failing after -32m45s
* migrate legacy schemas in memory only * log hint to use amcs-migrate-config for persistence
This commit is contained in:
@@ -40,16 +40,14 @@ func LoadWithLogger(explicitPath string, log *slog.Logger) (*Config, string, err
|
||||
}
|
||||
|
||||
if len(applied) > 0 {
|
||||
if err := rewriteConfigFile(path, data, raw); err != nil {
|
||||
return nil, path, err
|
||||
}
|
||||
if log != nil {
|
||||
for _, step := range applied {
|
||||
log.Warn("config migrated",
|
||||
log.Warn("config migrated in memory",
|
||||
slog.String("path", path),
|
||||
slog.Int("from_version", step.From),
|
||||
slog.Int("to_version", step.To),
|
||||
slog.String("describe", step.Describe),
|
||||
slog.String("hint", "persist with amcs-migrate-config"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -81,22 +79,6 @@ func decodeTyped(raw map[string]any) (Config, error) {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func rewriteConfigFile(path string, original []byte, migrated map[string]any) error {
|
||||
backupPath := fmt.Sprintf("%s.bak.%d", path, time.Now().Unix())
|
||||
if err := os.WriteFile(backupPath, original, 0o600); err != nil {
|
||||
return fmt.Errorf("write backup %q: %w", backupPath, err)
|
||||
}
|
||||
|
||||
out, err := yaml.Marshal(migrated)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal migrated config: %w", err)
|
||||
}
|
||||
if err := os.WriteFile(path, out, 0o600); err != nil {
|
||||
return fmt.Errorf("write migrated config %q: %w", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResolvePath(explicitPath string) string {
|
||||
if path := strings.TrimSpace(explicitPath); path != "" {
|
||||
if path != ".yaml" && path != ".yml" {
|
||||
|
||||
Reference in New Issue
Block a user