mig-sql
authorJason Etheridge <jason@esilibrary.com>
Wed, 3 May 2017 19:21:20 +0000 (15:21 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 3 May 2017 19:21:20 +0000 (15:21 -0400)
Mig wrapper for psql.  Plan is to start injecting some useful mig-tracked
variables into psql sessions thus invoked.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>

mig
mig-bin/mig-sql [new file with mode: 0755]

diff --git a/mig b/mig
index ea6cfd1..3f6557b 100755 (executable)
--- a/mig
+++ b/mig
@@ -226,6 +226,10 @@ or for all mapped files if no file is specified.
 Generates <parent table>_prod.sql for the specified linked and mapped file, or
 all such files if no file is specified.
 
+=item B<sql> [arguments...]
+
+A wrapper around the psql command.  At some point the plan is to shove mig-tracked variables into psql sessions.
+
 =back
 
 =cut
@@ -317,6 +321,10 @@ switch($ARGV[0]) {
         Mig::die_if_no_env_migschema();
         standard_invocation(@ARGV);
     }
+    case "sql" {
+        Mig::die_if_no_env_migschema();
+        standard_invocation(@ARGV);
+    }
     case "map" {
         Mig::die_if_no_env_migschema();
     }
diff --git a/mig-bin/mig-sql b/mig-bin/mig-sql
new file mode 100755 (executable)
index 0000000..7c0c2ed
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+###############################################################################
+=pod
+
+=head1 NAME
+
+mig-sql 
+
+A wrapper around the psql command.  At some point the plan is to shove mig-tracked variables into psql sessions.
+
+=head1 SYNOPSIS
+
+B<mig-sql> [arguments...]
+
+=cut
+
+###############################################################################
+
+use strict;
+use Switch;
+use Env qw(
+    HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
+    MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
+);
+use Pod::Usage;
+use DBI;
+use Cwd 'abs_path';
+use FindBin;
+my $mig_bin = "$FindBin::Bin/";
+use lib "$FindBin::Bin/";
+use Mig;
+
+pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help';
+
+system(
+    'psql', 
+    # TODO inject mig-tracked variables here
+    @ARGV
+);
+
+exit 0;
+