From 8eebecf559922d97829c4672a9cd1bb4ab43b58a Mon Sep 17 00:00:00 2001 From: Frank Cizmich Date: Mon, 30 Jun 2014 13:36:25 -0300 Subject: [PATCH] asks for confirmation when using alter-foreign-key-method none - issue 1329422 --- bin/pt-online-schema-change | 14 ++++++++++++++ t/pt-online-schema-change/basics.t | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 0b508383..37f65d52 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -7860,6 +7860,16 @@ sub main { $o->save_error("Invalid --alter-foreign-keys-method value: $alter_fk_method"); } + # Issue a strong warning if alter-foreign-keys-method = none + if ( $alter_fk_method eq 'none' && !$o->get('force') ) { + print STDERR "WARNING! Using alter-foreign-keys-method = \"none\". This will typically cause foreign key violations!\nThis method of handling foreign key constraints is only provided so that the database administrator can disable the tool’s built-in functionality if desired.\n\nContinue anyway? (y/N)"; + my $response; + chomp($response = ); + if ($response !~ /y|(yes)/i) { + exit 1; + } + } + if ( $alter_fk_method eq 'drop_swap' && !$o->get('drop-new-table') ) { $o->save_error("--alter-foreign-keys-method=drop_swap does not work with --no-drop-new-table."); } @@ -11025,6 +11035,10 @@ only perform some safety checks and exit. This helps ensure that you have read documentation and understand how to use this tool. If you have not read the documentation, then do not specify this option. +=item --force + +This options bypasses confirmation in case of using alter-foreign-keys-method = none , which might break foreign key constraints. + =item --help Show help and exit. diff --git a/t/pt-online-schema-change/basics.t b/t/pt-online-schema-change/basics.t index 625e6b16..fbd032e1 100644 --- a/t/pt-online-schema-change/basics.t +++ b/t/pt-online-schema-change/basics.t @@ -591,7 +591,7 @@ test_alter_table( test_type => "new_engine", new_engine => "innodb", cmds => [ - qw(--execute --alter-foreign-keys-method none --alter ENGINE=INNODB) + qw(--execute --alter-foreign-keys-method none --force --alter ENGINE=INNODB) ], );