install.pl: Change handling of upgrades.

Drop predefined actions in favor of arbitrary statements.
Minor code fixup.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2010-09-19 16:53:07 +02:00
parent 53dcbea63e
commit 59d0c5ef86

View file

@ -140,19 +140,6 @@ Don't forget to restart your INN feed so that it can pick up the new version:
(or whatever you called your feed). (or whatever you called your feed).
UPGRADE UPGRADE
##### --------------------------------------------------------------------------
##### Upgrading
##### --------------------------------------------------------------------------
my (%DBUpgrade,%Instructions);
# 0.01 -> 0.02
$DBUpgrade{'0.02'} = <<DB0point02;
SELECT 1;
DB0point02
$Instructions{'0.02'} = <<IN0point02;
Dummy Instructions.
IN0point02
##### --------------------------- End of definitions --------------------------- ##### --------------------------- End of definitions ---------------------------
### DB init, read list of tables ### DB init, read list of tables
@ -174,26 +161,17 @@ if (!$Options{'u'}) {
} else { } else {
##### upgrade mode ##### upgrade mode
print "----------\nStarting upgrade process.\n"; print "----------\nStarting upgrade process.\n";
$PackageVersion = '0.03';
if ($Options{'u'} < $PackageVersion) { if ($Options{'u'} < $PackageVersion) {
# Database upgrades for each version if ($Options{'u'} < 0.02) {
foreach my $UpVersion (sort keys %DBUpgrade) { # 0.01 -> 0.02
if ($UpVersion > $Options{'u'} and $UpVersion <= $PackageVersion) { # &DoMySQL('...;');
print "v$UpVersion: Executing database upgrade ...\n"; # print "v0.02: Database upgrades ...\n";
&DoMySQL($DBUpgrade{$UpVersion}); # &PrintInstructions('0.02',<<" INSTRUCTIONS");
# INSTRUCTIONS
}; };
}; };
# Display upgrade instructions for each version # Display general upgrade instructions
foreach my $UpVersion (sort keys %Instructions) {
if ($UpVersion > $Options{'u'} and $UpVersion <= $PackageVersion) {
print "v$UpVersion: Upgrade Instructions >>>>>\n";
my $Padding = ' ' x (length($UpVersion) + 3);
$Instructions{$UpVersion} =~ s/^/$Padding/;
print $Instructions{$UpVersion};
print "<" x (length($UpVersion) + 29) . "\n";
};
};
};
# Display upgrade instructions
print $Upgrade; print $Upgrade;
}; };
@ -204,7 +182,7 @@ exit(0);
################################# Subroutines ################################## ################################# Subroutines ##################################
sub CreateTable() { sub CreateTable {
my $Table = shift; my $Table = shift;
if (defined($TablesInDB{$Conf{$Table}})) { if (defined($TablesInDB{$Conf{$Table}})) {
printf("Database table %s.%s already exists, skipping ....\n",$Conf{'DBDatabase'},$Conf{$Table}); printf("Database table %s.%s already exists, skipping ....\n",$Conf{'DBDatabase'},$Conf{$Table});
@ -216,13 +194,22 @@ sub CreateTable() {
return; return;
}; };
sub DoMySQL() { sub DoMySQL {
my $SQL = shift; my $SQL = shift;
my $DBQuery = $DBHandle->prepare($SQL); my $DBQuery = $DBHandle->prepare($SQL);
$DBQuery->execute() or warn sprintf("$MySelf: E: Database error: %s\n",$DBI::errstr); $DBQuery->execute() or warn sprintf("$MySelf: E: Database error: %s\n",$DBI::errstr);
return; return;
}; };
sub PrintInstructions {
my ($UpVersion,$Instructions) = @_;
print "v$UpVersion: Upgrade Instructions >>>>>\n";
my $Padding = ' ' x (length($UpVersion) + 3);
$Instructions =~ s/^ /$Padding/mg;
print $Instructions;
print "<" x (length($UpVersion) + 29) . "\n";
};
__END__ __END__