Merge lp:~percona-toolkit-dev/percona-toolkit/dis-fk-chk-bug-976108 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 245
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/dis-fk-chk-bug-976108
Merge into: lp:percona-toolkit/2.1
Diff against target: 113 lines (+49/-40)
1 file modified
bin/pt-online-schema-change (+49/-40)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/dis-fk-chk-bug-976108
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+104936@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-online-schema-change'
2--- bin/pt-online-schema-change 2012-04-26 20:56:18 +0000
3+++ bin/pt-online-schema-change 2012-05-07 16:34:23 +0000
4@@ -5235,50 +5235,59 @@
5 # ########################################################################
6 # Get child tables of the original table, if necessary.
7 # ########################################################################
8- my $child_tables = find_child_tables(
9- tbl => $orig_tbl,
10- Cxn => $cxn,
11- Quoter => $q,
12- );
13- if ( !$child_tables ) {
14- if ( $alter_fk_method ) {
15- warn "No foreign keys reference $orig_tbl->{name}; ignoring "
16- . "--alter-foreign-keys-method.\n";
17-
18- if ( $alter_fk_method eq 'drop_swap' ) {
19- # These opts are disabled at the start if the user specifies
20- # the drop_swap method, but now that we know there are no
21- # child tables, we must re-enable these to make the alter work.
22- $o->set('swap-tables', 1);
23- $o->set('drop-old-table', 1);
24- }
25-
26- $alter_fk_method = '';
27- }
28- # No child tables and --alter-fk-method wasn't specified,
29- # so nothing to do.
30+ my $child_tables;
31+ if ( ($alter_fk_method || '') eq 'none' ) {
32+ print "Not updating foreign keys because "
33+ . "--alter-foreign-keys-method=none. Foreign keys "
34+ . "that reference the table will no longer work.\n";
35 }
36 else {
37- print "Child tables:\n";
38- foreach my $child_table ( @$child_tables ) {
39- printf " %s (approx. %s rows)\n",
40- $child_table->{name},
41- $child_table->{row_est} || '?';
42+ $child_tables = find_child_tables(
43+ tbl => $orig_tbl,
44+ Cxn => $cxn,
45+ Quoter => $q,
46+ );
47+ if ( !$child_tables ) {
48+ if ( $alter_fk_method ) {
49+ warn "No foreign keys reference $orig_tbl->{name}; ignoring "
50+ . "--alter-foreign-keys-method.\n";
51+
52+ if ( $alter_fk_method eq 'drop_swap' ) {
53+ # These opts are disabled at the start if the user specifies
54+ # the drop_swap method, but now that we know there are no
55+ # child tables, we must re-enable these to make the alter work.
56+ $o->set('swap-tables', 1);
57+ $o->set('drop-old-table', 1);
58+ }
59+
60+ $alter_fk_method = '';
61+ }
62+ # No child tables and --alter-fk-method wasn't specified,
63+ # so nothing to do.
64 }
65+ else {
66+ print "Child tables:\n";
67+ foreach my $child_table ( @$child_tables ) {
68+ printf " %s (approx. %s rows)\n",
69+ $child_table->{name},
70+ $child_table->{row_est} || '?';
71+ }
72
73- if ( $alter_fk_method ) {
74- # Let the user know how we're going to update the child table fk refs.
75- my $choice
76+ if ( $alter_fk_method ) {
77+ # Let the user know how we're going to update the child table
78+ # fk refs.
79+ my $choice
80 = $alter_fk_method eq 'none' ? "not"
81 : $alter_fk_method eq 'auto' ? "automatically choose the method to"
82 : "use the $alter_fk_method method to";
83- print "Will $choice update foreign keys.\n";
84- }
85- else {
86- print "You did not specify --alter-foreign-keys-method, but there "
87- . "are foreign keys that reference the table. "
88- . "Please read the tool's documentation carefully.\n";
89- return 1;
90+ print "Will $choice update foreign keys.\n";
91+ }
92+ else {
93+ print "You did not specify --alter-foreign-keys-method, but there "
94+ . "are foreign keys that reference the table. "
95+ . "Please read the tool's documentation carefully.\n";
96+ return 1;
97+ }
98 }
99 }
100
101@@ -5909,9 +5918,9 @@
102 if ( $child_tables ) {
103 eval {
104 if ( $alter_fk_method eq 'none' ) {
105- print "Not updating foreign keys because "
106- . "--alter-foreign-keys-method=none. Foreign keys "
107- . "that reference the table will no longer work.\n";
108+ # This shouldn't happen, but in case it does we should know.
109+ warn "The tool detected child tables but "
110+ . "--alter-foreign-keys-method=none";
111 }
112 elsif ( $alter_fk_method eq 'rebuild_constraints' ) {
113 rebuild_constraints(

Subscribers

People subscribed via source and target branches