DB-CouchDB-Schema
view release on metacpan or search on metacpan
lib/DB/CouchDB/Schema.pm view on Meta::CPAN
sub get_views {
my $self = shift;
my $db = $self->server;
#load our schema
return $db->all_docs({startkey => '"_design/"',
endkey => '"_design/ZZZZZ"'});
}
=head2 dump_db
dumps the entire db to a file for backup
=cut
#TODO(jwall) tool to dump the whole db to a backup file
sub dump_whole_db {
my $self = shift;
my $pretty = shift;
my $db = $self->server;
#load our schema
my $doc_list = $db->all_docs();
my @docs;
while (my $docname = $doc_list->next_key() ) {
my $doc = $db->get_doc($docname);
push @docs, $doc;
script/couch_schema_tool.pl view on Meta::CPAN
#! /usr/bin/env perl
use DB::CouchDB::Schema;
use Getopt::Long;
use Pod::Usage;
#TODO(jwall): Write POD and convert useage to do pod2useage
my ($dump,$load,$create,
$backup, $restore,
$database,$host,$port,$dsn,
$file,$help,
);
my $opts = GetOptions ("dump" => \$dump,
"load" => \$load,
"create" => \$create,
"file=s" => \$file,
"help" => \$help,
"db=s" => \$database,
"host=s" => \$host,
"port=i" => \$port,
"backup" => \$backup,
"restore" => \$restore,
);
sub useage {
my $message = shift;
my $status = shift;
$status = 2 if (! defined $status );
$message = "did not understand options!!$/" if (! defined $message );
pod2usage( -msg => $message,
-exitval => $status );
script/couch_schema_tool.pl view on Meta::CPAN
} elsif ($load && $file) {
open my $fh, '>:encoding(UTF-8)', $file or die $!;
local $/;
$script = <$fh>;
print "loading schema: ", $/, $script;
$db->wipe();
$db->load_schema_from_script($script);
$db->push();
close $fh;
exit 0;
} elsif ($backup && $file) {
# no the backup and restore code
open my $fh, '>:encoding(UTF-8)', $file or die $!;
my $script = $db->dump_whole_db();
print $fh $script;
close $fh;
exit 0;
} elsif ($restore && $file) {
# no the backup and restore code
open my $fh, '>:encoding(UTF-8)', $file or die $!;
local $/;
$script = <$fh>;
print "loading data: ", $/, $script;
$db->wipe();
$db->push_from_script($script);
close $fh;
exit 0;
} else {
useage("Did not understand options!! did you specify one of:", $/,
"--dump, --load, --backup, or --restore with a --file?", $/);
}
} else {
useage("Must have a db and a hostname");
}
__END__
=pod
=head1 NAME
script/couch_schema_tool.pl view on Meta::CPAN
# dump the schema to filename
couch_schema_tool.pl --db=name --host=hostname \
[--port=<port>] \
--dump --file=filename
# load the schema from the filename
couch_schema_tool.pl --db=name --host=hostname \
[--port=<port>] \
--load --file=filename
# backup the database to this filename
couch_schema_tool.pl --db=name --host=hostname \
[--port=<port>] \
--backup --file=filename
# restore the database from this filename
couch_schema_tool.pl --db=name --host=hostname \
[--port=<port>] \
--restore --file=filename
# create a database
couch_schema_tool.pl --create --db=name --host=hostname \
[--port=<port>]
( run in 1.418 second using v1.01-cache-2.11-cpan-49f99fa48dc )