7 opendir SQLDIR, "sql/$db-upgrade" or die "Can't open sql dir";
 
   8 @ups = sort(cmp_script_version grep(/$db-upgrade-.*?\.(sql|pl)$/, readdir(SQLDIR)));
 
  11 $up =~ s/(.*de-)|(.sql$)|(.pl$)//g;
 
  12 ($from, $to) = split /-/, $up;
 
  13 @next = split(/\./, $to);
 
  14 $newsub = (pop @next)+1;
 
  15 $next = join (".",@next).".".$newsub;
 
  17 $name =~ /\.([^\.]+)$/;
 
  21 $db-upgrade Adder v$version
 
  23 USE: pgupadd [file] [!]
 
  25 Computes the next minor database version.
 
  26 If [file] is given, proposes a copy command to add this file to the upgrade dir.
 
  27 Use pgupadd [file] ! to let the adder copy and add it to svn for you (check the command first).
 
  29 Current highest upgrade:   $up
 
  30 Proposed next version:     $next
 
  31 Proposed name for upgrade: $db-upgrade-$to-$next.$ext |;
 
  33 $cmd = "cp $name sql/$db-upgrade/$db-upgrade-$to-$next.$ext; svn add sql/$db-upgrade/$db-upgrade-$to-$next.$ext;";
 
  34 print qq|Proposed copy/add command:
 
  39 if ($name && !-f $name) {
 
  40   print qq|Warning! Given file does not exist!|;
 
  44 if ($name && -f "sql/$db-upgrade/$db-upgrade-$up.$ext" &&
 
  45     !`cmp $name sql/$db-upgrade/$db-upgrade-$up.$ext`) {
 
  46   print qq|Warning! Given file is identical to latest $db-upgrade!|;
 
  50 exec($cmd) if ($exec eq "!" and $name);
 
  53 # both functions stolen and slightly modified from SL/User.pm
 
  54 sub cmp_script_version {
 
  55   my ($a_from, $a_to, $b_from, $b_to);
 
  56   my ($i, $res_a, $res_b);
 
  57   my ($my_a, $my_b) = ($a, $b);
 
  59   $my_a =~ s/.*-upgrade-//;
 
  60   $my_a =~ s/.(sql|pl)$//;
 
  61   $my_b =~ s/.*-upgrade-//;
 
  62   $my_b =~ s/.(sql|pl)$//;
 
  63   ($my_a_from, $my_a_to) = split(/-/, $my_a);
 
  64   ($my_b_from, $my_b_to) = split(/-/, $my_b);
 
  66   $res_a = calc_version($my_a_from);
 
  67   $res_b = calc_version($my_b_from);
 
  69   if ($res_a == $res_b) {
 
  70     $res_a = calc_version($my_a_to);
 
  71     $res_b = calc_version($my_b_to);
 
  74   return $res_a <=> $res_b;
 
  77   my $r = !(my @v = split(/\./, shift));
 
  78   map { $r = $r * 1000 + $v[$_] } 0..4;