{"record":{"id":"fdecbe56ceac14a0","repo":"semaphoreui/semaphore","slug":"cannot-specify-both-undo-to-and-apply-to","errorCode":null,"errorMessage":"Cannot specify both --undo-to and --apply-to","messagePattern":"Cannot specify both --undo-to and --apply-to","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/cmd/migrate.go","lineNumber":32,"sourceCode":"}\n\nfunc init() {\n\tmigrateCmd.PersistentFlags().StringVar(&migrationArgs.undoTo, \"undo-to\", \"\", \"Undo to specific version\")\n\tmigrateCmd.PersistentFlags().StringVar(&migrationArgs.applyTo, \"apply-to\", \"\", \"Apply to specific version\")\n\tmigrateCmd.PersistentFlags().IntVar(&migrationArgs.errLogSize, \"err-log-size\", 0, \"Error log size\")\n\tmigrateCmd.PersistentFlags().BoolVar(&migrationArgs.skipTaskOutput, \"skip-task-output\", false, \"Skip task output importing during migration\")\n\tmigrateCmd.PersistentFlags().BoolVar(&migrationArgs.mergeExistingUsers, \"merge-existing-users\", false, \"Reuse existing users matched by username instead of failing on conflict\")\n\n\trootCmd.AddCommand(migrateCmd)\n}\n\nvar migrateCmd = &cobra.Command{\n\tUse:   \"migrate\",\n\tShort: \"Execute migrations\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\n\t\tif migrationArgs.undoTo != \"\" && migrationArgs.applyTo != \"\" {\n\t\t\tpanic(\"Cannot specify both --undo-to and --apply-to\")\n\t\t}\n\n\t\tvar undoTo, applyTo *string\n\n\t\tif migrationArgs.undoTo != \"\" {\n\t\t\tundoTo = &migrationArgs.undoTo\n\t\t}\n\n\t\tif migrationArgs.applyTo != \"\" {\n\t\t\tapplyTo = &migrationArgs.applyTo\n\t\t}\n\n\t\tstore := createStoreWithMigrationVersion(\"migrate\", undoTo, applyTo)\n\n\t\tdefer store.Close()\n\t\tutil.Config.PrintDbInfo()\n\t},\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/cli/cmd/migrate.go#L14-L50","documentation":"The semaphore migrate command panics when both --undo-to and --apply-to flags are supplied. The two flags are mutually exclusive: one performs a forward apply, the other a rollback, and applying both directions in a single invocation is ambiguous.","triggerScenarios":"Running `semaphore migrate --apply-to <version> --undo-to <version>` — the Run function panics immediately when both migrationArgs.undoTo and migrationArgs.applyTo are non-empty.","commonSituations":"Copy-pasting a rollback command and appending a forward-migration flag; scripting migration chains and forgetting to remove --undo-to from a template; misreading docs about flag precedence.","solutions":["Remove one of the two flags: keep only --apply-to to migrate forward or only --undo-to to roll back","Run the two operations as separate sequential commands if you need to undo then re-apply","Check the command help (`semaphore migrate --help`) for supported flag combinations"],"exampleFix":"// before\nsemaphore migrate --apply-to 2.1 --undo-to 2.0\n// after\nsemaphore migrate --undo-to 2.0   # rollback only\n# or separately:\nsemaphore migrate --apply-to 2.1  # forward only","handlingStrategy":"validation","validationCode":"if [ -n \"$UNDO_TO\" ] && [ -n \"$APPLY_TO\" ]; then echo \"use --apply-to or --undo-to, not both\"; exit 1; fi\nsemaphore migrate --apply-to \"$APPLY_TO\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only one direction flag per migrate invocation","Chain migrations as separate sequential commands","Check `semaphore migrate --help` before composing flags","Parameterize migration scripts so only one of the two variables is ever set"],"tags":["cli","migrations","cobra","flags"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}