~stub/slony-i/trunk

« back to all changes in this revision

Viewing changes to tools/altperl/slonik_build_env.pl

  • Committer: Steve Singer
  • Author(s): Marc Cousin
  • Date: 2016-12-10 15:51:40 UTC
  • Revision ID: git-v1:91ede977785e01102a634abd686b19de5e09a4cb
Support multi-schema in slonik_build_env

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
my $dataBasePassword;
20
20
my $dataBasePort;
21
21
my @nodes;
22
 
my $schema = 'public';
 
22
my @schema=();
23
23
my $usage =
24
 
  "$0 -node host:database:user[:password:port] [-node ...] [-schema myschema]
 
24
  "$0 -node host:database:user[:password:port] [-node ...] [-schema myschema] [-schema myschema2...]
25
25
First node is assumed to be the master.
26
26
Default schema is \"public\"\n";
27
27
 
28
 
&usage if ( !GetOptions( 'node=s@' => \@nodes, 'schema=s' => \$schema ) );
 
28
&usage if ( !GetOptions( 'node=s@' => \@nodes, 'schema=s' => \@schema ) );
29
29
 
30
30
die "At least one node is required" if ( scalar(@nodes) < 1 );
31
31
 
 
32
# If we get no schema, use public
 
33
@schema = ('public') unless (@schema);
 
34
 
32
35
my $nodeNumber = 1;
33
36
my $parentString;
34
37
foreach my $node (@nodes) {
58
61
    { RaiseError => 0, PrintError => 0, AutoCommit => 1 } );
59
62
die "connect: $DBI::errstr" if ( !defined($dbh) || $DBI::err );
60
63
 
61
 
# Read in all the user 'normal' tables in $schema (public by default).
 
64
# Read in all the user 'normal' tables in @schema (public by default).
 
65
# put all schemas between single quotes for the query
 
66
my @protected_schema=map("'".$_."'",@schema);
62
67
my $tableQuery = $dbh->prepare( "
63
68
SELECT pg_namespace.nspname || '.' || pg_class.relname,pg_class.relkind,pg_class.relhaspkey 
64
69
FROM pg_namespace,pg_class
65
70
WHERE pg_class.reltype > 0
66
71
AND pg_class.relnamespace = pg_catalog.pg_namespace.oid
67
72
AND (pg_class.relkind = 'r' OR pg_class.relkind = 'S')
68
 
AND pg_namespace.nspname = '$schema' AND pg_namespace.oid = pg_class.relnamespace"
 
73
AND pg_namespace.nspname IN (" . join(',',@protected_schema) . ") AND pg_namespace.oid = pg_class.relnamespace"
69
74
);
70
75
 
71
76
die "prepare(tableQuery): $DBI::errstr"
72
77
  if ( !defined($tableQuery) || $DBI::err );
73
78
die "execute(tableQuery): $DBI::errstr" if ( !$tableQuery->execute() );
74
 
die "No objects to replicate found in schema \"$schema\"\n"
 
79
die "No objects to replicate found in schema(s) \"" . join(',',@schema) . "\"\n"
75
80
  if ( $tableQuery->rows <= 0 );
76
81
 
77
82
my @tablesWithIndexes;