2 ###############################################################################
7 mig-add - This will add the specified files to the mig tracking table for the
8 schema pointed to by the MIGSCHEMA environment variable in the PostgreSQL
9 database specified by various PG environment variables. <inhales, exhales>
11 --headers (the default) and --no-headers are repeatable, and indicate whether
12 subsequent files have headers or not
14 --headers-file specifies a text file <hfile> defining the column headers for
15 the next added <file>, which should contain one line per header
17 --headers-file will automatically invoke --no-headers
19 You'll need to invoke B<mig-init> prior to using commands like B<mig-add>
23 B<mig-add> [--no-headers|--headers|--headers-file <hfile>] <file> [file|--no-headers|--headers|--headers-file <hfile>] [...]
27 ###############################################################################
32 HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
33 MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
39 my $mig_bin = "$FindBin::Bin/";
40 use lib "$FindBin::Bin/";
43 pod2usage(-verbose => 2) if ! $ARGV[0] || $ARGV[0] eq '--help';
45 Mig::die_if_no_env_migschema();
46 Mig::die_if_mig_tracking_table_does_not_exist();
50 my $next_arg_is_headers_file = 0;
52 foreach my $arg (@ARGV) {
53 if ($next_arg_is_headers_file) {
54 $next_arg_is_headers_file = 0;
55 $headers_file = abs_path($arg);
58 if ($arg eq '--headers') {
62 if ($arg eq '--no-headers') {
66 if ($arg eq '--headers-file') {
67 $next_arg_is_headers_file = 1;
71 my $file = abs_path($arg);
72 if ($file =~ /^$MIGBASEWORKDIR/) {
75 add_this_file($file,$has_headers,$headers_file);
76 $headers_file = ''; # clear after applying to just one file
78 print "Not a real file: $file\n";
81 print "Could not find file: $file\n";
84 print "File falls outside of MIGWORKDIR ($MIGWORKDIR): $file\n";
90 ###############################################################################
95 my $headers_file = shift;
97 if (! (-e $headers_file && -f $headers_file)) {
98 print "Could not find headers file $headers_file, skipping $file\n";
102 if (Mig::check_for_tracked_file($file)) {
103 print "File already tracked: $file\n";
107 print "with headers file = $headers_file";
109 print ($headers ? ' with headers' : 'without headers');
111 print '): ' . "$file\n";
112 my $dbh = Mig::db_connect();
114 INSERT INTO $MIGSCHEMA.tracked_file (
119 " . $dbh->quote($file) . "
120 ," . $dbh->quote($headers) . "
121 ," . $dbh->quote($headers_file) . "
123 ") || die "Error inserting into table $MIGSCHEMA.tracked_file: $!\n";
124 Mig::db_disconnect($dbh);