From: Peter Rabbitson Date: Tue, 30 Nov 2010 11:54:20 +0000 (+0000) Subject: Fix MySQL producer attaching View definitions to a schema X-Git-Tag: v0.11008~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3ebe2ce5b1630df3b822f73558562e582fdda50c;p=dbsrgits%2FSQL-Translator.git Fix MySQL producer attaching View definitions to a schema in hash-key order (which sadly *appears* stable after 5.8.2) --- diff --git a/Changes b/Changes index d2762c2..638515d 100644 --- a/Changes +++ b/Changes @@ -5,8 +5,9 @@ * Some minor fixes to squash warnings on new perls * Support a custom_type_name hint when creating enum types in PostgreSQL * Fix sqlt options/pod mismatch (RT#58318) -* Add support for triggers in the MySQL producer * Oracle Producer multicolumn constraint support +* Add support for triggers in the MySQL producer +* Fix unstable order of View's in MySQL parser # ---------------------------------------------------------- # 0.11006 2010-06-03 diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 1f73b23..b521914 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -942,14 +942,13 @@ sub parse { sql => $result->{procedures}->{$proc_name}->{sql}, ); } - my @views = sort { $result->{views}->{ $a }->{'order'} <=> $result->{views}->{ $b }->{'order'} } keys %{ $result->{views} }; - for my $view_name ( keys %{ $result->{'views'} } ) { + for my $view_name ( @views ) { $schema->add_view( name => $view_name, sql => $result->{'views'}->{$view_name}->{sql}, diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 5565308..321f2ff 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -616,17 +616,18 @@ BEGIN { 'Field has right default value' ); is( $t1f2->extra('on update'), 'CURRENT_TIMESTAMP', 'Field has right on update qualifier' ); - + my @views = $schema->get_views; is( scalar @views, 3, 'Right number of views (3)' ); - my ($view3, $view1, $view2) = @views; + + my ($view1, $view2, $view3) = @views; is( $view1->name, 'vs_asset', 'Found "vs_asset" view' ); is( $view2->name, 'vs_asset2', 'Found "vs_asset2" view' ); is( $view3->name, 'vs_asset3', 'Found "vs_asset3" view' ); - like($view1->sql, qr/ALGORITHM=UNDEFINED/, "Detected algorithm"); - like($view1->sql, qr/vs_asset/, "Detected view vs_asset"); - unlike($view1->sql, qr/cfgmgmt_mig/, "Did not detect cfgmgmt_mig"); - + like($view1->sql, qr/ALGORITHM=UNDEFINED/, "Detected algorithm"); + like($view1->sql, qr/vs_asset/, "Detected view vs_asset"); + unlike($view1->sql, qr/cfgmgmt_mig/, "Did not detect cfgmgmt_mig"); + my @procs = $schema->get_procedures; is( scalar @procs, 2, 'Right number of procedures (2)' ); my $proc1 = shift @procs;