Automatically regenerate the example ddl/db from the example Schema
[dbsrgits/DBIx-Class.git] / maint / gen_sqlite_schema_files
index 9fa6a4c..03db999 100755 (executable)
@@ -14,6 +14,7 @@ my $args = {};
 $getopt->getoptions($args, qw/
   ddl-out=s@
   schema-class=s@
+  deploy-to=s@
 /);
 
 die "You need to specify one DDL output filename via --ddl-out\n"
@@ -22,8 +23,19 @@ die "You need to specify one DDL output filename via --ddl-out\n"
 die "You need to specify one DBIC schema class via --schema-class\n"
   if @{$args->{'schema-class'}||[]} != 1;
 
+die "You may not specify more than one deploy path via --deploy-to\n"
+  if @{$args->{'deploy-to'}||[]} > 1;
 
-my $schema = use_module( $args->{'schema-class'}[0] )->connect();
+my $schema = use_module( $args->{'schema-class'}[0] )->connect(
+  $args->{'deploy-to'}
+    ? ( "DBI:SQLite:$args->{'deploy-to'}[0]", undef, undef, { on_connect_do => "PRAGMA synchronous = OFF" } )
+    : ()
+);
+
+if ($args->{'deploy-to'}) {
+  file($args->{'deploy-to'}[0])->dir->mkpath;
+  $schema->deploy({ add_drop_table => 1 });
+}
 
 my $ddl_fh;
 if ($args->{'ddl-out'}[0] eq '-') {