mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-30 01:01:51 +08:00
PT-91 Fixes with locks and --no-swap-table
* Merged code that implements TABLE LOCKs during tiggers creation PR #241 https://github.com/percona/percona-toolkit/pull/241/ * Code refactored for --preserve triggers with --no-swap-tables and drop-new-table * Added new test for --preserve triggers with --no-swap-tables and drop-new-table
This commit is contained in:
@@ -838,131 +838,6 @@ like(
|
||||
|
||||
$master_dbh->do("DROP DATABASE test_recursion_method");
|
||||
|
||||
|
||||
# #############################################################################
|
||||
# Tests for --preserve-triggers option
|
||||
# #############################################################################
|
||||
|
||||
SKIP: {
|
||||
skip 'Sandbox MySQL version should be >= 5.7' unless $sandbox_version ge '5.7';
|
||||
|
||||
test_alter_table(
|
||||
name => 'Basic --preserve-triggers',
|
||||
table => "pt_osc.account",
|
||||
pk_col => "id",
|
||||
file => "triggers.sql",
|
||||
test_type => "add_col",
|
||||
new_col => "foo",
|
||||
cmds => [
|
||||
qw(--execute --preserve-triggers), '--alter', 'ADD COLUMN foo INT',
|
||||
],
|
||||
);
|
||||
|
||||
test_alter_table(
|
||||
name => "--preserve-triggers: after triggers",
|
||||
table => "test.t1",
|
||||
pk_col => "id",
|
||||
file => "after_triggers.sql",
|
||||
test_type => "add_col",
|
||||
new_col => "foo3",
|
||||
cmds => [
|
||||
qw(--execute --preserve-triggers --alter-foreign-keys-method rebuild_constraints), '--alter', 'ADD COLUMN foo3 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 cannot drop column 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,
|
||||
"$dsn,D=test,t=t1",
|
||||
qw(--execute --no-swap-tables --preserve-triggers), '--alter', 'ADD COLUMN foo INT')
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
$exit,
|
||||
0,
|
||||
"--preserve-triggers --no-swap-tables exit status",
|
||||
);
|
||||
|
||||
$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 --no-drop-old-table --preserve-triggers), '--alter', 'ADD COLUMN foo INT')
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
$exit,
|
||||
0,
|
||||
"--preserve-triggers --no-drop-old-table exit status",
|
||||
);
|
||||
|
||||
my $rows = $master_dbh->selectall_arrayref("SHOW TABLES LIKE '%t1%'");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[ [ '_t1_old' ], [ 't1' ] ],
|
||||
"--preserve-triggers --no-drop-old-table original & new tables still exists",
|
||||
);
|
||||
|
||||
($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 cannot be used --no-drop-triggers",
|
||||
);
|
||||
|
||||
test_alter_table(
|
||||
name => "Basic FK auto --execute",
|
||||
table => "pt_osc.country",
|
||||
pk_col => "country_id",
|
||||
file => "basic_with_fks.sql",
|
||||
test_type => "drop_col",
|
||||
drop_col => "last_update",
|
||||
check_fks => "rebuild_constraints",
|
||||
cmds => [
|
||||
qw(
|
||||
--execute
|
||||
--alter-foreign-keys-method rebuild_constraints
|
||||
--preserve-triggers
|
||||
),
|
||||
'--alter', 'DROP COLUMN last_update',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
diag("Reloading sakila");
|
||||
my $master_port = $sb->port_for('master');
|
||||
system "$trunk/sandbox/load-sakila-db $master_port &";
|
||||
|
||||
Reference in New Issue
Block a user