Add 'DROP PRIMARY KEY' to --check-alter.

This commit is contained in:
Daniel Nichter
2013-01-29 18:16:38 -07:00
parent 7ec6abd684
commit 680477ed58
3 changed files with 99 additions and 2 deletions

View File

@@ -210,7 +210,7 @@ $sb->load_file('master', "$sample/del-trg-bug-1062324.sql");
sub { pt_online_schema_change::main(@args,
"$master_dsn,D=test,t=t1",
"--alter", "drop key 2bpk, drop key c3, drop primary key, drop c1, add primary key (c2, c3(4)), add key (c3(4))",
qw(--execute --no-drop-new-table --no-swap-tables)) },
qw(--no-check-alter --execute --no-drop-new-table --no-swap-tables)) },
);
# Since _t1_new no longer has the c1 column, the bug caused this
@@ -242,7 +242,7 @@ $sb->load_file('master', "$sample/del-trg-bug-1062324.sql");
sub { pt_online_schema_change::main(@args,
"$master_dsn,D=test,t=t1",
"--alter", "drop primary key, add column _id int unsigned not null primary key auto_increment FIRST",
qw(--execute --no-drop-new-table --no-swap-tables)) },
qw(--no-check-alter --execute --no-drop-new-table --no-swap-tables)) },
);
eval {

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use Data::Dumper;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-online-schema-change";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $slave_dbh = $sb->get_dbh_for('slave1');
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave1';
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = (qw(--lock-wait-timeout 3));
my $output;
my $exit_status;
my $sample = "t/pt-online-schema-change/samples/";
# #############################################################################
# DROP PRIMARY KEY
# #############################################################################
$sb->load_file('master', "$sample/del-trg-bug-1103672.sql");
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args,
"$master_dsn,D=test,t=t1",
"--alter", "drop primary key, add column _id int unsigned not null primary key auto_increment FIRST",
qw(--execute)),
},
);
like(
$output,
qr/--check-alter failed/,
"DROP PRIMARY KEY"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;