Only check --alter if given. Fix some tests, add add_col to make some tests work on PXC or not.

This commit is contained in:
Daniel Nichter
2012-11-28 21:11:29 +00:00
parent d515e3b382
commit 824c34b5d2
2 changed files with 48 additions and 26 deletions

View File

@@ -8177,7 +8177,9 @@ sub main {
# ######################################################################## # ########################################################################
# Check the --alter statement. This is done again after the # Check the --alter statement. This is done again after the
# ######################################################################## # ########################################################################
my $renamed_cols = find_renamed_cols( my $renamed_cols = {};
if ( my $alter = $o->get('alter') ) {
$renamed_cols = find_renamed_cols(
alter => $o->get('alter'), alter => $o->get('alter'),
TableParser => $tp, TableParser => $tp,
); );
@@ -8185,13 +8187,14 @@ sub main {
if ( $o->get('check-alter') ) { if ( $o->get('check-alter') ) {
check_alter( check_alter(
tbl => $orig_tbl, tbl => $orig_tbl,
alter => $o->get('alter'), alter => $alter,
dry_run => $o->get('dry-run'), dry_run => $o->get('dry-run'),
renamed_cols => $renamed_cols, renamed_cols => $renamed_cols,
Cxn => $cxn, Cxn => $cxn,
TableParser => $tp, TableParser => $tp,
); );
} }
}
if ( %$renamed_cols && !$o->get('dry-run') ) { if ( %$renamed_cols && !$o->get('dry-run') ) {
print "Renaming columns:\n" print "Renaming columns:\n"

View File

@@ -101,9 +101,9 @@ sub test_alter_table {
my $tbl_struct = $tp->parse($ddl); my $tbl_struct = $tp->parse($ddl);
my $cols = '*'; my $cols = '*';
if ( $test_type eq 'drop_col' && !grep { $_ eq '--dry-run' } @$cmds ) { if ( $test_type =~ m/(?:add|drop)_col/ && !grep { $_ eq '--dry-run' } @$cmds ) {
# Don't select the column being dropped. # Don't select the column being dropped.
my $col = $args{drop_col}; my $col = $args{drop_col} || $args{new_col};
die "I need a drop_col argument" unless $col; die "I need a drop_col argument" unless $col;
$cols = join(', ', grep { $_ ne $col } @{$tbl_struct->{cols}}); $cols = join(', ', grep { $_ ne $col } @{$tbl_struct->{cols}});
} }
@@ -148,6 +148,7 @@ sub test_alter_table {
); );
my $new_ddl = $tp->get_create_table($master_dbh, $db, $tbl); my $new_ddl = $tp->get_create_table($master_dbh, $db, $tbl);
my $new_tbl_struct = $tp->parse($new_ddl);
my $fail = 0; my $fail = 0;
is( is(
@@ -165,7 +166,7 @@ sub test_alter_table {
) or $fail = 1; ) or $fail = 1;
# Rows in the original and new table should be identical. # Rows in the original and new table should be identical.
my $new_rows = $master_dbh->selectall_arrayref("SELECT * FROM $table ORDER BY `$pk_col`"); my $new_rows = $master_dbh->selectall_arrayref("SELECT $cols FROM $table ORDER BY `$pk_col`");
is_deeply( is_deeply(
$new_rows, $new_rows,
$orig_rows, $orig_rows,
@@ -174,7 +175,7 @@ sub test_alter_table {
if ( grep { $_ eq '--no-drop-new-table' } @$cmds ) { if ( grep { $_ eq '--no-drop-new-table' } @$cmds ) {
$new_rows = $master_dbh->selectall_arrayref( $new_rows = $master_dbh->selectall_arrayref(
"SELECT * FROM `$db`.`$new_tbl` ORDER BY `$pk_col`"); "SELECT $cols FROM `$db`.`$new_tbl` ORDER BY `$pk_col`");
is_deeply( is_deeply(
$new_rows, $new_rows,
$orig_rows, $orig_rows,
@@ -217,6 +218,18 @@ sub test_alter_table {
} }
} }
elsif ( $test_type eq 'add_col' ) { elsif ( $test_type eq 'add_col' ) {
if ( $args{no_change} ) {
ok(
!$new_tbl_struct->{is_col}->{$args{new_col}},
"$name $args{new_col} not added"
);
}
else {
ok(
$new_tbl_struct->{is_col}->{$args{new_col}},
"$name $args{new_col} added"
);
}
} }
elsif ( $test_type eq 'new_engine' ) { elsif ( $test_type eq 'new_engine' ) {
my $new_engine = lc($args{new_engine}); my $new_engine = lc($args{new_engine});
@@ -644,22 +657,28 @@ test_table(
test_alter_table( test_alter_table(
name => "--no-swap-tables", name => "--no-swap-tables",
table => "pt_osc.t", table => "pt_osc.t",
file => "basic_no_fks.sql", file => "basic_no_fks_innodb.sql",
max_id => 20, max_id => 20,
test_type => "new_engine", # Engine doesn't actually change test_type => "add_col",
new_engine => "MyISAM", # because the tables aren't swapped new_col => "foo",
cmds => [qw(--execute --alter ENGINE=InnoDB --no-swap-tables)], no_change => 1,
cmds => [
qw(--execute --no-swap-tables), '--alter', 'ADD COLUMN foo INT'
],
); );
test_alter_table( test_alter_table(
name => "--no-swap-tables --no-drop-new-table", name => "--no-swap-tables --no-drop-new-table",
table => "pt_osc.t", table => "pt_osc.t",
file => "basic_no_fks.sql", file => "basic_no_fks_innodb.sql",
max_id => 20, max_id => 20,
test_type => "new_engine", # Engine doesn't actually change test_type => "add_col",
new_engine => "MyISAM", # because the tables aren't swapped new_col => "foo",
cmds => [qw(--execute --alter ENGINE=InnoDB --no-swap-tables), no_change => 1,
qw(--no-drop-new-table)], cmds => [
qw(--execute --no-swap-tables), '--alter', 'ADD COLUMN foo INT',
qw(--no-drop-new-table),
],
); );
# ############################################################################# # #############################################################################