App-Netdisco
view release on metacpan or search on metacpan
bin/netdisco-db-deploy view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
our $home;
BEGIN {
use FindBin;
FindBin::again();
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
# try to find a localenv if one isn't already in place.
if (!exists $ENV{PERL_LOCAL_LIB_ROOT}) {
use File::Spec;
my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
$localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
die "Sorry, can't find libs required for App::Netdisco.\n"
if !exists $ENV{PERLBREW_PERL};
}
}
BEGIN {
use Path::Class;
# stuff useful locations into @INC and $PATH
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
use Config;
$ENV{PATH} = $FindBin::RealBin . $Config{path_sep} . $ENV{PATH};
}
use App::Netdisco;
use Dancer ':script';
use Try::Tiny;
use App::Netdisco::DB::Deploy qw(parse_args run_deploy deploy_schema);
use App::Netdisco::DB::SchemaCheck;
use App::Netdisco::Util::PostgresFloor 'warn_postgres_floor_all_tenants';
=head1 NAME
netdisco-db-deploy - Database deployment for Netdisco
=head1 USAGE
This script upgrades or initializes a Netdisco database schema.
~/bin/netdisco-db-deploy [--redeploy-all | --force-step N | --check]
This script connects to the database and runs without user interaction. If
there's no Netdisco schema, it is deployed. If there's an unversioned schema
then versioning is added, and updates applied. Otherwise only necessary
updates are applied to an already versioned schema.
Pre-existing requirements are that there's a working database connection and a
user with rights to create tables in that database. These settings are defined
in your environment YAML file (default C<~/environments/deployment.yml>).
From version 38 on, if a step fails, the script stops at that step and exits
non-zero.
Nothing from the failed step is applied. The message names the step file, the
failing statement and the PostgreSQL error, and prints the commands to go on.
=head1 OPTIONS
=over 4
=item C<--redeploy-all>
Replays every upgrade step from version 2, tolerating the errors that come
from steps already applied. It changes no data that Netdisco or an
administrator maintains. It repeats one cleanup: step 39-40 deletes vlan-0
( run in 0.584 second using v1.01-cache-2.11-cpan-ac8be02dad9 )