seed kmig-sql from mig-sql
authorJason Etheridge <jason@equinoxinitiative.org>
Fri, 10 Apr 2020 02:04:17 +0000 (22:04 -0400)
committerJason Etheridge <jason@equinoxinitiative.org>
Fri, 10 Apr 2020 02:04:17 +0000 (22:04 -0400)
kmig.d/bin/kmig-sql [new file with mode: 0755]

diff --git a/kmig.d/bin/kmig-sql b/kmig.d/bin/kmig-sql
new file mode 100755 (executable)
index 0000000..3909ab3
--- /dev/null
@@ -0,0 +1,48 @@
+#!/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
+    BIBSTART
+);
+use Pod::Usage;
+use DBI;
+use Cwd 'abs_path';
+use FindBin;
+my $mig_bin = "$FindBin::Bin/";
+use lib "$FindBin::Bin/";
+use Mig;
+
+my @MYARGV = (
+     'psql'
+    ,'-vmigschema=' . $MIGSCHEMA
+    ,'-vmigschema_text=\'' . $MIGSCHEMA . '\''
+    ,'-F ' . "\t"
+);
+if (defined $BIBSTART) {
+    push @MYARGV, '-vbibstart=' . $BIBSTART;
+}
+# TODO inject more mig-tracked variables here
+
+system(@MYARGV, @ARGV);
+
+exit 0;
+