From f96728963e82716ea87985fac2f0b16a6a75eb58 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 10 Apr 2020 12:13:45 -0400 Subject: [PATCH] first cut of kmig-add --- kmig.d/bin/kmig-add | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-) diff --git a/kmig.d/bin/kmig-add b/kmig.d/bin/kmig-add index 3e433c5..3538e9f 100755 --- a/kmig.d/bin/kmig-add +++ b/kmig.d/bin/kmig-add @@ -4,9 +4,7 @@ =head1 NAME -mig-add - This will add the specified files to the mig tracking table for the -schema pointed to by the MIGSCHEMA environment variable in the PostgreSQL -database specified by various PG environment variables. +kmig-add - This will add the specified files to the mig tracking table --headers (the default) and --no-headers are repeatable, and indicate whether subsequent files have headers or not @@ -16,11 +14,11 @@ the next added , which should contain one line per header --headers-file will automatically invoke --no-headers -You'll need to invoke B prior to using commands like B +You'll need to invoke B prior to using commands like B =head1 SYNOPSIS -B [--no-headers|--headers|--headers-file ] [file|--no-headers|--headers|--headers-file ] [...] +B [--no-headers|--headers|--headers-file ] [file|--no-headers|--headers|--headers-file ] [...] =cut @@ -29,8 +27,8 @@ B [--no-headers|--headers|--headers-file ] [file|--no-hea use strict; use Switch; use Env qw( - HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA - MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR + HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW + MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR ); use Pod::Usage; use DBI; @@ -38,12 +36,12 @@ use Cwd 'abs_path'; use FindBin; my $mig_bin = "$FindBin::Bin/"; use lib "$FindBin::Bin/"; -use Mig; +use KMig; pod2usage(-verbose => 2) if ! $ARGV[0] || $ARGV[0] eq '--help'; -Mig::die_if_no_env_migschema(); -Mig::die_if_mig_tracking_table_does_not_exist(); +KMig::die_if_no_env_migschema(); +KMig::die_if_mig_tracking_table_does_not_exist(); my $has_headers = 1; my $headers_file; @@ -99,7 +97,7 @@ sub add_this_file { return; } } - if (Mig::check_for_tracked_file($file)) { + if (KMig::check_for_tracked_file($file)) { print "File already tracked: $file\n"; } else { print 'Adding ('; @@ -109,9 +107,9 @@ sub add_this_file { print ($headers ? ' with headers' : 'without headers'); } print '): ' . "$file\n"; - my $dbh = Mig::db_connect(); + my $dbh = KMig::db_connect(); my $rv = $dbh->do(" - INSERT INTO $MIGSCHEMA.tracked_file ( + INSERT INTO m_tracked_file ( base_filename ,has_headers ,headers_file @@ -120,8 +118,8 @@ sub add_this_file { ," . $dbh->quote($headers) . " ," . $dbh->quote($headers_file) . " ); - ") || die "Error inserting into table $MIGSCHEMA.tracked_file: $!\n"; - Mig::db_disconnect($dbh); + ") || die "Error inserting into table m_tracked_file: $!\n"; + KMig::db_disconnect($dbh); } } -- 1.7.2.5