From 1ca77cb748c3c2195cebc762d7e4aff7585fcd59 Mon Sep 17 00:00:00 2001 From: Mykola Malkov Date: Fri, 14 Feb 2020 17:17:15 +0200 Subject: [PATCH] TT#71209 Add exceptions to compare db tool Sometimes there is divergence in schemes which are inevitable or harmless. So add exceptions' list which is easy to maintain. The format is the following: ================================= /// Where: element-type - tables, columns, views, etc schema-name - name of the schema element-name - name of the element (table, index, etc) ================================= F.e.: views/ldap/ldap_entries/view_definition For columns columns//_ columns/billing/table1_column1/is_nullable Add 1st exception from TT#74728. The reason of this diff is that view was created without schema name on sp1 but the replication statement was written with schema name. Change-Id: I29dd109cefb560fe89d92a430cd6522e4513f7d5 --- helper/compare_dbs.pl | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/helper/compare_dbs.pl b/helper/compare_dbs.pl index d7fa4ed..ad0b95f 100755 --- a/helper/compare_dbs.pl +++ b/helper/compare_dbs.pl @@ -8,6 +8,22 @@ use Data::Compare; use Getopt::Long; use Carp; +# Format: /// +# Where: +# element-type - tables, columns, views, etc +# schema-name - name of the schema +# element-name - name of the element (table, index, etc) +# element-attribute - engine for the table, is_nullable for the column, etc +# F.e.: +# views/ldap/ldap_entries/view_definition +# For columns: columns//_ +# columns/billing/table1_column1/is_nullable +my @diff_exceptions = qw( + views/ldap/ldap_entries/view_definition +); +my @missing_sp1_exceptions = qw(); +my @missing_sp2_exceptions = qw(); + my $credentials_file = '/etc/mysql/sipwise_extra.cnf'; my $argv = { formatter => '', @@ -216,16 +232,39 @@ __USAGE__ return 1; } +sub is_exception { + my ($exceptions, $type, $schema, $element, $attr) = @_; + + $attr //= ''; + foreach my $exception (@{$exceptions}) { + # 'views/ldap/ldap_entries/view_definition' + my ($e_type, $e_schema, $e_element, $e_attr) = split( /\//, $exception ); + $e_attr //= ''; + if ( lc($element) eq lc($e_element) + and lc($type) eq lc($e_type) + and lc($schema) eq lc($e_schema) + and lc($attr) eq lc($e_attr) ) + { + print {*STDERR} "Exception found: $e_type/$e_schema/$e_element/$e_attr\n"; + return 1; + } + } + + return 0; +} + sub print_diff { my ($obj1, $obj2, $object_name, $result, $schema) = @_; foreach my $key ( sort( keys( %{$obj1} ) ) ) { unless ( exists($obj2->{$key}) ) { + next if ( is_exception(\@missing_sp2_exceptions, $object_name, $schema, $key) ); push( @{$result}, "Schema $schema, $object_name element: $key is missing in Schema2" ); next; } foreach my $c_name ( sort( keys( %{ $obj1->{$key} } ) ) ) { unless ( exists($obj2->{$key}->{$c_name}) ) { + next if ( is_exception(\@missing_sp2_exceptions, $object_name, $schema, $key, $c_name) ); push( @{$result}, "Schema $schema, $object_name element: $key.$c_name is missing in Schema2" ); next; } @@ -237,6 +276,7 @@ sub print_diff { $obj2->{$key}->{$c_name} = 'NULL' if ( ! defined($obj2->{$key}->{$c_name}) ); if ( $obj1->{$key}->{$c_name} ne $obj2->{$key}->{$c_name} ) { + next if ( is_exception(\@diff_exceptions, $object_name, $schema, $key, $c_name) ); push( @{$result}, "Schema $schema, $object_name elements: $key.$c_name are not equal:\n ---\n" . " Schema1: $obj1->{$key}->{$c_name}\n" . " Schema2: $obj2->{$key}->{$c_name}" ); @@ -246,11 +286,13 @@ sub print_diff { foreach my $key ( sort( keys( %{$obj2} ) ) ) { unless ( exists($obj1->{$key}) ) { + next if ( is_exception(\@missing_sp1_exceptions, $object_name, $schema, $key) ); push( @{$result}, "Schema $schema, $object_name element: $key is missing in Schema1" ); next; } foreach my $c_name ( sort( keys( %{ $obj2->{$key} } ) ) ) { unless ( exists($obj1->{$key}->{$c_name}) ) { + next if ( is_exception(\@missing_sp1_exceptions, $object_name, $schema, $key, $c_name) ); push( @{$result}, "Schema $schema, $object_name element: $key.$c_name is missing in Schema1" ); next; }