Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a7820e64

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID a7820e648c271e85f408353c1be009ad16a5b70c
  • Vorgänger e0cb5a6c
  • Nachfolger f3323945

Script wird nicht mehr benötigt, da für den neuen Upgrademechanismus keine Versionsnummern mehr verwendet werden.

Unterschiede anzeigen:

scripts/pgupadd.pl
1
#!/usr/bin/perl -l
2
#
3
$db = "Pg";
4
$version = "0.2b";
5

  
6
($name,$exec) = @ARGV;
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)));
9
closedir SQLDIR;
10
$up = $ups[-1];
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;
16

  
17
$name =~ /\.([^\.]+)$/;
18
$ext = $1;
19

  
20
print qq|
21
$db-upgrade Adder v$version
22

  
23
USE: pgupadd [file] [!]
24

  
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).
28

  
29
Current highest upgrade:   $up
30
Proposed next version:     $next
31
Proposed name for upgrade: $db-upgrade-$to-$next.$ext |;
32

  
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:
35

  
36
$cmd
37
| if $name;
38

  
39
if ($name && !-f $name) {
40
  print qq|Warning! Given file does not exist!|;
41
  exit;
42
}
43

  
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!|;
47
  exit;
48
}
49

  
50
exec($cmd) if ($exec eq "!" and $name);
51

  
52

  
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);
58

  
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);
65

  
66
  $res_a = calc_version($my_a_from);
67
  $res_b = calc_version($my_b_from);
68

  
69
  if ($res_a == $res_b) {
70
    $res_a = calc_version($my_a_to);
71
    $res_b = calc_version($my_b_to);
72
  }
73

  
74
  return $res_a <=> $res_b;
75
}
76
sub calc_version {
77
  my $r = !(my @v = split(/\./, shift));
78
  map { $r = $r * 1000 + $v[$_] } 0..4;
79
  $r;
80
}

Auch abrufbar als: Unified diff