# vim: set ft=perl:
# -------------------------------------------------------------------
-# $Id: sqlt-diff,v 1.13 2006-05-20 09:02:47 schiffbruechige Exp $
+# $Id: sqlt-diff,v 1.14 2007-03-01 22:16:00 duality72 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 The SQLFairy Authors
#
-d|--debug Show debugging info
-t|--trace Turn on tracing for Parse::RecDescent
-c|--case-insensitive Compare tables/columns case-insenstiviely
+ --ignore-index-names Ignore index name differences
+ --ignore-constraint-names Ignore constraint name differences
=head1 DESCRIPTION
use SQL::Translator::Schema::Constants;
use vars qw( $VERSION );
-$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
-my ( @input, $list, $help, $debug, $trace, $caseopt );
+my ( @input, $list, $help, $debug, $trace, $caseopt , $ignore_index_names, $ignore_constraint_names );
for my $arg ( @ARGV ) {
if ( $arg =~ m/^-?-l(ist)?$/ ) {
$list = 1;
elsif ( $arg =~ m/^-?-t(race)?$/ ) {
$trace = 1;
}
- elsif ( $arg =~ m/^-?-c(ase-insenstive)?$/ ) {
+ elsif ( $arg =~ m/^-?-c(ase-insensitive)?$/ ) {
$caseopt = 1;
}
+ elsif ( $arg =~ m/^--ignore-index-names$/ ) {
+ $ignore_index_names = 1;
+ }
+ elsif ( $arg =~ m/^--ignore-constraint-names?$/ ) {
+ $ignore_constraint_names = 1;
+ }
elsif ( $arg =~ m/^([^=]+)=(.+)$/ ) {
push @input, { file => $1, parser => $2 };
}
my $result = SQL::Translator::Diff::schema_diff($source_schema, $source_db,
$target_schema, $target_db,
- { caseopt => $caseopt,
- debug => $debug,
- trace => $trace });
+ { caseopt => $caseopt,
+ ignore_index_names => $ignore_index_names,
+ ignore_constraint_names => $ignore_constraint_names,
+ debug => $debug,
+ trace => $trace });
if($result)
{
print $result;
my $caseopt = $options->{caseopt} || 0;
my $debug = $options->{debug} || 0;
my $trace = $options->{trace} || 0;
+ my $ignore_index_names = $options->{ignore_index_names} || 0;
+ my $ignore_constraint_names = $options->{ignore_constraint_names} || 0;
my $case_insensitive = $source_db =~ /SQLServer/ || $caseopt;
INDEX:
for my $i_tar ( $tar_table->get_indices ) {
for my $i_src ( $src_table->get_indices ) {
- if ( $i_tar->equals($i_src, $case_insensitive) ) {
+ if ( $i_tar->equals($i_src, $case_insensitive, $ignore_index_names) ) {
$checked_indices{$i_src} = 1;
next INDEX;
}
for my $i_src ( $src_table->get_indices ) {
next if $checked_indices{$i_src};
for my $i_tar ( $tar_table->get_indices ) {
- next INDEX2 if $i_src->equals($i_tar, $case_insensitive);
+ next INDEX2 if $i_src->equals($i_tar, $case_insensitive, $ignore_index_names);
}
$source_db =~ /SQLServer/
? push @diffs_index_drops, "DROP INDEX $tar_table_name.".$i_src->name.";"
CONSTRAINT:
for my $c_tar ( $tar_table->get_constraints ) {
next if $target_db =~ /Oracle/ &&
- $c_tar->type eq UNIQUE && $c_tar->name =~ /^SYS_/i;
+ $c_tar->type eq UNIQUE && $c_tar->name =~ /^SYS_/i; # Ignore Oracle SYS_ constraints hack
for my $c_src ( $src_table->get_constraints ) {
- if ( $c_tar->equals($c_src, $case_insensitive) ) {
+ if ( $c_tar->equals($c_src, $case_insensitive, $ignore_constraint_names) ) {
$checked_constraints{$c_src} = 1;
next CONSTRAINT;
}
CONSTRAINT2:
for my $c_src ( $src_table->get_constraints ) {
next if $source_db =~ /Oracle/ &&
- $c_src->type eq UNIQUE && $c_src->name =~ /^SYS_/i;
+ $c_src->type eq UNIQUE && $c_src->name =~ /^SYS_/i; # Ignore Oracle SYS_ constraints hack
next if $checked_constraints{$c_src};
for my $c_tar ( $tar_table->get_constraints ) {
- next CONSTRAINT2 if $c_src->equals($c_tar, $case_insensitive);
+ next CONSTRAINT2 if $c_src->equals($c_tar, $case_insensitive, $ignore_constraint_names);
}
if ( $c_src->type eq UNIQUE ) {
push @diffs_constraint_drops, "ALTER TABLE $tar_table_name DROP INDEX ".
package SQL::Translator::Schema::Constraint;
# ----------------------------------------------------------------------
-# $Id: Constraint.pm,v 1.20 2007-02-27 20:45:30 duality72 Exp $
+# $Id: Constraint.pm,v 1.21 2007-03-01 22:15:59 duality72 Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.21 $ =~ /(\d+)\.(\d+)/;
my %VALID_CONSTRAINT_TYPE = (
PRIMARY_KEY, 1,
my $self = shift;
my $other = shift;
my $case_insensitive = shift;
+ my $ignore_constraint_names = shift;
return 0 unless $self->SUPER::equals($other);
return 0 unless $self->type eq $other->type;
- return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name;
+ unless ($ignore_constraint_names) {
+ return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name;
+ }
return 0 unless $self->deferrable eq $other->deferrable;
#return 0 unless $self->is_valid eq $other->is_valid;
return 0 unless $case_insensitive ? uc($self->table->name) eq uc($other->table->name)
package SQL::Translator::Schema::Index;
# ----------------------------------------------------------------------
-# $Id: Index.pm,v 1.14 2005-08-10 16:46:55 duality72 Exp $
+# $Id: Index.pm,v 1.15 2007-03-01 22:16:00 duality72 Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/;
my %VALID_INDEX_TYPE = (
UNIQUE, 1,
my $self = shift;
my $other = shift;
my $case_insensitive = shift;
+ my $ignore_index_names = 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;
+ unless ($ignore_index_names) {
+ 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;
return 0 unless $self->type eq $other->type;
my $selfFields = join(":", $self->fields);
: catfile($Bin, "t", @create2);
BEGIN {
- maybe_plan(20,
+ maybe_plan(23,
'SQL::Translator::Parser::SQLite',
'SQL::Translator::Parser::MySQL',
'SQL::Translator::Parser::Oracle',
? catfile($Bin, @mysql_create2)
: catfile($Bin, "t", @mysql_create2);
+# Test for differences
@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
$out = `@cmd`;
"Detected missing rock star field");
like($out, qr/ALTER TABLE person ADD UNIQUE UC_person_id/,
"Detected missing unique constraint");
+like($out, qr/CREATE UNIQUE INDEX unique_name/,
+ "Detected unique index with different name");
like($out, qr/ALTER TABLE person ENGINE=InnoDB;/,
"Detected altered table option");
-like($out, qr/ALTER TABLE employee DROP FOREIGN KEY/,
+like($out, qr/ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E/,
"Detected drop foreign key");
-like($out, qr/ALTER TABLE employee ADD CONSTRAINT/,
+like($out, qr/ALTER TABLE employee ADD CONSTRAINT FK5302D47D93FE702E_diff/,
"Detected add constraint");
unlike($out, qr/ALTER TABLE employee ADD PRIMARY KEY/, "Primary key looks different when it shouldn't");
-
+
+# Test ignore parameters
+@cmd = ($sqlt_diff, "--ignore-index-names", "--ignore-constraint-names",
+ "$mysql_create1=MySQL", "$mysql_create2=MySQL");
+$out = `@cmd`;
+
+unlike($out, qr/CREATE UNIQUE INDEX unique_name/,
+ "Detected unique index with different name");
+unlike($out, qr/ALTER TABLE employee ADD CONSTRAINT FK5302D47D93FE702E_diff/,
+ "Detected add constraint");
+
+# Test for sameness
@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
$out = `@cmd`;
UNIQUE KEY UC_person_id (person_id)
) ENGINE=InnoDB;
-create unique index u_name on person (name);
+create unique index unique_name on person (name);
create table employee (
position varchar(50),