mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-05-05 01:00:35 +08:00
Fix and test --alter-fk-method=none.
This commit is contained in:
@@ -4936,7 +4936,7 @@ sub main {
|
||||
}
|
||||
|
||||
my $alter_fk_method = $o->get('alter-foreign-keys-method') || '';
|
||||
if ( $alter_fk_method =~ m/^(?:drop_swap|none)/ ) {
|
||||
if ( $alter_fk_method eq 'drop_swap' ) {
|
||||
$o->set('swap-tables', 0);
|
||||
$o->set('drop-old-table', 0);
|
||||
}
|
||||
@@ -5928,6 +5928,17 @@ sub main {
|
||||
}
|
||||
else {
|
||||
print "Dropping old table...\n";
|
||||
|
||||
if ( $alter_fk_method eq 'none' ) {
|
||||
# Child tables still reference the old table, but the user
|
||||
# has chosen to break fks, so we need to disable fk checks
|
||||
# in order to drop the old table.
|
||||
my $sql = "SET foreign_key_checks=0";
|
||||
PTDEBUG && _d($sql);
|
||||
print $sql, "\n" if $o->get('print');
|
||||
$cxn->dbh()->do($sql);
|
||||
}
|
||||
|
||||
my $sql = "DROP TABLE IF EXISTS $old_tbl->{name}";
|
||||
print $sql, "\n" if $o->get('print');
|
||||
PTDEBUG && _d($sql);
|
||||
|
||||
@@ -32,7 +32,7 @@ elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
}
|
||||
else {
|
||||
plan tests => 83;
|
||||
plan tests => 90;
|
||||
}
|
||||
|
||||
my $q = new Quoter();
|
||||
@@ -158,7 +158,7 @@ sub test_alter_table {
|
||||
) or $fail = 1;
|
||||
|
||||
# There should be no new or missing tables.
|
||||
my $new_tbls = $master_dbh->selectall_arrayref("SHOW TABLES FROM `$db`");
|
||||
my $new_tbls = $master_dbh->selectall_arrayref("SHOW TABLES FROM `$db`");
|
||||
is_deeply(
|
||||
$new_tbls,
|
||||
$orig_tbls,
|
||||
@@ -480,6 +480,39 @@ SKIP: {
|
||||
);
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# --alther-foreign-keys-method=none. This intentionally breaks fks because
|
||||
# they're not updated so they'll point to the old table that is dropped.
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "$sample/basic_with_fks.sql");
|
||||
PerconaTest::wait_for_table($slave_dbh, "pt_osc.address", "address_id=5");
|
||||
|
||||
# Specify --alter-foreign-keys-method for a table with no child tables.
|
||||
test_alter_table(
|
||||
name => "Update fk method none",
|
||||
table => "pt_osc.country",
|
||||
pk_col => "country_id",
|
||||
file => "basic_with_fks.sql",
|
||||
wait => ["pt_osc.address", "address_id=5"],
|
||||
test_type => "new_engine",
|
||||
new_engine => "innodb",
|
||||
cmds => [
|
||||
qw(
|
||||
--execute
|
||||
--alter-foreign-keys-method none
|
||||
),
|
||||
'--alter', 'ENGINE=INNODB',
|
||||
],
|
||||
);
|
||||
|
||||
my $fks = $tp->get_fks(
|
||||
$tp->get_create_table($master_dbh, "pt_osc", "city"));
|
||||
is(
|
||||
$fks->{fk_city_country}->{parent_tbl}->{tbl},
|
||||
"_country_old",
|
||||
"--alter-foreign-keys-method=none"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Alter tables with columns with resvered words and spaces.
|
||||
# #############################################################################
|
||||
|
||||
Reference in New Issue
Block a user