From d711dd20ca577779493e2c7ee3cd4a592adf4b90 Mon Sep 17 00:00:00 2001 From: Tim Laszlo Date: Mon, 4 Jun 2012 16:09:00 -0500 Subject: DBStats: drop database table for ping --- .../Bcfg2/Server/Reports/Updater/Changes/1_3_0.py | 3 ++- src/lib/Bcfg2/Server/Reports/Updater/Routines.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/lib/Bcfg2/Server/Reports/Updater/Changes/1_3_0.py b/src/lib/Bcfg2/Server/Reports/Updater/Changes/1_3_0.py index b09b06302..1a2fff1ea 100644 --- a/src/lib/Bcfg2/Server/Reports/Updater/Changes/1_3_0.py +++ b/src/lib/Bcfg2/Server/Reports/Updater/Changes/1_3_0.py @@ -6,7 +6,7 @@ The updates() method must be defined and it should return an Updater object """ from Bcfg2.Server.Reports.Updater import Updater, UpdaterError from Bcfg2.Server.Reports.Updater.Routines import AddColumns, \ - RemoveColumns, RebuildTable + RemoveColumns, RebuildTable, DropTable from Bcfg2.Server.Reports.reports.models import Reason, Interaction @@ -21,6 +21,7 @@ def updates(): 'perms', 'current_perms', 'status', 'current_status', 'to', 'current_to'])) + fixes.add(DropTable('reports_ping')) return fixes diff --git a/src/lib/Bcfg2/Server/Reports/Updater/Routines.py b/src/lib/Bcfg2/Server/Reports/Updater/Routines.py index 1d41848e4..b500fd0a6 100644 --- a/src/lib/Bcfg2/Server/Reports/Updater/Routines.py +++ b/src/lib/Bcfg2/Server/Reports/Updater/Routines.py @@ -1,4 +1,5 @@ import logging +import traceback from django.db.models.fields import NOT_PROVIDED from django.db import connection, DatabaseError, backend, models from django.core.management.color import no_style @@ -232,6 +233,26 @@ class RemoveColumns(RebuildTable): raise UpdaterRoutineException +class DropTable(UpdaterRoutine): + """ + Drop a table + """ + def __init__(self, table_name): + self.table_name = table_name + + def __str__(self): + return "Drop table %s" % self.table_name + + def run(self): + try: + cursor = connection.cursor() + cursor.execute('DROP TABLE %s' % _quote(self.table_name)) + except DatabaseError: + logger.error("Failed to drop table: %s" % + traceback.format_exc().splitlines()[-1]) + raise UpdaterRoutineException + + class UpdaterCallable(UpdaterRoutine): """Helper for routines. Basically delays execution""" def __init__(self, fn): -- cgit v1.2.3-1-g7c22