@@ -19,7 +19,7 @@ use Sandbox;
1919use SqlModes;
2020use File::Temp qw/ tempdir / ;
2121
22- plan tests => 6 ;
22+ plan tests => 10 ;
2323
2424require " $trunk /bin/pt-online-schema-change" ;
2525
@@ -44,7 +44,7 @@ $sb->load_file('source', "$sample/pt-153.sql");
4444
4545($output , $exit_status ) = full_output(
4646 sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
47- ' --execute' ,
47+ ' --execute' ,
4848 ' --alter' , " ADD UNIQUE INDEX c1 (f2, f3)" ,
4949 ),
5050 },
6464
6565($output , $exit_status ) = full_output(
6666 sub { pt_online_schema_change::main(@args , " $source_dsn ,D=test,t=t1" ,
67- ' --execute' ,
67+ ' --execute' ,
6868 ' --alter' , " ADD UNIQUE INDEX c1 (f2, f3), PRIMARY KEY (f3), UNIQUE KEY k2 (f3)" ,
6969 ),
7070 },
8888 " PT-153 Adding multiple unique indexes -> multime example queries." ,
8989);
9090
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+
91132$source_dbh -> do(" DROP DATABASE IF EXISTS test" );
92133
93134# #############################################################################
0 commit comments