From: Chris Hilton Date: Wed, 21 Mar 2007 15:20:50 +0000 (+0000) Subject: Added options for ignoring the differences in SQL for views and procedures X-Git-Tag: v0.11008~364 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1a895ce01722a31d6311111e9b8e6b177ff7d7d;p=dbsrgits%2FSQL-Translator.git Added options for ignoring the differences in SQL for views and procedures --- diff --git a/bin/sqlt-diff b/bin/sqlt-diff index ee47c8b..5e8167b 100755 --- a/bin/sqlt-diff +++ b/bin/sqlt-diff @@ -2,7 +2,7 @@ # vim: set ft=perl: # ------------------------------------------------------------------- -# $Id: sqlt-diff,v 1.17 2007-03-19 17:15:54 duality72 Exp $ +# $Id: sqlt-diff,v 1.18 2007-03-21 15:20:50 duality72 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 The SQLFairy Authors # @@ -51,6 +51,8 @@ Options: --output-db= This Producer will be used instead of one corresponding to parser1 to format output for new tables + --ignore-view-sql Ignore view SQL differences + --ignore-proc-sql Ignore procedure SQL differences =head1 DESCRIPTION @@ -107,10 +109,11 @@ use SQL::Translator::Diff; use SQL::Translator::Schema::Constants; use vars qw( $VERSION ); -$VERSION = sprintf "%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/; -my ( @input, $list, $help, $debug, $trace, $caseopt,$ignore_index_names, - $ignore_constraint_names, $output_db, $mysql_parser_version ); +my ( @input, $list, $help, $debug, $trace, $caseopt, $ignore_index_names, + $ignore_constraint_names, $output_db, $mysql_parser_version, + $ignore_view_sql, $ignore_proc_sql ); for my $arg ( @ARGV ) { if ( $arg =~ m/^-?-l(ist)?$/ ) { $list = 1; @@ -139,6 +142,12 @@ for my $arg ( @ARGV ) { elsif ( $arg =~ m/^--output-db=(.+)$/ ) { $output_db = $1; } + elsif ( $arg =~ m/^--ignore-view-sql$/ ) { + $ignore_view_sql = 1; + } + elsif ( $arg =~ m/^--ignore-proc-sql$/ ) { + $ignore_proc_sql = 1; + } elsif ( $arg =~ m/^([^=]+)=(.+)$/ ) { push @input, { file => $1, parser => $2 }; } @@ -169,7 +178,7 @@ my ( $source_schema, $source_db, $target_schema, $target_db ) = map { die "Unable to read file '$file'\n" unless -r $file; die "'$parser' is an invalid parser\n" unless $valid_parsers{ $parser }; - my $t = SQL::Translator->new(parser_args => {mysql_parser_version => $mysql_parser_version || 0}); + my $t = SQL::Translator->new(parser_args => {mysql_parser_version => $mysql_parser_version}); $t->debug( $debug ); $t->trace( $trace ); $t->parser( $parser ) or die $tr->error; @@ -187,6 +196,8 @@ my $result = SQL::Translator::Diff::schema_diff($source_schema, $source_db, { caseopt => $caseopt, ignore_index_names => $ignore_index_names, ignore_constraint_names => $ignore_constraint_names, + ignore_view_sql => $ignore_view_sql, + ignore_proc_sql => $ignore_proc_sql, output_db => $output_db, debug => $debug, trace => $trace }); diff --git a/lib/SQL/Translator/Diff.pm b/lib/SQL/Translator/Diff.pm index 5759f11..43b688b 100644 --- a/lib/SQL/Translator/Diff.pm +++ b/lib/SQL/Translator/Diff.pm @@ -14,6 +14,8 @@ sub schema_diff my $trace = $options->{trace} || 0; my $ignore_index_names = $options->{ignore_index_names} || 0; my $ignore_constraint_names = $options->{ignore_constraint_names} || 0; + my $ignore_view_sql = $options->{ignore_view_sql} || 0; + my $ignore_proc_sql = $options->{ignore_proc_sql} || 0; my $output_db = $options->{output_db} || $source_db; my $tar_name = $target_schema->name; @@ -311,7 +313,7 @@ END 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) ) { + if ( $p_tar->equals($p_src, $case_insensitive, $ignore_proc_sql) ) { $checked_procs{$p_src} = 1; next PROC; } @@ -322,7 +324,7 @@ END 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); + next PROC2 if $p_src->equals($p_tar, $case_insensitive, $ignore_proc_sql); } 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"; @@ -333,7 +335,7 @@ END 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) ) { + if ( $v_tar->equals($v_src, $case_insensitive, $ignore_view_sql) ) { $checked_views{$v_src} = 1; next VIEW; } @@ -344,7 +346,7 @@ END 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); + next VIEW2 if $v_src->equals($v_tar, $case_insensitive, $ignore_view_sql); } my $view_ident = $v_src->name; push @diffs_view_drops, "DROP VIEW $view_ident;\nGO\n"; diff --git a/lib/SQL/Translator/Schema/Procedure.pm b/lib/SQL/Translator/Schema/Procedure.pm index 1f71227..f54f846 100644 --- a/lib/SQL/Translator/Schema/Procedure.pm +++ b/lib/SQL/Translator/Schema/Procedure.pm @@ -1,7 +1,7 @@ package SQL::Translator::Schema::Procedure; # ---------------------------------------------------------------------- -# $Id: Procedure.pm,v 1.7 2007-03-14 20:22:58 duality72 Exp $ +# $Id: Procedure.pm,v 1.8 2007-03-21 15:20:50 duality72 Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -54,7 +54,7 @@ use base 'SQL::Translator::Schema::Object'; use vars qw($VERSION); -$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/; # ---------------------------------------------------------------------- @@ -256,23 +256,26 @@ Determines if this procedure is the same as another my $self = shift; my $other = shift; my $case_insensitive = shift; + my $ignore_sql = shift; return 0 unless $self->SUPER::equals($other); return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; - my $selfSql = $self->sql; - my $otherSql = $other->sql; - # Remove comments - $selfSql =~ s/--.*$//mg; - $otherSql =~ s/--.*$//mg; - # Collapse whitespace to space to avoid whitespace comparison issues - $selfSql =~ s/\s+/ /sg; - $otherSql =~ s/\s+/ /sg; - return 0 unless $selfSql eq $otherSql; + unless ($ignore_sql) { + my $selfSql = $self->sql; + my $otherSql = $other->sql; + # Remove comments + $selfSql =~ s/--.*$//mg; + $otherSql =~ s/--.*$//mg; + # Collapse whitespace to space to avoid whitespace comparison issues + $selfSql =~ s/\s+/ /sg; + $otherSql =~ s/\s+/ /sg; + return 0 unless $selfSql eq $otherSql; + } return 0 unless $self->_compare_objects(scalar $self->parameters, scalar $other->parameters); # return 0 unless $self->comments eq $other->comments; - return 0 unless $case_insensitive ? uc($self->owner) eq uc($other->owner) : $self->owner eq $other->owner; +# return 0 unless $case_insensitive ? uc($self->owner) eq uc($other->owner) : $self->owner eq $other->owner; return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra); return 1; } diff --git a/lib/SQL/Translator/Schema/View.pm b/lib/SQL/Translator/Schema/View.pm index 401cbc5..cada3e1 100644 --- a/lib/SQL/Translator/Schema/View.pm +++ b/lib/SQL/Translator/Schema/View.pm @@ -1,7 +1,7 @@ package SQL::Translator::Schema::View; # ---------------------------------------------------------------------- -# $Id: View.pm,v 1.13 2007-03-14 20:22:58 duality72 Exp $ +# $Id: View.pm,v 1.14 2007-03-21 15:20:50 duality72 Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -50,7 +50,7 @@ use base 'SQL::Translator::Schema::Object'; use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/; # ---------------------------------------------------------------------- @@ -225,20 +225,23 @@ Determines if this view is the same as another my $self = shift; my $other = shift; my $case_insensitive = shift; + my $ignore_sql = shift; return 0 unless $self->SUPER::equals($other); return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; #return 0 unless $self->is_valid eq $other->is_valid; - my $selfSql = $self->sql; - my $otherSql = $other->sql; - # Remove comments - $selfSql =~ s/--.*$//mg; - $otherSql =~ s/--.*$//mg; - # Collapse whitespace to space to avoid whitespace comparison issues - $selfSql =~ s/\s+/ /sg; - $otherSql =~ s/\s+/ /sg; - return 0 unless $selfSql eq $otherSql; + unless ($ignore_sql) { + my $selfSql = $self->sql; + my $otherSql = $other->sql; + # Remove comments + $selfSql =~ s/--.*$//mg; + $otherSql =~ s/--.*$//mg; + # Collapse whitespace to space to avoid whitespace comparison issues + $selfSql =~ s/\s+/ /sg; + $otherSql =~ s/\s+/ /sg; + return 0 unless $selfSql eq $otherSql; + } my $selfFields = join(":", $self->fields); my $otherFields = join(":", $other->fields);