From: Chris Hilton Date: Wed, 14 Mar 2007 20:23:30 +0000 (+0000) Subject: Added diff comparison of views and procedures X-Git-Tag: v0.11008~370 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7ac784ff272b0095c811bff6d581eb61eb34fb39;p=dbsrgits%2FSQL-Translator.git Added diff comparison of views and procedures --- diff --git a/lib/SQL/Translator/Diff.pm b/lib/SQL/Translator/Diff.pm index c7c5b6f..4d1a727 100644 --- a/lib/SQL/Translator/Diff.pm +++ b/lib/SQL/Translator/Diff.pm @@ -306,6 +306,53 @@ END } push(@diffs, @diffs_at_end); + # Procedures + my(%checked_procs, @diffs_proc_creates, @diffs_proc_drops); + PROC: + for my $p_tar ( $target_schema->get_procedures ) { + for my $p_src ( $source_schema->get_procedures ) { + if ( $p_tar->equals($p_src, $case_insensitive) ) { + $checked_procs{$p_src} = 1; + next PROC; + } + } + push @diffs_proc_creates, $p_tar->sql; + } + PROC2: + for my $p_src ( $source_schema->get_procedures ) { + next if $checked_procs{$p_src}; + for my $p_tar ( $target_schema->get_procedures ) { + next PROC2 if $p_src->equals($p_tar, $case_insensitive); + } + my $proc_ident = $p_src->owner ? sprintf("[%s].%s", $p_src->owner, $p_src->name) : $p_src->name; + push @diffs_proc_drops, "DROP PROCEDURE $proc_ident;\nGO\n"; + } + + # Views + my(%checked_views, @diffs_view_creates, @diffs_view_drops); + VIEW: + for my $v_tar ( $target_schema->get_views ) { + for my $v_src ( $source_schema->get_views ) { + if ( $v_tar->equals($v_src, $case_insensitive) ) { + $checked_views{$v_src} = 1; + next VIEW; + } + } + push @diffs_view_creates, $v_tar->sql; + } + VIEW2: + for my $v_src ( $source_schema->get_views ) { + next if $checked_views{$v_src}; + for my $v_tar ( $target_schema->get_views ) { + next VIEW2 if $v_src->equals($v_tar, $case_insensitive); + } + my $view_ident = $v_src->name; + push @diffs_view_drops, "DROP VIEW $view_ident;\nGO\n"; + } + + push @diffs, @diffs_view_drops, @diffs_view_creates, + @diffs_proc_creates, @diffs_proc_drops; + if ( @diffs ) { if ( $target_db !~ /^(MySQL|SQLServer|Oracle)$/ ) { unshift(@diffs, "-- Target database $target_db is untested/unsupported!!!");