| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use 5.010000; | ||
| 4 | use lib qw( ../blib/lib ) ; | ||
| 5 | use Pg::Loader::Options qw/ get_options /; | ||
| 6 | use Pg::Loader qw/ copy_loader update_loader /; | ||
| 7 | use Pg::Loader::Query qw/ connect_db /; | ||
| 8 | use Pg::Loader::Log qw/ l4p_config /; | ||
| 9 | use Pg::Loader::Misc_2 qw/ sample_config show_sections add_defaults/; | ||
| 10 | use Pg::Loader::Misc qw/ error_check_pgsql print_results ini_conf/; | ||
| 11 | use Data::Dumper; | ||
| 12 | use Log::Log4perl qw/ :easy /; | ||
| 13 | use strict; | ||
| 14 | use warnings; | ||
| 15 | |||
| 16 | our $VERSION = '0.19'; | ||
| 17 | |||
| 18 | my $o = get_options; | ||
| 19 | my $conf = $o->opts; | ||
| 20 | |||
| 21 | ############################# Options Processing | ||
| 22 | $conf->{version} and say $VERSION and exit; | ||
| 23 | $conf->{sample} and say sample_config and exit; | ||
| 24 | |||
| 25 | ############################# M A I N | ||
| 26 | my $ini = ini_conf $conf->{config} ; | ||
| 27 | error_check_pgsql( $conf, $ini ); | ||
| 28 | l4p_config( $conf); | ||
| 29 | my $l = get_logger('Pg::Loader'); | ||
| 30 | $l->info( 'Configuration from ' . ($conf->{config}//='pgloader.conf') ); | ||
| 31 | |||
| 32 | my $dh = connect_db $ini->{pgsql}; | ||
| 33 | show_sections($conf, $ini) unless @ARGV; | ||
| 34 | |||
| 35 | ## MAIN | ||
| 36 | my @stats; | ||
| 37 | |||
| 38 | for ( @ARGV ) { | ||
| 39 | add_defaults( $ini, $_ ) ; | ||
| 40 | # setup per-section logging | ||
| 41 | |||
| 42 | # update, or load table | ||
| 43 | $ini->{$_}{mode} eq 'update' | ||
| 44 | ? (push @stats, update_loader( $conf, $ini, $dh , $_)) | ||
| 45 | : (push @stats, copy_loader( $conf, $ini, $dh , $_)) ; | ||
| 46 | |||
| 47 | }; | ||
| 48 | |||
| 49 | print_results( @stats) if $conf->{summary}; | ||
| 50 | |||
| 51 | END { $dh and $dh->disconnect } | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | __END__ |