Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
venkat-iblox committed Oct 2, 2024
1 parent 8ab5a72 commit 6bebd33
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 245 deletions.
4 changes: 2 additions & 2 deletions cmd/migrate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ var (
flagConfigFile = pflag.String("config.file", "", "configuration file name without extension")

// goto command flags
flagDirty = pflag.Bool("dirty", false, "migration is dirty")
flagPVCPath = pflag.String("intermediate-path", "", "path to the mounted volume which is used to copy the migration files")
flagDirty = pflag.Bool("force-dirty-handling", false, "force the handling of dirty database state")
flagMountPath = pflag.String("cache-dir", "", "path to the mounted volume which is used to copy the migration files")
)
30 changes: 11 additions & 19 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const (
Use -format option to specify a Go time format string. Note: migrations with the same time cause "duplicate migration version" error.
Use -tz option to specify the timezone that will be used when generating non-sequential migrations (defaults: UTC).
`
gotoUsage = `goto V [-dirty] [-intermediate-path] Migrate to version V`
gotoUsage = `goto V [-force-dirty-handling] [-cache-dir P] Migrate to version V
Use -force-dirty-handling to handle dirty database state
Use -cache-dir to specify the intermediate path P for storing migrations`
upUsage = `up [N] Apply all or N up migrations`
downUsage = `down [N] [-all] Apply all or N down migrations
Use -all to apply all down migrations`
Expand Down Expand Up @@ -262,28 +264,18 @@ Database drivers: `+strings.Join(database.List(), ", ")+"\n", createUsage, gotoU
if err != nil {
log.fatal("error: can't read version argument V")
}
handleDirty := viper.GetBool("dirty")
destPath := viper.GetString("intermediate-path")
srcPath := ""
// if sourcePtr is set, use it to get the source path
// otherwise, use the path flag
if path != "" {
srcPath = path
}
if sourcePtr != "" {
// parse the source path from the source argument
parse, err := url.Parse(sourcePtr)
if err != nil {
log.fatal("error: can't parse the source path from the source argument")
handleDirty := viper.GetBool("force-dirty-handling")
if handleDirty {
destPath := viper.GetString("cache-dir")
if destPath == "" {
log.fatal("error: cache-dir must be specified when force-dirty-handling is set")
}
srcPath = parse.Path
}

if handleDirty && destPath == "" {
log.fatal("error: intermediate-path must be specified when dirty is set")
if err = migrater.WithDirtyStateHandler(sourcePtr, destPath, handleDirty); err != nil {
log.fatalErr(err)
}
}

migrater.WithDirtyStateHandler(srcPath, destPath, handleDirty)
if err = gotoCmd(migrater, uint(v)); err != nil {
log.fatalErr(err)
}
Expand Down
Loading

0 comments on commit 6bebd33

Please sign in to comment.