summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Reports/updatefix.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/Server/Reports/updatefix.py')
-rw-r--r--src/lib/Bcfg2/Server/Reports/updatefix.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/Bcfg2/Server/Reports/updatefix.py b/src/lib/Bcfg2/Server/Reports/updatefix.py
index b5e41b8f9..192b94b61 100644
--- a/src/lib/Bcfg2/Server/Reports/updatefix.py
+++ b/src/lib/Bcfg2/Server/Reports/updatefix.py
@@ -63,10 +63,20 @@ def _interactions_constraint_or_idx():
def _remove_table_column(tbl, col):
"""sqlite doesn't support deleting a column via alter table"""
cursor = connection.cursor()
- try:
+ db_engine = Bcfg2.Server.Reports.settings.DATABASES['default']['ENGINE']
+ if db_engine == 'django.db.backends.mysql':
+ db_name = Bcfg2.Server.Reports.settings.DATABASES['default']['NAME']
+ column_exists = cursor.execute('select * from information_schema.columns '
+ 'where table_schema="%s" and '
+ 'table_name="%s" '
+ 'and column_name="%s";' % (db_name, tbl, col))
+ if not column_exists:
+ # column doesn't exist
+ return
+ # if column exists from previous database, remove it
cursor.execute('alter table %s '
'drop column %s;' % (tbl, col))
- except DatabaseError:
+ elif db_engine == 'django.db.backends.sqlite3':
# check if table exists
try:
cursor.execute('select * from sqlite_master where name=%s and type="table";' % tbl)