Skip to content

Commit 0ae5788

Browse files
Add ability to skip apply confirm prompt (#134)
1 parent 6319a93 commit 0ae5788

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cmd/pg-schema-diff/apply_cmd.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func buildApplyCmd() *cobra.Command {
2626
"Specify the hazards that are allowed. Order does not matter, and duplicates are ignored. If the"+
2727
" migration plan contains unwanted hazards (hazards not in this list), then the migration will fail to run"+
2828
" (example: --allowed-hazards DELETES_DATA,INDEX_BUILD)")
29+
skipConfirmPrompt := cmd.Flags().Bool("skip-confirm-prompt", false, "Skips prompt asking for user to confirm before applying")
2930
cmd.RunE = func(cmd *cobra.Command, args []string) error {
3031
logger := log.SimpleLogger()
3132
connConfig, err := parseConnConfig(*connFlags, logger)
@@ -54,13 +55,16 @@ func buildApplyCmd() *cobra.Command {
5455
if err := failIfHazardsNotAllowed(plan, *allowedHazardsTypesStrs); err != nil {
5556
return err
5657
}
57-
if err := mustContinuePrompt(
58-
fmt.Sprintf(
59-
"Apply migration with the following hazards: %s?",
60-
strings.Join(*allowedHazardsTypesStrs, ", "),
61-
),
62-
); err != nil {
63-
return err
58+
59+
if !*skipConfirmPrompt {
60+
if err := mustContinuePrompt(
61+
fmt.Sprintf(
62+
"Apply migration with the following hazards: %s?",
63+
strings.Join(*allowedHazardsTypesStrs, ", "),
64+
),
65+
); err != nil {
66+
return err
67+
}
6468
}
6569

6670
if err := runPlan(context.Background(), connConfig, plan); err != nil {

0 commit comments

Comments
 (0)