@@ -19,7 +19,7 @@ use Sandbox;
19
19
use SqlModes;
20
20
use File::Temp qw/ tempdir / ;
21
21
22
- plan tests => 6 ;
22
+ plan tests => 10 ;
23
23
24
24
require " $trunk /bin/pt-online-schema-change" ;
25
25
@@ -44,7 +44,7 @@ $sb->load_file('source', "$sample/pt-153.sql");
44
44
45
45
($output , $exit_status ) = full_output(
46
46
sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
47
- ' --execute' ,
47
+ ' --execute' ,
48
48
' --alter' , " ADD UNIQUE INDEX c1 (f2, f3)" ,
49
49
),
50
50
},
64
64
65
65
($output , $exit_status ) = full_output(
66
66
sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
67
- ' --execute' ,
67
+ ' --execute' ,
68
68
' --alter' , " ADD UNIQUE INDEX c1 (f2, f3), PRIMARY KEY (f3), UNIQUE KEY k2 (f3)" ,
69
69
),
70
70
},
88
88
" PT-153 Adding multiple unique indexes -> multime example queries." ,
89
89
);
90
90
91
+ # UNIQUE is possible without INDEX or KEY, we need to check this as well.
92
+ ($output , $exit_status ) = full_output(
93
+ sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
94
+ ' --execute' ,
95
+ ' --alter' , " ADD UNIQUE c1 (f2, f3)" ,
96
+ ),
97
+ },
98
+ );
99
+
100
+ isnt(
101
+ $exit_status ,
102
+ 0,
103
+ " PT-153 Adding unique index without index/key keyword exit status != 0." ,
104
+ );
105
+
106
+ like(
107
+ $output ,
108
+ qr / You are trying to add an unique key. This can result in data loss if the data is not unique/ s ,
109
+ " PT-153 Adding unique index without index/key keyword warning message." ,
110
+ );
111
+
112
+ ($output , $exit_status ) = full_output(
113
+ sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
114
+ ' --execute' ,
115
+ ' --alter' , " ADD UNIQUE(f2, f3)" ,
116
+ ),
117
+ },
118
+ );
119
+
120
+ isnt(
121
+ $exit_status ,
122
+ 0,
123
+ " PT-153 Adding unique index without index/key keyword and index name exit status != 0." ,
124
+ );
125
+
126
+ like(
127
+ $output ,
128
+ qr / You are trying to add an unique key. This can result in data loss if the data is not unique/ s ,
129
+ " PT-153 Adding unique index without index/key keyword and index name warning message." ,
130
+ );
131
+
91
132
$source_dbh -> do(" DROP DATABASE IF EXISTS test" );
92
133
93
134
# #############################################################################
0 commit comments