#!/usr/bin/env perl

use strict;
use warnings;

use DBIx::Class::Schema::Loader qw/ make_schema_at /;

my $debug = 0;
my $dir = './lib';

my %map = (
    Patcher => {
        db_schema => 'patcher',
    },
#    Public => {
#        db_schema => 'public',
#        constraint => qr/ ^(?:
#            foo |
#        )$ /x,
#        moniker_map => {
#            orders => 'Orders',
#        },
#    },
#    Mail => {
#        db_schema => 'mail',
#    },
);


while (my($ns,$opts) = each %map) {

    make_schema_at(
        (defined $ARGV[0]) ? $ARGV[0].'::Schema' : 'Patcher::Schema',
#        'Lychee::Schema',
        {
            overwrite_modifications => 1,
            debug => $debug,
            #exclude => qr/^(foo|bar)/,
            #dump_directory => './lib',
            dump_directory => $dir,
            use_namespaces => 1,
            result_namespace => "Result::$ns",
            resultset_namespace => "ResultSet::$ns",
            components => ["InflateColumn::DateTime"],
            #constraints => [qw/ ^public.* ^flow.* /],
            #constraints => [qw/ ^flow.* /],
            %$opts,
        },
# FIXME        [ 'dbi:Pg:dbname="lychee"', 'www', '',
        [ 'dbi:Pg:dbname="patcher"', 'postgres', '',
#        { loader_class => 'MyLoader' } # optionally
        ],
    );
# FIXME
    Patcher::Schema->_loader_invoked(0);
}

make_schema_at(
        (defined $ARGV[0]) ? $ARGV[0].'::Schema' : 'Patcher::Schema',
#    "Lychee::Schema",
    {
        overwrite_modifications => 1,
        exclude => qr/./,
        dump_directory => $dir,
#        use_namespaces => 1,
    },
# FIXME
    [ 'dbi:Pg:dbname="patcher"', 'postgres', '', ],
);
