Skip to content

Commit

Permalink
Added --getsequences option to export sequences to separate files. Th…
Browse files Browse the repository at this point in the history
…is allows unowned sequences to be exported. Not part of --getall option. See help for more info
  • Loading branch information
keithf4 committed Sep 10, 2012
1 parent fd6eef8 commit f6ecf45
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
10 changes: 9 additions & 1 deletion help
Expand Up @@ -113,7 +113,15 @@ OPTIONS

--getall
gets all tables, views, functions, types and roles. Shortcut to having to set all
--get* options. Does NOT include data
--get* options. Does NOT include data or separate sequence files (see
--getsequences).

--getsequences
If you need to export unowned sequences, set this option. --gettables or --getall
will include any sequence that is owned by a table in that table's output file.
Note that this will export both owned and unowned sequences to the separate
sequence folder. Current sequence values can only be obtained for owned sequences
and will only be output in the table file if --getdata is set.

--getdata
include data in the output files. Note that format will be plaintext (-Fp) unless
Expand Down
35 changes: 31 additions & 4 deletions pg_extractor.pl
Expand Up @@ -8,7 +8,7 @@
# https://github.com/omniti-labs/pg_extractor
# POD Documentation also available by issuing pod2text pg_extractor.pl

# Version 1.2.1
# Version 1.3.0

use Cwd;
use English qw( -no_match_vars);
Expand All @@ -32,7 +32,7 @@
my (@includefunction, @excludefunction);
my (@includeowner, @excludeowner);
my (@regex_incl, @regex_excl);
my (@schemalist, @tablelist, @viewlist, @functionlist, @aggregatelist, @typelist, @acl_list, @commentlist);
my (@schemalist, @tablelist, @viewlist, @functionlist, @aggregatelist, @typelist, @sequencelist, @acl_list, @commentlist);
my (%createdfiles);

+my %ignoredirs = ('.svn' => 1, '.git' => 1);
Expand All @@ -50,7 +50,7 @@
SUFFIX => '.tmp',
DIR => ( File::Spec->tmpdir || $O->{'basedir'} ));

if ($O->{'getschemata'} || $O->{'gettables'} || $O->{'getfuncs'} || $O->{'getviews'} || $O->{'gettypes'}) {
if ($O->{'getschemata'} || $O->{'gettables'} || $O->{'getfuncs'} || $O->{'getviews'} || $O->{'gettypes'} || $O->{'getsequences'}) {
print "Creating temp dump...\n" if !$O->{'quiet'};
create_temp_dump();

Expand Down Expand Up @@ -86,6 +86,10 @@
print "Creating type ddl files...\n" if !$O->{'quiet'};
create_ddl_files(\@typelist, "type");
}
if (@sequencelist) {
print "Creating sequence ddl files...\n" if !$O->{'quiet'};
create_ddl_files(\@sequencelist, "sequence");
}
}

if ($O->{'getroles'}) {
Expand Down Expand Up @@ -168,6 +172,7 @@ sub get_options {
'gettypes!',
'getroles!',
'getall!',
'getsequences!',
'getdata!',
'Fc!',
'sqldump!',
Expand Down Expand Up @@ -249,6 +254,8 @@ sub set_config {
$O->{'getviews'} = 1;
$O->{'gettypes'} = 1;
$O->{'getroles'} = 1;
} elsif ($O->{'getsequences'}) {
# do nothing and allow only sequences to be dumped
} else {
die("NOTICE: No output options set. Please set one or more of the following: --gettables, --getviews, --getprocs, --gettypes, --getroles. Or --getall for all. Use --help to show all options\n");
}
Expand Down Expand Up @@ -479,6 +486,12 @@ sub build_object_lists {
}
}
($objid, $objtype, $objschema, $objname, $objowner) = /(\d+;\s\d+\s\d+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/;
# sequences owned by a table will be output with the table as well and set ownership there.
} elsif ($typetest =~ /^SEQUENCE/) {
if ( /\d+;\s\d+\s\d+\sSEQUENCE\sOWNED\sBY\s\S+\s\S+\s\S+/ ) {
next RESTORE_LABEL;
}
($objid, $objtype, $objschema, $objname, $objowner) = /(\d+;\s\d+\s\d+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/;
} elsif ($typetest =~ /^ACL/) {
$fnname = '';
if (/\(.*\)/) {
Expand Down Expand Up @@ -659,6 +672,16 @@ sub build_object_lists {
};
}

if ($O->{'getsequences'} && $objtype eq "SEQUENCE") {
push @sequencelist, {
"id" => $objid,
"type" => $objtype,
"schema" => $objschema,
"name" => $objname,
"owner" => $objowner,
};
}

if ($objtype eq "COMMENT") {

push @commentlist, {
Expand Down Expand Up @@ -1185,7 +1208,11 @@ =head2 filters
=item --getall
gets all tables, views, functions, types and roles. Shortcut to having to set all --get* options. Does NOT include data
gets all tables, views, functions, types and roles. Shortcut to having to set all --get* options. Does NOT include data or separate sequence files (see --getsequences).
=item --getsequences
If you need to export unowned sequences, set this option. --gettables or --getall will include any sequence that is owned by a table in that table's output file. Note that this will export both owned and unowned sequences to the separate sequence folder. Current sequence values can only be obtained for owned sequences and will only be output in the table file if --getdata is set.
=item --getdata
Expand Down

0 comments on commit f6ecf45

Please sign in to comment.