Generalize the SQLite DDL generation tool (see next commit)
[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';
7use SQL::Translator;
8use Path::Class 'file';
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@
17/);
18
19die "You need to specify one DDL output filename via --ddl-out\n"
20 if @{$args->{'ddl-out'}||[]} != 1;
21
22die "You need to specify one DBIC schema class via --schema-class\n"
23 if @{$args->{'schema-class'}||[]} != 1;
24
25
26my $schema = use_module( $args->{'schema-class'}[0] )->connect();
27
28my $ddl_fh;
29if ($args->{'ddl-out'}[0] eq '-') {
30 $ddl_fh = *STDOUT;
31}
32else {
33 my $fn = file($args->{'ddl-out'}[0]);
34 $fn->dir->mkpath;
35 open $ddl_fh, '>', $fn
36 or die "Unable to open $fn: $!\n";
37}
38binmode $ddl_fh; # avoid win32 \n crapfest
39
40print $ddl_fh scalar $schema->deployment_statements(
41 'SQLite',
42 undef,
43 undef,
44 {
45 producer_args => { no_transaction => 1 },
46 quote_identifiers => 1,
47 no_comments => 1,
48 },
49);