6 use Module::Runtime 'use_module';
8 use Path::Class 'file';
10 my $getopt = Getopt::Long::Parser->new(
11 config => [qw/gnu_getopt bundling_override no_ignore_case/]
14 $getopt->getoptions($args, qw/
20 die "You need to specify one DDL output filename via --ddl-out\n"
21 if @{$args->{'ddl-out'}||[]} != 1;
23 die "You need to specify one DBIC schema class via --schema-class\n"
24 if @{$args->{'schema-class'}||[]} != 1;
26 die "You may not specify more than one deploy path via --deploy-to\n"
27 if @{$args->{'deploy-to'}||[]} > 1;
30 my $schema = use_module( $args->{'schema-class'}[0] )->connect(
32 ? ( "DBI:SQLite:$args->{'deploy-to'}[0]", undef, undef, { on_connect_do => "PRAGMA synchronous = OFF" } )
36 if ($args->{'deploy-to'}) {
37 file($args->{'deploy-to'}[0])->dir->mkpath;
38 $schema->deploy({ add_drop_table => 1 });
42 if ($args->{'ddl-out'}[0] eq '-') {
46 my $fn = file($args->{'ddl-out'}[0]);
48 open $ddl_fh, '>', $fn
49 or die "Unable to open $fn: $!\n";
51 binmode $ddl_fh; # avoid win32 \n crapfest
53 print $ddl_fh scalar $schema->deployment_statements(
58 producer_args => { no_transaction => 1 },
59 quote_identifiers => 1,