diff options
author | Monty Taylor <mordred@inaugust.com> | 2012-12-24 21:39:53 +0000 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2012-12-24 21:39:53 +0000 |
commit | cab49ee6f0a896fe51d15a0af0978b340a3b03a8 (patch) | |
tree | 2cc84e88e1d4837df1075f4fcd20e839a5428898 | |
parent | 908fb13a4a30d2db8a2729d900f12dc9a86ced91 (diff) | |
download | askbot-cab49ee6f0a896fe51d15a0af0978b340a3b03a8.tar.gz askbot-cab49ee6f0a896fe51d15a0af0978b340a3b03a8.tar.bz2 askbot-cab49ee6f0a896fe51d15a0af0978b340a3b03a8.zip |
Add MySQL support for safe_add_column.
-rw-r--r-- | askbot/migrations_api/__init__.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/askbot/migrations_api/__init__.py b/askbot/migrations_api/__init__.py index 0260f51b..3ea250f2 100644 --- a/askbot/migrations_api/__init__.py +++ b/askbot/migrations_api/__init__.py @@ -13,14 +13,19 @@ def safe_add_column(table, column, column_data, keep_default = False): so, we need to add these columns here in separate transactions and roll back if they fail, if we want we could also record - which columns clash """ - try: - db.start_transaction() - db.add_column(table, column, column_data, keep_default = keep_default) - db.commit_transaction() - return True - except: - db.rollback_transaction() - return False + if db.backend_name=='mysql': + if len(db.execute('select column_name from information_schema.columns where table_name=%s and column_name=%s', params=[table, column])) == 0: + db.add_column(table, column, column_data, keep_default = keep_default) + + else: + try: + db.start_transaction() + db.add_column(table, column, column_data, keep_default = keep_default) + db.commit_transaction() + return True + except: + db.rollback_transaction() + return False def mysql_table_supports_full_text_search(table_name): |