Improvements to make-db-patch.pl
authorThomas Berezansky <tsbere@mvlc.org>
Tue, 17 May 2011 17:50:44 +0000 (13:50 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 17 May 2011 18:58:02 +0000 (14:58 -0400)
Grab all changes to base sql files into the upgrade script
Based on HEAD (uncommitted changes) or --from=refspec

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

Open-ILS/src/sql/Pg/make-db-patch.pl

index ffb1b01..30993b8 100755 (executable)
@@ -22,6 +22,7 @@ use Getopt::Long;
 
 my $db_patch_num;
 my $patch_name;
+my $patch_from;
 my @deprecates;
 my @supersedes;
 
@@ -29,6 +30,7 @@ exit_usage() if $#ARGV == -1;
 GetOptions( 
     'num=i' => \$db_patch_num,
     'name=s' => \$patch_name,
+    'from=s' => \$patch_from,
     'deprecates=i' => \@deprecates,
     'supersedes=i' => \@supersedes,
 ) or exit_usage();
@@ -36,6 +38,8 @@ GetOptions(
 exit_usage('--num required') unless defined $db_patch_num;
 exit_usage('--name required') unless defined $patch_name;
 
+$patch_from = 'HEAD' unless defined $patch_from;
+
 # pad to four digits
 $db_patch_num = sprintf('%-04.4d', $db_patch_num);
 $_ = sprintf('%-04.4d', $_) foreach @deprecates;
@@ -92,12 +96,16 @@ if (@deprecates or @supersedes) {
               ");\n";
 }
 
+my $patch_init_contents;
+$patch_init_contents = `git diff $patch_from -- ./[0-9][0-9][0-9].*.sql | sed -e '/^[^+-]/d' -e '/^\\(--- a\\|+++ b\\)/d' -e 's/^+//'` if ($patch_from ne '');
+
 print OUT <<_FOOTER_;
 
 -- check whether patch can be applied
 SELECT evergreen.update_deps_block_check('$db_patch_num', :eg_version);
 
--- FIXME: add SQL statements to perform the upgrade
+-- FIXME: add/check SQL statements to perform the upgrade
+$patch_init_contents
 
 COMMIT;
 _FOOTER_
@@ -117,6 +125,7 @@ Make template for a DB patch SQL file.
     --name         descriptive part of patch filename 
     --deprecates   patch(es) deprecated by this update
     --supersedes   patch(es) superseded by this update
+    --from         git refspec to compare against
 _HELP_
     exit 0;
 }