Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "notablespace" option to same_schema #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ my @cleanfiles = (
'/tmp/cptesting_socket3',
'/tmp/cptesting_socket4',
'/tmp/cptesting_socket5',
'test_tablespace_check_postgres/',
'test_tablespace_check_postgres2/',
'test_tablespace_check_postgres3/',
'test_tablespace_check_postgres4/',
'test_tablespace_check_postgres5/',
);

print "Configuring check_postgres $VERSION\n";
Expand Down
8 changes: 8 additions & 0 deletions check_postgres.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6992,6 +6992,12 @@ sub check_same_schema {
next;
}

## Do not show tablespace differences if filtered out with "notablespace"
if (($col eq 'tablespace' or $col eq 'reltablespace')
and $opt{filtered}{notablespace}) {
next;
}

## Do not show function body differences if filtered out with "nofuncbody"
## Also skip if the equivalent 'dash' and 'empty'
if ($item eq 'function'
Expand Down Expand Up @@ -9844,6 +9850,8 @@ =head2 B<same_schema>

The filter option "noperm" prevents comparison of object permissions.

The filter option "notablespace" prevents comparison of object tablespaces.

To provide the second database, just append the differences to the first one
by a call to the appropriate connection argument. For example, to compare
databases on hosts alpha and bravo, use "--dbhost=alpha,bravo". Also see the
Expand Down
16 changes: 15 additions & 1 deletion t/02_same_schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use 5.006;
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 76;
use Test::More tests => 78;
use lib 't','.';
use CP_Testing;

Expand Down Expand Up @@ -308,6 +308,20 @@ Table "public.berri":
\s*Database 1: r/check_postgres_testing
\s*Database 2: wd/check_postgres_testing\s*}s,
$t);
$dbh2->do(q{REVOKE UPDATE,DELETE ON TABLE berri FROM alternate_owner});
$dbh1->do(q{REVOKE SELECT ON TABLE berri FROM alternate_owner});

$t = qq{$S reports tablespace differences};
$dbh1->do(q{ALTER TABLE berri SET TABLESPACE check_postgres});
like ($cp1->run($connect2),
qr{^$label CRITICAL.*Items not matched: 1 .*
Table "public.berri":
\s*"reltablespace" is different:.*
\s*"tablespace" is different:.*}s,
$t);

$t = qq{$S does not report tablespace differences if the 'notablespace' filter is given};
like ($cp1->run("$connect2 --filter=notablespace"), qr{^$label OK}, $t);

$t = qq{$S does not report table differences if the 'notable' filter is given};
like ($cp1->run("$connect3 --filter=notable"), qr{^$label OK}, $t);
Expand Down
21 changes: 21 additions & 0 deletions t/CP_Testing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sub new {
my $self = {
started => time(),
dbdir => $arg->{dbdir} || 'test_database_check_postgres',
tsdir => $arg->{tsdir} || 'test_tablespace_check_postgres',
testuser => $arg->{testuser} || 'check_postgres_testing',
testuser2 => $arg->{testuser2} || 'powerless_pete',
};
Expand All @@ -32,6 +33,9 @@ sub new {
if (exists $arg->{dbnum} and $arg->{dbnum}) {
$self->{dbdir} .= $arg->{dbnum};
}
if (exists $arg->{dbnum} and $arg->{dbnum}) {
$self->{tsdir} .= $arg->{dbnum};
}
return bless $self => $class;
}

Expand Down Expand Up @@ -84,6 +88,18 @@ sub test_database_handle {
mkdir $dbdir;
}

## Create the test tablespace directory if it does not exist
my $tsdir = $arg->{tsdir} || $self->{tsdir};
$DEBUG and warn qq{Tablespacedir: $tsdir\n};
if (! -d $tsdir) {

-e $tsdir and die qq{Oops: I cannot create "$tsdir", there is already a file there!\n};

Test::More::diag qq{Creating tablespace in directory "$tsdir"\n};

mkdir $tsdir;
}

my $datadir = "$dbdir/data space";
if (! -e $datadir) {

Expand Down Expand Up @@ -350,6 +366,11 @@ sub test_database_handle {
}
}

$dbh->{RaiseError} = 1;
my $tablespaces = $dbh->selectall_hashref('SELECT spcname FROM pg_tablespace', 'spcname');
$dbh->do("CREATE TABLESPACE check_postgres LOCATION '$here/$tsdir'") unless ($tablespaces->{check_postgres});
$dbh->{RaiseError} = 0;

my $databases = $dbh->selectall_hashref('SELECT datname FROM pg_database', 'datname');
$dbh->do('CREATE DATABASE beedeebeedee') unless ($databases->{beedeebeedee});
$dbh->do('CREATE DATABASE ardala') unless ($databases->{ardala});
Expand Down