summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-05-23 10:14:48 -0500
committerTim Laszlo <tim.laszlo@gmail.com>2012-05-23 10:14:48 -0500
commit2d96ac9d2c6ebd07108d3b85745678598cf2e5ca (patch)
tree5c9d132bdf009f92af205a1e5b7225b6d2648cd3 /src
parent5fcba365e0f5a67f6a3e77fc49bf2924de9d5896 (diff)
downloadbcfg2-2d96ac9d2c6ebd07108d3b85745678598cf2e5ca.tar.gz
bcfg2-2d96ac9d2c6ebd07108d3b85745678598cf2e5ca.tar.bz2
bcfg2-2d96ac9d2c6ebd07108d3b85745678598cf2e5ca.zip
DBStats: Use more sensible column definitions for Reason
Diffstat (limited to 'src')
-rw-r--r--src/lib/Bcfg2/Server/Reports/reports/models.py28
-rw-r--r--src/lib/Bcfg2/Server/Reports/updatefix.py44
2 files changed, 56 insertions, 16 deletions
diff --git a/src/lib/Bcfg2/Server/Reports/reports/models.py b/src/lib/Bcfg2/Server/Reports/reports/models.py
index 9a71fb16a..84bdc5291 100644
--- a/src/lib/Bcfg2/Server/Reports/reports/models.py
+++ b/src/lib/Bcfg2/Server/Reports/reports/models.py
@@ -270,23 +270,23 @@ class Interaction(models.Model):
class Reason(models.Model):
"""reason why modified or bad entry did not verify, or changed."""
- owner = models.TextField(max_length=128, blank=True)
- current_owner = models.TextField(max_length=128, blank=True)
- group = models.TextField(max_length=128, blank=True)
- current_group = models.TextField(max_length=128, blank=True)
- perms = models.TextField(max_length=4, blank=True) # txt fixes typing issue
- current_perms = models.TextField(max_length=4, blank=True)
- status = models.TextField(max_length=3, blank=True) # on/off/(None)
- current_status = models.TextField(max_length=1, blank=True) # on/off/(None)
- to = models.TextField(max_length=256, blank=True)
- current_to = models.TextField(max_length=256, blank=True)
- version = models.TextField(max_length=128, blank=True)
- current_version = models.TextField(max_length=128, blank=True)
+ owner = models.CharField(max_length=255, blank=True)
+ current_owner = models.CharField(max_length=255, blank=True)
+ group = models.CharField(max_length=255, blank=True)
+ current_group = models.CharField(max_length=255, blank=True)
+ perms = models.CharField(max_length=4, blank=True)
+ current_perms = models.CharField(max_length=4, blank=True)
+ status = models.CharField(max_length=128, blank=True)
+ current_status = models.CharField(max_length=128, blank=True)
+ to = models.CharField(max_length=1024, blank=True)
+ current_to = models.CharField(max_length=1024, blank=True)
+ version = models.CharField(max_length=1024, blank=True)
+ current_version = models.CharField(max_length=1024, blank=True)
current_exists = models.BooleanField() # False means its missing. Default True
- current_diff = models.TextField(max_length=1280, blank=True)
+ current_diff = models.TextField(max_length=1024*1024, blank=True)
is_binary = models.BooleanField(default=False)
is_sensitive = models.BooleanField(default=False)
- unpruned = models.TextField(max_length=1280, blank=True)
+ unpruned = models.TextField(max_length=4096, blank=True)
def _str_(self):
return "Reason"
diff --git a/src/lib/Bcfg2/Server/Reports/updatefix.py b/src/lib/Bcfg2/Server/Reports/updatefix.py
index 192b94b61..61029c6fd 100644
--- a/src/lib/Bcfg2/Server/Reports/updatefix.py
+++ b/src/lib/Bcfg2/Server/Reports/updatefix.py
@@ -1,12 +1,12 @@
import Bcfg2.Server.Reports.settings
-from django.db import connection, DatabaseError
+from django.db import connection, DatabaseError, backend
import django.core.management
import logging
import sys
import traceback
from Bcfg2.Server.Reports.reports.models import InternalDatabaseVersion, \
- TYPE_BAD, TYPE_MODIFIED, TYPE_EXTRA
+ Reason, TYPE_BAD, TYPE_MODIFIED, TYPE_EXTRA
logger = logging.getLogger('Bcfg2.Server.Reports.UpdateFix')
@@ -60,6 +60,45 @@ def _interactions_constraint_or_idx():
cursor.execute('create unique index reports_interaction_20100601 on reports_interaction (client_id,timestamp)')
+def _rebuild_reports_reason():
+ """Rebuild the reports_reason table with better data types"""
+ cursor = connection.cursor()
+ columns = ['owner', 'current_owner',
+ 'group', 'current_group',
+ 'perms', 'current_perms',
+ 'status', 'current_status',
+ 'to', 'current_to']
+
+ tbl_name = backend.DatabaseOperations().quote_name('reports_reason')
+
+ db_engine = Bcfg2.Server.Reports.settings.DATABASES['default']['ENGINE']
+ if db_engine == 'django.db.backends.mysql':
+ modify_cmd = 'MODIFY '
+ elif db_engine == 'django.db.backends.sqlite3':
+ """ Sqlite is a special case. Altering columns is not supported. """
+ tmp_tbl_name = backend.DatabaseOperations().quote_name('reports_reason_temp')
+ cursor.execute('ALTER TABLE %s RENAME TO %s' % (tbl_name, tmp_tbl_name))
+ django.core.management.call_command("syncdb", interactive=False, verbosity=0)
+ columns = ",".join([backend.DatabaseOperations().quote_name(f.name) \
+ for f in Reason._meta.fields])
+ cursor.execute('insert into %s(%s) select %s from %s;' % (tbl_name,
+ columns,
+ columns,
+ tmp_tbl_name))
+ cursor.execute('DROP TABLE %s;' % tmp_tbl_name)
+ return
+ else:
+ modify_cmd = 'ALTER COLUMN '
+
+ col_strings = []
+ for column in columns:
+ col_strings.append("%s %s %s" % ( \
+ modify_cmd,
+ backend.DatabaseOperations().quote_name(column),
+ Reason._meta.get_field(column).db_type()
+ ))
+ cursor.execute('ALTER TABLE %s %s' % (tbl_name, ", ".join(col_strings)))
+
def _remove_table_column(tbl, col):
"""sqlite doesn't support deleting a column via alter table"""
cursor = connection.cursor()
@@ -188,6 +227,7 @@ _fixes = [_merge_database_table_entries,
'alter table reports_reason add is_sensitive bool NOT NULL default False;',
_remove_table_column('reports_interaction', 'client_version'),
"alter table reports_reason add unpruned varchar(1280) not null default '';",
+ _rebuild_reports_reason,
]
# this will calculate the last possible version of the database