diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2012-05-11 09:22:45 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2012-05-11 09:22:45 -0500 |
commit | 94aa5f3d0c043547f9bac6f0046b64898cf277e7 (patch) | |
tree | 6e558b52dd20481973ca678bb33f94ceb69111c6 | |
parent | 356cc0b44ab1aecaca74ff3779360b08038b77e8 (diff) | |
download | bcfg2-94aa5f3d0c043547f9bac6f0046b64898cf277e7.tar.gz bcfg2-94aa5f3d0c043547f9bac6f0046b64898cf277e7.tar.bz2 bcfg2-94aa5f3d0c043547f9bac6f0046b64898cf277e7.zip |
reports: Fix traceback reported by Rodney Young
Previously left out a check for whether the column exists when using
MySQL. We will probably eventually need checks for other db types as well.
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
-rw-r--r-- | src/lib/Bcfg2/Server/Reports/updatefix.py | 14 |
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) |