feat: add guarded workflow-migrate force command#6
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new guarded force subcommand to workflow-migrate/shared migrate CLI to repair golang-migrate metadata without applying SQL, with safety checks and supporting tests/docs.
Changes:
- Add
workflow-migrate force <version>command with typed confirmation and optional--allow-clean. - Implement
Driver.Force()in the golang-migrate driver, including target validation, source-version existence checks, and clean/dirty safety gating. - Add CLI + driver tests and update plugin manifest, binary usage docs, and changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plugin.json | Registers the new force command in the plugin manifest. |
| pkg/cli/root.go | Adds the force Cobra subcommand and custom arg splitting to support -1 as a positional version. |
| pkg/cli/root_test.go | Adds tests ensuring the command is present and guarded by typed confirmation; verifies -1 parsing. |
| internal/golangmigrate/driver.go | Implements metadata-only Force() with validation and safety checks. |
| internal/golangmigrate/driver_test.go | Adds coverage for force behavior (clean refusal, dirty-only default, missing target, -1 nil version). |
| cmd/workflow-migrate/main.go | Updates usage comment to include force. |
| CHANGELOG.md | Documents the new force command under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Use: "force <version>", | ||
| Short: "Force-set the recorded migration version", | ||
| DisableFlagParsing: true, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| target, flagArgs, err := splitForceArgs(args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := cmd.Flags().Parse(flagArgs); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
With DisableFlagParsing enabled and custom parsing in splitForceArgs, force --help / force -h will not show help. For example, --help is treated as a flag arg and (when no version is provided) results in "force requires exactly one version" instead of displaying usage. Consider handling help explicitly before enforcing the version/confirmation (e.g., detect -h/--help in args and call cmd.Help()), or restructure parsing so Cobra's built-in help handling still works.
| if arg == "-1" || !strings.HasPrefix(arg, "-") { | ||
| if target != "" { | ||
| return "", nil, fmt.Errorf("force requires exactly one version") | ||
| } | ||
| target = arg | ||
| continue | ||
| } | ||
| flagArgs = append(flagArgs, arg) |
There was a problem hiding this comment.
splitForceArgs only treats -1 as a positional version; any other negative number (e.g. force -2) is treated as a flag and will produce a misleading parse error (or "force requires exactly one version") rather than the intended "invalid target version" message. If the intent is to reject all negatives except -1, it would be clearer to accept any ^-?\d+$ as the target positionally and let parseForceTarget validate it, or explicitly detect ^-\d+$ here and return an "invalid target version" error.
Summary
Verification
Review