Only normalize conditions during resolution time, instead on every ->search
[dbsrgits/DBIx-Class.git] / maint / gen_sqlite_schema_files
CommitLineData
a2c29633 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use Module::Runtime 'use_module';
e48635f7 7use DBIx::Class::_Util qw(mkdir_p parent_dir);
a2c29633 8use SQL::Translator;
a2c29633 9use Getopt::Long;
10my $getopt = Getopt::Long::Parser->new(
11 config => [qw/gnu_getopt bundling_override no_ignore_case/]
12);
13my $args = {};
14$getopt->getoptions($args, qw/
15 ddl-out=s@
16 schema-class=s@
6635c6d2 17 deploy-to=s@
a2c29633 18/);
19
20die "You need to specify one DDL output filename via --ddl-out\n"
21 if @{$args->{'ddl-out'}||[]} != 1;
22
23die "You need to specify one DBIC schema class via --schema-class\n"
24 if @{$args->{'schema-class'}||[]} != 1;
25
6635c6d2 26die "You may not specify more than one deploy path via --deploy-to\n"
27 if @{$args->{'deploy-to'}||[]} > 1;
a2c29633 28
37b5ab51 29local $ENV{DBI_DSN};
6635c6d2 30my $schema = use_module( $args->{'schema-class'}[0] )->connect(
31 $args->{'deploy-to'}
32 ? ( "DBI:SQLite:$args->{'deploy-to'}[0]", undef, undef, { on_connect_do => "PRAGMA synchronous = OFF" } )
33 : ()
34);
35
36if ($args->{'deploy-to'}) {
e48635f7 37 mkdir_p parent_dir $args->{'deploy-to'}[0];
6635c6d2 38 $schema->deploy({ add_drop_table => 1 });
39}
a2c29633 40
41my $ddl_fh;
42if ($args->{'ddl-out'}[0] eq '-') {
43 $ddl_fh = *STDOUT;
44}
45else {
e48635f7 46 mkdir_p parent_dir $args->{'ddl-out'}[0];
47 open $ddl_fh, '>', $args->{'ddl-out'}[0]
48 or die "Unable to open $args->{'ddl-out'}[0]: $!\n";
a2c29633 49}
50binmode $ddl_fh; # avoid win32 \n crapfest
51
52print $ddl_fh scalar $schema->deployment_statements(
53 'SQLite',
54 undef,
55 undef,
56 {
57 producer_args => { no_transaction => 1 },
58 quote_identifiers => 1,
59 no_comments => 1,
60 },
61);