2 ###############################################################################
7 kmig-add - This will add the specified files to the mig tracking table
9 --headers (the default) and --no-headers are repeatable, and indicate whether
10 subsequent files have headers or not
12 --headers-file specifies a text file <hfile> defining the column headers for
13 the next added <file>, which should contain one line per header
15 --headers-file will automatically invoke --no-headers
17 You'll need to invoke B<kmig-init> prior to using commands like B<kmig-add>
21 B<kmig-add> [--no-headers|--headers|--headers-file <hfile>] <file> [file|--no-headers|--headers|--headers-file <hfile>] [...]
25 ###############################################################################
30 HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW
31 MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
37 my $mig_bin = "$FindBin::Bin/";
38 use lib "$FindBin::Bin/";
41 pod2usage(-verbose => 2) if ! $ARGV[0] || $ARGV[0] eq '--help';
43 KMig::die_if_no_env_migschema();
44 KMig::die_if_mig_tracking_table_does_not_exist();
48 my $next_arg_is_headers_file = 0;
50 foreach my $arg (@ARGV) {
51 if ($next_arg_is_headers_file) {
52 $next_arg_is_headers_file = 0;
53 $headers_file = abs_path($arg);
56 if ($arg eq '--headers') {
60 if ($arg eq '--no-headers') {
64 if ($arg eq '--headers-file') {
65 $next_arg_is_headers_file = 1;
69 my $file = abs_path($arg);
70 if ($file =~ /^$MIGBASEWORKDIR/) {
73 add_this_file($file,$has_headers,$headers_file);
74 $headers_file = ''; # clear after applying to just one file
76 print "Not a real file: $file\n";
79 print "Could not find file: $file\n";
82 print "File falls outside of MIGWORKDIR ($MIGWORKDIR): $file\n";
88 ###############################################################################
93 my $headers_file = shift;
95 if (! (-e $headers_file && -f $headers_file)) {
96 print "Could not find headers file $headers_file, skipping $file\n";
100 if (KMig::check_for_tracked_file($file)) {
101 print "File already tracked: $file\n";
105 print "with headers file = $headers_file";
107 print ($headers ? ' with headers' : 'without headers');
109 print '): ' . "$file\n";
110 my $dbh = KMig::db_connect();
112 INSERT INTO m_tracked_file (
117 " . $dbh->quote($file) . "
118 ," . $dbh->quote($headers) . "
119 ," . $dbh->quote($headers_file) . "
121 ") || die "Error inserting into table m_tracked_file: $!\n";
122 KMig::db_disconnect($dbh);