mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
pt-osc fixed fk underscore toggling lp1498128
This commit is contained in:
@@ -9880,11 +9880,8 @@ sub create_new_table {
|
|||||||
# This is in contrast to previous behavior were we added underscores
|
# This is in contrast to previous behavior were we added underscores
|
||||||
# indefinitely, sometimes exceeding the allowed name limit
|
# indefinitely, sometimes exceeding the allowed name limit
|
||||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1215587
|
# https://bugs.launchpad.net/percona-toolkit/+bug/1215587
|
||||||
if ( $sql =~ /CONSTRAINT `_/ ) {
|
$sql =~ s/^ CONSTRAINT `(_?)/' CONSTRAINT `'.($1 eq '' ? '_' : '')/gme;
|
||||||
$sql =~ s/^ CONSTRAINT `_/ CONSTRAINT `/gm;
|
|
||||||
} else {
|
|
||||||
$sql =~ s/^ CONSTRAINT `/ CONSTRAINT `_/gm;
|
|
||||||
}
|
|
||||||
if ( $o->get('default-engine') ) {
|
if ( $o->get('default-engine') ) {
|
||||||
$sql =~ s/\s+ENGINE=\S+//;
|
$sql =~ s/\s+ENGINE=\S+//;
|
||||||
}
|
}
|
||||||
|
@@ -42,8 +42,7 @@ my $sample = "t/pt-online-schema-change/samples/";
|
|||||||
$sb->load_file('master', "$sample/bug-1215587.sql");
|
$sb->load_file('master', "$sample/bug-1215587.sql");
|
||||||
|
|
||||||
# run once: we expect constraint names to be prefixed with one underscore
|
# run once: we expect constraint names to be prefixed with one underscore
|
||||||
# note: We're running just a neutral no-op alter. We are only interested in constraint name
|
# if they havre't one, and to remove one if they already do.
|
||||||
# changes.
|
|
||||||
($output, $exit_status) = full_output(
|
($output, $exit_status) = full_output(
|
||||||
sub { pt_online_schema_change::main(@args,
|
sub { pt_online_schema_change::main(@args,
|
||||||
"$master_dsn,D=bug1215587,t=Table1",
|
"$master_dsn,D=bug1215587,t=Table1",
|
||||||
@@ -52,24 +51,24 @@ $sb->load_file('master', "$sample/bug-1215587.sql");
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
my $constraints = $master_dbh->selectall_hashref("SELECT CONSTRAINT_NAME, TABLE_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE table_schema='bug1215587' and (TABLE_NAME='Table1' OR TABLE_NAME='Table2') and CONSTRAINT_NAME LIKE '%fkey%'", 'table_name');
|
my $constraints = $master_dbh->selectall_arrayref("SELECT TABLE_NAME, CONSTRAINT_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE table_schema='bug1215587' and (TABLE_NAME='Table1' OR TABLE_NAME='Table2') and CONSTRAINT_NAME LIKE '%fkey%' ORDER BY TABLE_NAME, CONSTRAINT_NAME");
|
||||||
|
|
||||||
|
|
||||||
is(
|
is_deeply(
|
||||||
$constraints->{Table1}->{constraint_name},
|
$constraints,
|
||||||
'_fkey1',
|
[
|
||||||
"Altered table: constraint name prefixed one underscore after 1st run"
|
['Table1', 'fkey1a'],
|
||||||
|
['Table1', '_fkey1b'],
|
||||||
|
['Table2', 'fkey2b'],
|
||||||
|
['Table2', '_fkey2a'],
|
||||||
|
],
|
||||||
|
"First run adds or removes underscore from constraint names, accordingly"
|
||||||
);
|
);
|
||||||
|
|
||||||
is(
|
|
||||||
$constraints->{Table2}->{constraint_name},
|
|
||||||
'_fkey2',
|
|
||||||
"Child table : constraint name prefixed one underscore after 1st run"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
# run second time
|
# run second time
|
||||||
# we expect underscores to be removed
|
# we expect constraints to be the same as we started (toggled back)
|
||||||
($output, $exit_status) = full_output(
|
($output, $exit_status) = full_output(
|
||||||
sub { pt_online_schema_change::main(@args,
|
sub { pt_online_schema_change::main(@args,
|
||||||
"$master_dsn,D=bug1215587,t=Table1",
|
"$master_dsn,D=bug1215587,t=Table1",
|
||||||
@@ -77,19 +76,18 @@ is(
|
|||||||
qw(--execute)) },
|
qw(--execute)) },
|
||||||
);
|
);
|
||||||
|
|
||||||
$constraints = $master_dbh->selectall_hashref("SELECT CONSTRAINT_NAME, TABLE_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE table_schema='bug1215587' and (TABLE_NAME='Table1' OR TABLE_NAME='Table2') and CONSTRAINT_NAME LIKE '%fkey%'", 'table_name');
|
$constraints = $master_dbh->selectall_arrayref("SELECT TABLE_NAME, CONSTRAINT_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE table_schema='bug1215587' and (TABLE_NAME='Table1' OR TABLE_NAME='Table2') and CONSTRAINT_NAME LIKE '%fkey%' ORDER BY TABLE_NAME, CONSTRAINT_NAME");
|
||||||
|
|
||||||
|
|
||||||
is(
|
is_deeply(
|
||||||
$constraints->{'Table1'}->{constraint_name},
|
$constraints,
|
||||||
'fkey1',
|
[
|
||||||
"Altered table: constraint name removed underscore after 2nd run"
|
['Table1', 'fkey1b'],
|
||||||
);
|
['Table1', '_fkey1a'],
|
||||||
|
['Table2', 'fkey2a'],
|
||||||
is(
|
['Table2', '_fkey2b'],
|
||||||
$constraints->{'Table2'}->{constraint_name},
|
],
|
||||||
'fkey2',
|
"Second run toggles constraint names back to how they were"
|
||||||
"Child table : constraint name removed underscore after 2nd run"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,8 +16,13 @@ CREATE TABLE `Table2` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
ALTER TABLE `Table1`
|
ALTER TABLE `Table1`
|
||||||
ADD CONSTRAINT `fkey1` FOREIGN KEY (`T2ID`) REFERENCES `Table2` (`ID`) ON DELETE NO ACTION;
|
ADD CONSTRAINT `_fkey1a` FOREIGN KEY (`T2ID`) REFERENCES `Table2` (`ID`) ON DELETE NO ACTION;
|
||||||
|
|
||||||
|
ALTER TABLE `Table1`
|
||||||
|
ADD CONSTRAINT `fkey1b` FOREIGN KEY (`T2ID`) REFERENCES `Table2` (`ID`) ON DELETE NO ACTION;
|
||||||
|
|
||||||
ALTER TABLE `Table2`
|
ALTER TABLE `Table2`
|
||||||
ADD CONSTRAINT `fkey2` FOREIGN KEY (`ID`) REFERENCES `Table1` (`T2ID`) ON DELETE NO ACTION;
|
ADD CONSTRAINT `fkey2a` FOREIGN KEY (`ID`) REFERENCES `Table1` (`T2ID`) ON DELETE NO ACTION;
|
||||||
|
|
||||||
|
ALTER TABLE `Table2`
|
||||||
|
ADD CONSTRAINT `_fkey2b` FOREIGN KEY (`ID`) REFERENCES `Table1` (`T2ID`) ON DELETE NO ACTION;
|
||||||
|
Reference in New Issue
Block a user