]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG/DBTools.pm: remove unused code
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 24 Apr 2017 06:41:26 +0000 (08:41 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 24 Apr 2017 06:41:26 +0000 (08:41 +0200)
We do not support upgrading from very old versions ...

PMG/DBTools.pm

index 7c179d3d6bf44f792a19a23f10d798fb3cb5661f..612a0a7dccd0f9775a9ae816fc3d59d02d30443a 100644 (file)
@@ -428,242 +428,6 @@ sub cond_create_std_actions {
 }
 
 
-sub upgrade_mailstore_db {
-    my ($dbh) = @_;
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT tablename FROM pg_tables WHERE tablename = lower ('MailStore')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if ($ref) { # table exists
-
-           $cmd = "INSERT INTO CMailStore " .
-               "(CID, RID, ID, Time, QType, Bytes, Spamlevel, Info, Header, Sender, File) " .
-               "SELECT 0, ID, ID, Time, QType, Bytes, Spamlevel, Info, Header, Sender, File FROM MailStore";
-
-           $dbh->do($cmd);
-
-           $cmd = "INSERT INTO CMSReceivers " .
-               "(CMailStore_CID, CMailStore_RID, PMail, Receiver, TicketID, Status, MTime) " .
-               "SELECT 0, MailStore_ID, PMail, Receiver, TicketID, Status, 0 FROM MSReceivers";
-
-           $dbh->do($cmd);
-
-           $dbh->do("SELECT setval ('cmailstore_id_seq', nextval ('mailstore_id_seq'))");
-
-           $dbh->do("DROP TABLE MailStore");
-           $dbh->do("DROP TABLE MSReceivers");
-       }
-
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $err;
-    }
-}
-
-sub upgrade_dailystat_db {
-    my ($dbh) = @_;
-
-    eval { # make sure we have MTime
-       $dbh->do("ALTER TABLE DailyStat ADD COLUMN MTime INTEGER;" .
-                "UPDATE DailyStat SET MTime = EXTRACT (EPOCH FROM now());");
-    };
-
-    eval { # make sure we have correct constraints for MTime
-       $dbh->do ("ALTER TABLE DailyStat ALTER COLUMN MTime SET NOT NULL;");
-    };
-
-    eval { # make sure we have RBLCount
-       $dbh->do ("ALTER TABLE DailyStat ADD COLUMN RBLCount INTEGER;" .
-                 "UPDATE DailyStat SET RBLCount = 0;");
-    };
-
-    eval { # make sure we have correct constraints for RBLCount
-       $dbh->do ("ALTER TABLE DailyStat ALTER COLUMN RBLCount SET DEFAULT 0;" .
-                 "ALTER TABLE DailyStat ALTER COLUMN RBLCount SET NOT NULL;");
-    };
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT indexname FROM pg_indexes WHERE indexname = lower ('DailyStat_MTime_Index')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if (!$ref) { # index does not exist
-           $dbh->do ("CREATE INDEX DailyStat_MTime_Index ON DailyStat (MTime)");
-       }
-
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $err;
-    }
-}
-
-sub upgrade_domainstat_db {
-    my ($dbh) = @_;
-
-    eval { # make sure we have MTime
-       $dbh->do("ALTER TABLE DomainStat ADD COLUMN MTime INTEGER;" .
-                "UPDATE DomainStat SET MTime = EXTRACT (EPOCH FROM now());" .
-                "ALTER TABLE DomainStat ALTER COLUMN MTime SET NOT NULL;");
-    };
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT indexname FROM pg_indexes WHERE indexname = lower ('DomainStat_MTime_Index')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if (!$ref) { # index does not exist
-           $dbh->do ("CREATE INDEX DomainStat_MTime_Index ON DomainStat (MTime)");
-       }
-
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $@;
-    }
-}
-
-sub upgrade_statistic_db {
-    my ($dbh) = @_;
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT tablename FROM pg_tables WHERE tablename = lower ('Statistic')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if ($ref) { # old table exists
-
-           my $timezone = tz_local_offset();;
-
-           $dbh->do("INSERT INTO VirusInfo (Time, Name, Count, MTime) " .
-                    "SELECT ((time + $timezone) / 86400) * 86400 as day, virusinfo, " .
-                    "count (virusinfo), max (Time) FROM Statistic " .
-                    "WHERE virusinfo IS NOT NULL GROUP BY day, virusinfo");
-
-           my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime (time());
-           my $end = timelocal(0, 0, 0, $mday, $mon, $year);
-           my $start = $end - 3600*24*7; # / days
-
-           $cmd = "INSERT INTO CStatistic " .
-               "(CID, RID, ID, Time, Bytes, Direction, Spamlevel, VirusInfo, PTime, Sender) " .
-               "SELECT 0, ID, ID, Time, Bytes, Direction, Spamlevel, VirusInfo, PTime, Sender FROM Statistic " .
-               "WHERE time >= $start";
-
-           $dbh->do($cmd);
-
-           $dbh->do("SELECT setval ('cstatistic_id_seq', nextval ('statistic_id_seq'))");
-
-           $dbh->do("INSERT INTO StatInfo (name, ivalue) VALUES ('virusinfo_index', " .
-                    "nextval ('statistic_id_seq'))");
-
-           $cmd = "INSERT INTO CReceivers (CStatistic_CID, CStatistic_RID, Receiver, Blocked) " .
-               "SELECT 0, Mail_ID, Receiver, Blocked FROM Receivers " .
-               "WHERE EXISTS (SELECT * FROM CStatistic WHERE CID = 0 AND RID = Mail_ID)";
-
-           $dbh->do($cmd);
-
-           $dbh->do("DROP TABLE Statistic");
-           $dbh->do("DROP TABLE Receivers");
-       }
-
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $err;
-    }
-}
-
-sub upgrade_greylist_db {
-    my ($dbh) = @_;
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT tablename FROM pg_tables WHERE tablename = lower ('Greylist')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if ($ref) { # table exists
-
-           $cmd = "INSERT INTO CGreylist " .
-               "(IPNet, Host, Sender, Receiver, Instance, RCTime, ExTime, Delay, Blocked, Passed, MTime, CID) " .
-               "SELECT IPNet, Host, Sender, Receiver, Instance, RCTime, ExTime, Delay, Blocked, Passed, RCTime, 0 FROM Greylist";
-
-           $dbh->do($cmd);
-
-           $dbh->do("DROP TABLE Greylist");
-       }
-
-       $dbh->commit;
-    };
-    if (my $err = $@) {
-       $dbh->rollback;
-       die $err;
-    }
-}
-
-sub upgrade_userprefs_db {
-    my ($dbh) = @_;
-
-    eval {
-       $dbh->do("ALTER TABLE UserPrefs ADD COLUMN MTime INTEGER;" .
-                "UPDATE UserPrefs SET MTime = EXTRACT (EPOCH FROM now());" .
-                "ALTER TABLE UserPrefs ALTER COLUMN MTime SET NOT NULL;");
-    };
-
-
-    eval {
-       $dbh->begin_work;
-
-       my $cmd = "SELECT indexname FROM pg_indexes WHERE indexname = lower ('UserPrefs_MTime_Index')";
-
-       my $sth = $dbh->prepare($cmd);
-       $sth->execute();
-       my $ref = $sth->fetchrow_hashref();
-       $sth->finish();
-
-       if (!$ref) { # index does not exist
-           $dbh->do("CREATE INDEX UserPrefs_MTime_Index ON UserPrefs (MTime)");
-       }
-
-       $dbh->commit;
-    };
-    if ($@) {
-       $dbh->rollback;
-       die $@;
-    }
-}
-
 sub upgradedb {
     my ($ruledb) = @_;
 
@@ -691,17 +455,7 @@ sub upgradedb {
 
     cond_create_std_actions($ruledb);
 
-    upgrade_mailstore_db($dbh);
-
-    upgrade_statistic_db($dbh);
-
-    upgrade_userprefs_db($dbh);
-
-    upgrade_greylist_db($dbh);
-
-    upgrade_dailystat_db($dbh);
-
-    upgrade_domainstat_db($dbh);
+    # upgrade tables here if necessary
 
     # update obsolete content type names
     eval {