mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-27 07:54:58 +00:00
PT-186 osc doesn't recognize mixed case in field names
--alter 'CHANGE COLUMN C1 c1 ...' was failing because osc was not lowering the case of the field names when trying to detect renamed columns.
This commit is contained in:
91
t/pt-online-schema-change/pt-186.t
Normal file
91
t/pt-online-schema-change/pt-186.t
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/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 threads;
|
||||
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
use File::Temp qw/ tempdir /;
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
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 $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
|
||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||
# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the
|
||||
# tool will die.
|
||||
my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
|
||||
my $output;
|
||||
my $exit_status;
|
||||
my $sample = "t/pt-online-schema-change/samples/";
|
||||
|
||||
$sb->load_file('master', "$sample/pt-186.sql");
|
||||
|
||||
my $ori_rows = $master_dbh->selectall_arrayref('SELECT * FROM test.t1');
|
||||
|
||||
($output, $exit_status) = full_output(
|
||||
sub { pt_online_schema_change::main(@args, "$master_dsn,D=test,t=t1",
|
||||
'--execute', '--no-check-alter',
|
||||
'--alter', 'CHANGE COLUMN `Last_referenced` `c11` INT NOT NULL default 99'
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
is(
|
||||
$exit_status,
|
||||
0,
|
||||
"--alter rename columns with uppercase names -> exit status 0",
|
||||
);
|
||||
|
||||
my $structure = $master_dbh->selectall_arrayref('DESCRIBE test.t1');
|
||||
is_deeply(
|
||||
$structure->[2],
|
||||
[
|
||||
'c11',
|
||||
'int(11)',
|
||||
'NO',
|
||||
'MUL',
|
||||
'99',
|
||||
''
|
||||
],
|
||||
'--alter rename columns with uppercase names -> Column was renamed'
|
||||
);
|
||||
|
||||
my $new_rows = $master_dbh->selectall_arrayref('SELECT * FROM test.t1');
|
||||
|
||||
is_deeply(
|
||||
$ori_rows,
|
||||
$new_rows,
|
||||
"--alter rename columns with uppercase names -> Row values OK"
|
||||
);
|
||||
|
||||
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS test");
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
33
t/pt-online-schema-change/samples/pt-186.sql
Normal file
33
t/pt-online-schema-change/samples/pt-186.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
DROP DATABASE IF EXISTS test;
|
||||
CREATE DATABASE test;
|
||||
|
||||
CREATE TABLE `test`.`t1` (
|
||||
`c1` int(10) unsigned NOT NULL,
|
||||
`c2` varchar(255) NOT NULL,
|
||||
`Last_referenced` INT NOT NULL DEFAULT 0,
|
||||
`c3` int(10) unsigned NOT NULL,
|
||||
`c4` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`c5` varchar(255) NOT NULL DEFAULT '',
|
||||
`c6` varchar(255) NOT NULL DEFAULT '',
|
||||
`c7` varchar(255) NOT NULL DEFAULT '',
|
||||
`c8` varchar(255) DEFAULT '',
|
||||
`c9` varchar(255) DEFAULT '',
|
||||
`c10` int(10) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`c1`,`c2`),
|
||||
KEY `Last_Referenced_c6_Index` (`Last_referenced`,`c6`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
INSERT INTO `test`.`t1` VALUES
|
||||
(1,'',0,139772,47473,'','','','','',178332),
|
||||
(2,'',1,74283,65463,'','','','','',159673),
|
||||
(3,'',2,161929,72681,'','','','','',189530),
|
||||
(4,'',3,76402,136494,'','','','','',132035),
|
||||
(5,'',4,133053,176778,'','','','','',198267),
|
||||
(6,'',5,68824,198479,'','','','','',139027),
|
||||
(7,'',6,98103,195314,'','','','','',307),
|
||||
(8,'',7,15094,53330,'','','','','',26258),
|
||||
(9,'',8,183263,73658,'','','','','',51367),
|
||||
(10,'',9,141835,87261,'','','','','',73928);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user