From 2ccf81ef8adec15e0a854c30ef563084b411b83e Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Tue, 4 Jul 2017 19:48:21 -0300 Subject: [PATCH] PT-91 Added some tests for --preserve-triggers --- t/pt-online-schema-change/basics.t | 70 +++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/t/pt-online-schema-change/basics.t b/t/pt-online-schema-change/basics.t index 4862ba1c..ad6539b2 100644 --- a/t/pt-online-schema-change/basics.t +++ b/t/pt-online-schema-change/basics.t @@ -120,10 +120,11 @@ sub test_alter_table { my $orig_max_id = $master_dbh->selectall_arrayref( "SELECT MAX(`$pk_col`) FROM `$db`.`$tbl`"); - my $triggers_sql = "SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT ". - " FROM INFORMATION_SCHEMA.TRIGGERS ". - "WHERE TRIGGER_SCHEMA = '$db' " . - " AND EVENT_OBJECT_TABLE = '$tbl'"; + my $triggers_sql = "SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, " + . " CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING " + . " FROM INFORMATION_SCHEMA.TRIGGERS " + . " WHERE TRIGGER_SCHEMA = '$db' " + . " AND EVENT_OBJECT_TABLE = '$tbl'"; my $orig_triggers = $master_dbh->selectall_arrayref($triggers_sql); my ($orig_auto_inc) = $ddl =~ m/\s+AUTO_INCREMENT=(\d+)\s+/; @@ -871,18 +872,27 @@ SKIP: { ); - #test_alter_table( - # name => "--preserve-triggers --no-swap-tables", - # table => "pt_osc.t", - # file => "basic_no_fks_innodb.sql", - # max_id => 20, - # test_type => "add_col", - # new_col => "foo", - # no_change => 1, - # cmds => [ - # qw(--execute --no-swap-tables --preserve-triggers), '--alter', 'ADD COLUMN foo INT' - # ], - #); + $sb->load_file('master', "$sample/after_triggers.sql"); + + ($output, $exit) = full_output( + sub { pt_online_schema_change::main(@args, + "$dsn,D=test,t=t1", + qw(--execute --preserve-triggers), '--alter', 'DROP COLUMN f1') + }, + stderr => 1, + ); + + isnt( + $exit, + 0, + "--preserve-triggers drop field used by trigger", + ); + + like( + $output, + qr/Check if all fields referenced by the trigger still exists after the operation you are trying to apply/, + "--preserve-triggers: message if try to drop a field used by triggers", + ); ($output, $exit) = full_output( sub { pt_online_schema_change::main(@args, @@ -898,6 +908,34 @@ SKIP: { "--preserve-triggers --no-swap-tables", ); + ($output, $exit) = full_output( + sub { pt_online_schema_change::main(@args, + "$dsn,D=pt_osc,t=t", + qw(--execute --no-drop-old-table --preserve-triggers), '--alter', 'ADD COLUMN foo INT') + }, + stderr => 1, + ); + + isnt( + $exit, + 0, + "--preserve-triggers --no-drop-old-table", + ); + + ($output, $exit) = full_output( + sub { pt_online_schema_change::main(@args, + "$dsn,D=pt_osc,t=t", + qw(--execute --no-drop-triggers --preserve-triggers), '--alter', 'ADD COLUMN foo INT') + }, + stderr => 1, + ); + + isnt( + $exit, + 0, + "--preserve-triggers --no-drop-triggers", + ); + test_alter_table( name => "Basic FK auto --execute", table => "pt_osc.country",