Skip to content

Commit 6b3ff61

Browse files
committed
Check if object implements Migrator before trying to upgrade
Also if one of `--metrics` and `--sources` is not specified and the other is a pg conn str, use the same conn str for both.
1 parent 266dffd commit 6b3ff61

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/cmdopts/cmdconfig.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,21 @@ func (cmd *ConfigUpgradeCommand) Execute([]string) (err error) {
103103
if !opts.IsPgConnStr(uri) {
104104
return fmt.Errorf("cannot upgrade storage %s: %w", uri, errors.ErrUnsupported)
105105
}
106-
m, initErr := newMigratorFunc()
106+
obj, initErr := newMigratorFunc()
107107
if initErr != nil {
108108
return initErr
109109
}
110-
return m.(db.Migrator).Migrate()
110+
if m, ok := obj.(db.Migrator); ok {
111+
return m.Migrate()
112+
}
113+
return nil
114+
}
111115

116+
switch {
117+
case opts.Sources.Sources == "" && opts.IsPgConnStr(opts.Metrics.Metrics):
118+
opts.Sources.Sources = opts.Metrics.Metrics
119+
case opts.Metrics.Metrics == "" && opts.IsPgConnStr(opts.Sources.Sources):
120+
opts.Metrics.Metrics = opts.Sources.Sources
112121
}
113122

114123
err = f(opts.Sources.Sources, func() (any, error) {

0 commit comments

Comments
 (0)