#!/pro/bin/perl

use strict;
use warnings;
use autodie;

use DBI;
use JSON::PP;
use Test::Smoke::Gateway;
use Test::Smoke::Gateway::Schema;

my $dbi_opt = {
    AutoCommit		=> 1,
    RaiseError		=> 1,
    PrintError		=> 1,
    ChopBlanks		=> 1,
    ShowErrorStatement	=> 1,
    FetchHashKeyName	=> "NAME_lc",
    };

my $dbm = DBI->connect ("dbi:mysql:database=ts_db", undef, undef, $dbi_opt);
my $dbp = Test::Smoke::Gateway::Schema->connect (
			"dbi:Pg:database=tsmb",     undef, undef, $dbi_opt);

my $gw  = Test::Smoke::Gateway->new (schema => $dbp);

{   my $sth = $dbm->prepare ("select rid, json from reports order by rid");
    $sth->execute;
    $sth->bind_columns (\my ($rid, $json));
    my $n = 0;
    while ($sth->fetch) {
	$json or next;
	printf STDERR "%6d %6d %5d\r", ++$n, $rid, length $json;
	$gw->post_report (decode_json ($json));
	}
    }
