#!/usr/bin/perl

use strict;
use warnings;
use open ':std', ':encoding(UTF-8)';

use JSON::XS;
use FileHandle;
use File::Basename;
use Parallel::ForkManager;
use Text::CSV::Easy(qw/csv_build csv_parse/);

use lib '/app/tools/common/lib';
use Common::Session;

use lib '/app/tools/stats/lib';
use Stats::Redshift::ExportSchema;

$| = 1;

my ( $opt, $usage ) = clopt(
    [ 'help|?|h'     => "Print usage message and exit", { 'implies'   => { 'database' => 1 } } ],
    [ 'database|d=s' => 'Database to load',             { 'requiured' => 1 } ],
    [ 'refresh|r'    => '"Refresh" the table - remove existing data' ],
);
if ( $opt->help ) {
    logMessage( 'info', $usage->text, 'options' );
    exit 1;
}

my $stat = Stats::Redshift::ExportSchema->new();
$stat->refresh( $opt->refresh );
$stat->export_database($opt->database);
