--- pgdiff 2003/08/15 22:06:19 1.7 +++ pgdiff 2003/10/31 11:19:45 1.13 @@ -43,7 +43,7 @@ --slavehost=hostname --slaveport=port --slaveuser=username --slavepassword=string --slavefile=filename - --tables[s]=table[,table...] + --table[s]=table[,table...] "; # exit ((scalar(@ARGV) < 2)? 1:0); exit; @@ -119,7 +119,8 @@ $verbose = 1 if ($debug); # init object for scheme in master database -my $mscheme = new Pg::Scheme( 'dbh' => $mdbh, 'DEBUG' => 0 ) || die "can't query schema"; +my $mscheme = new Pg::Scheme( 'dbh' => $mdbh, 'DEBUG' => 0 ) || die "can't query master schema"; +my $sscheme = new Pg::Scheme( 'dbh' => $sdbh, 'DEBUG' => 0 ) || die "can't query slave schema"; # which tables to compare? @@ -127,6 +128,16 @@ debug "Comparing tables: ".join(", ",@tables)."\n"; +# start transaction +print "begin work;\n"; + +# disable active triggers on slave database +my @triggers = $sscheme->get_activetriggers(); + +foreach my $tr (@triggers) { + print "update pg_trigger set tgenabled = false where tgname='$tr';\n"; +} + my $cols; my $diff_total = 0; @@ -134,15 +145,30 @@ my $sth; +print "-- schema...\n"; # diff schema + foreach my $row (@{$mscheme->pg_attribute($table)}) { +# print Dumper($row); + } - # all colums (for insert) +print "-- constraints...\n"; + # diff constraints + foreach my $tr (@{$mscheme->triggers($table)}) { +# print Dumper($tr); + } +print "-- triggers...\n"; + # diff triggers + foreach my $tr (@{$mscheme->triggers($table)}) { +# print Dumper($tr); + } + + # all columns (for insert) my @cols = @{$mscheme->cols($table)}; - # colums compared by a=b + # columns compared by a=b my @cols_notnull = @{$mscheme->cols_notnull($table)}; - # colums compared by a=b or a is null and b is null + # columns compared by a=b or a is null and b is null my @cols_null = @{$mscheme->cols_null($table)}; # primary key columns @@ -152,10 +178,10 @@ my @cols_cmp = @{$mscheme->cols_notpk($table)}; my @cols_skip; # skipped columns - my @cols_test; # all colums to test (without skipped) + my @cols_test; # all columns to test (without skipped) foreach my $row (@{$mscheme->pg_attribute($table)}) { - # attname | format_type | attnotnull | atthasdef | attnum + # attname format_type attnotnull atthasdef attnum default references # FIXME: do something with attributes which shouldn't be compared # (date, time, datetime, timestamp) @@ -219,11 +245,11 @@ debug_sql($msql); - my $msth = $mdbh->prepare($msql) || die; - $msth->execute() || die; + my $msth = $mdbh->prepare($msql) || die $mdbh->errstr; + $msth->execute() || die $msth->errstr; - my $ssth = $sdbh->prepare($ssql) || die; - $ssth->execute() || die; + my $ssth = $sdbh->prepare($ssql) || die $sdbh->errstr; + $ssth->execute() || die $ssth->errstr; my $diff_row = 0; @@ -381,7 +407,7 @@ if ($verbose) { if ($diff_total == 0) { - print STDERR "databases are same"; + print STDERR "databases are same\n"; } elsif ($diff_total > 0) { print STDERR "$diff_total differences in all tables\n"; } else { @@ -389,5 +415,12 @@ } } +# enable triggers again on slave +foreach my $tr (@triggers) { + print "update pg_trigger set tgenabled = true where tgname='$tr';\n"; +} +# end transaction +print "commit;\n"; + $mdbh->disconnect(); $sdbh->disconnect();