summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-11 18:14:32 -0700
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-11 18:14:32 -0700
commitddbd8c0c9bc6674eeb0d435b04b5f0463701b6c1 (patch)
treed0045d3c648a2bdf505120287733cecf65f4e303
parent45bf9b80bf6e73017e27d6f0a71d81413854a743 (diff)
parent2f8e4244747948e6bf2fe967d326dfa2d6f6366c (diff)
downloadaskbot-ddbd8c0c9bc6674eeb0d435b04b5f0463701b6c1.tar.gz
askbot-ddbd8c0c9bc6674eeb0d435b04b5f0463701b6c1.tar.bz2
askbot-ddbd8c0c9bc6674eeb0d435b04b5f0463701b6c1.zip
Merge pull request #106 from emonty/master
Fix things for MySQL InnoDB users
-rw-r--r--askbot/migrations/0013_add_response_count__to_user.py17
-rw-r--r--askbot/migrations/0014_rename_schema_from_forum_to_askbot.py21
-rw-r--r--askbot/migrations/0018_add___status__field_to_user_model.py16
-rw-r--r--askbot/migrations/0026_add_seen_and_new_response_counts_to_user.py8
-rw-r--r--askbot/migrations/0033_add__consecutive_days_visit_count__to__auth_user.py16
-rw-r--r--askbot/migrations/0035_add_country_fields_to_user.py8
-rw-r--r--askbot/migrations/0037_add_marked_tags_to_user_profile.py12
-rw-r--r--askbot/migrations/0038_add_tag_filter_strategies.py32
-rw-r--r--askbot/migrations/0043_add_temporal_extra_column_for_datamigration.py6
-rw-r--r--askbot/migrations/0122_auth_user__add_subscribed_tag_field.py8
-rw-r--r--askbot/migrations/0124_auto__add_field_post_is_private__add_field_replyaddress_reply_action.py15
-rw-r--r--askbot/migrations/0125_add_show_tags_field_to_user.py18
-rw-r--r--askbot/migrations/0126_add_field__auth_user__is_fake.py11
-rw-r--r--askbot/migrations/__init__.py5
-rw-r--r--askbot/migrations_api/__init__.py21
15 files changed, 101 insertions, 113 deletions
diff --git a/askbot/migrations/0013_add_response_count__to_user.py b/askbot/migrations/0013_add_response_count__to_user.py
index f3d724e3..68ac0c3c 100644
--- a/askbot/migrations/0013_add_response_count__to_user.py
+++ b/askbot/migrations/0013_add_response_count__to_user.py
@@ -3,6 +3,7 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
@@ -13,16 +14,12 @@ class Migration(SchemaMigration):
a bit hacky but we have to do it as long as we keep patching auth models
within the forum application
"""
- try:
- db.add_column(
- u'auth_user',
- 'response_count',
- self.gf('django.db.models.fields.IntegerField')(default=0, ),
- keep_default=False
- )
- except:
- print 'probably already have column User.response_count'
- pass
+ safe_add_column(
+ u'auth_user',
+ 'response_count',
+ self.gf('django.db.models.fields.IntegerField')(default=0, ),
+ keep_default=False
+ )
def backwards(self, orm):
diff --git a/askbot/migrations/0014_rename_schema_from_forum_to_askbot.py b/askbot/migrations/0014_rename_schema_from_forum_to_askbot.py
index f5f913da..f9a5b739 100644
--- a/askbot/migrations/0014_rename_schema_from_forum_to_askbot.py
+++ b/askbot/migrations/0014_rename_schema_from_forum_to_askbot.py
@@ -10,19 +10,20 @@ app_dir_name = os.path.basename(os.path.dirname(os.path.dirname(__file__)))
class Migration(SchemaMigration):
def forwards(self, orm):
- try:
- db.rename_table('forum_anonymousanswer', 'askbot_anonymousanswer')
- db.rename_table('forum_anonymousquestion', 'askbot_anonymousquestion')
- db.rename_table('forum_emailfeedsetting', 'askbot_emailfeedsetting')
- db.rename_table('forum_markedtag', 'askbot_markedtag')
- db.rename_table('forum_questionview', 'askbot_questionview')
- db.rename_table('forum_validationhash', 'askbot_validationhash')
- except:
- pass
+ if app_dir_name == 'forum':
+ try:
+ db.rename_table('forum_anonymousanswer', 'askbot_anonymousanswer')
+ db.rename_table('forum_anonymousquestion', 'askbot_anonymousquestion')
+ db.rename_table('forum_emailfeedsetting', 'askbot_emailfeedsetting')
+ db.rename_table('forum_markedtag', 'askbot_markedtag')
+ db.rename_table('forum_questionview', 'askbot_questionview')
+ db.rename_table('forum_validationhash', 'askbot_validationhash')
+ except:
+ pass
def backwards(self, orm):
- if app_dirname == 'forum':
+ if app_dir_name == 'forum':
db.rename_table('askbot_anonymousanswer', 'forum_anonymousanswer')
db.rename_table('askbot_anonymousquestion', 'forum_anonymousquestion')
db.rename_table('askbot_emailfeedsetting', 'forum_emailfeedsetting')
diff --git a/askbot/migrations/0018_add___status__field_to_user_model.py b/askbot/migrations/0018_add___status__field_to_user_model.py
index 5a713866..b30f30d7 100644
--- a/askbot/migrations/0018_add___status__field_to_user_model.py
+++ b/askbot/migrations/0018_add___status__field_to_user_model.py
@@ -3,21 +3,19 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'User.status'
- try:
- db.add_column(
- u'auth_user',
- 'status',
- self.gf('django.db.models.fields.CharField')(default ='w', max_length = 2),
- keep_default=False
- )
- except:
- pass
+ safe_add_column(
+ u'auth_user',
+ 'status',
+ self.gf('django.db.models.fields.CharField')(default ='w', max_length = 2),
+ keep_default=False
+ )
def backwards(self, orm):
diff --git a/askbot/migrations/0026_add_seen_and_new_response_counts_to_user.py b/askbot/migrations/0026_add_seen_and_new_response_counts_to_user.py
index 4cd05f83..8b6002bf 100644
--- a/askbot/migrations/0026_add_seen_and_new_response_counts_to_user.py
+++ b/askbot/migrations/0026_add_seen_and_new_response_counts_to_user.py
@@ -3,16 +3,14 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding fields
- try:
- db.add_column('auth_user', 'new_response_count', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
- db.add_column('auth_user', 'seen_response_count', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
- except:
- pass
+ safe_add_column('auth_user', 'new_response_count', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
+ safe_add_column('auth_user', 'seen_response_count', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
def backwards(self, orm):
# Deleting fields
diff --git a/askbot/migrations/0033_add__consecutive_days_visit_count__to__auth_user.py b/askbot/migrations/0033_add__consecutive_days_visit_count__to__auth_user.py
index 580c2f25..e5a10faf 100644
--- a/askbot/migrations/0033_add__consecutive_days_visit_count__to__auth_user.py
+++ b/askbot/migrations/0033_add__consecutive_days_visit_count__to__auth_user.py
@@ -3,21 +3,19 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'User.consecutive_days_visit_count'
- try:
- db.add_column(
- u'auth_user',
- 'consecutive_days_visit_count',
- self.gf('django.db.models.fields.IntegerField')(default = 0, max_length = 2),
- keep_default=False
- )
- except:
- pass
+ safe_add_column(
+ u'auth_user',
+ 'consecutive_days_visit_count',
+ self.gf('django.db.models.fields.IntegerField')(default = 0, max_length = 2),
+ keep_default=False
+ )
def backwards(self, orm):
diff --git a/askbot/migrations/0035_add_country_fields_to_user.py b/askbot/migrations/0035_add_country_fields_to_user.py
index 02dd404c..340883ba 100644
--- a/askbot/migrations/0035_add_country_fields_to_user.py
+++ b/askbot/migrations/0035_add_country_fields_to_user.py
@@ -3,17 +3,15 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model country fields to the model auth_user
- try:
- db.add_column(u'auth_user', 'country', self.gf('django_countries.fields.CountryField')(max_length=2, blank=True, null=True))
- db.add_column(u'auth_user', 'show_country', self.gf('django.db.models.fields.BooleanField')(default=False, blank=True))
- except:
- pass
+ safe_add_column(u'auth_user', 'country', self.gf('django_countries.fields.CountryField')(max_length=2, blank=True, null=True))
+ safe_add_column(u'auth_user', 'show_country', self.gf('django.db.models.fields.BooleanField')(default=False, blank=True))
def backwards(self, orm):
diff --git a/askbot/migrations/0037_add_marked_tags_to_user_profile.py b/askbot/migrations/0037_add_marked_tags_to_user_profile.py
index f10f53be..306e16e6 100644
--- a/askbot/migrations/0037_add_marked_tags_to_user_profile.py
+++ b/askbot/migrations/0037_add_marked_tags_to_user_profile.py
@@ -3,18 +3,16 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
- try:
- # Adding field 'User.interesting_tags'
- db.add_column(u'auth_user', 'interesting_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
- # Adding field 'User.ignored_tags'
- db.add_column(u'auth_user', 'ignored_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
- except:
- pass
+ # Adding field 'User.interesting_tags'
+ safe_add_column(u'auth_user', 'interesting_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
+ # Adding field 'User.ignored_tags'
+ safe_add_column(u'auth_user', 'ignored_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
def backwards(self, orm):
diff --git a/askbot/migrations/0038_add_tag_filter_strategies.py b/askbot/migrations/0038_add_tag_filter_strategies.py
index c2596366..a24d12bf 100644
--- a/askbot/migrations/0038_add_tag_filter_strategies.py
+++ b/askbot/migrations/0038_add_tag_filter_strategies.py
@@ -4,29 +4,27 @@ from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from askbot import const
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model country fields to the model auth_user
- try:
- db.add_column(
- u'auth_user',
- 'email_tag_filter_strategy',
- self.gf(
- 'django.db.models.fields.SmallIntegerField'
- )(default = const.EXCLUDE_IGNORED)
- )
- db.add_column(
- u'auth_user',
- 'display_tag_filter_strategy',
- self.gf(
- 'django.db.models.fields.SmallIntegerField'
- )(default = const.INCLUDE_ALL)
- )
- except:
- pass
+ safe_add_column(
+ u'auth_user',
+ 'email_tag_filter_strategy',
+ self.gf(
+ 'django.db.models.fields.SmallIntegerField'
+ )(default = const.EXCLUDE_IGNORED)
+ )
+ safe_add_column(
+ u'auth_user',
+ 'display_tag_filter_strategy',
+ self.gf(
+ 'django.db.models.fields.SmallIntegerField'
+ )(default = const.INCLUDE_ALL)
+ )
def backwards(self, orm):
diff --git a/askbot/migrations/0043_add_temporal_extra_column_for_datamigration.py b/askbot/migrations/0043_add_temporal_extra_column_for_datamigration.py
index 4a8140a4..7582dc04 100644
--- a/askbot/migrations/0043_add_temporal_extra_column_for_datamigration.py
+++ b/askbot/migrations/0043_add_temporal_extra_column_for_datamigration.py
@@ -3,14 +3,12 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
- try:
- db.add_column(u'auth_user', 'avatar_type', self.gf('django.db.models.fields.CharField')(max_length=1, default='n'), keep_default=False)
- except:
- pass
+ safe_add_column(u'auth_user', 'avatar_type', self.gf('django.db.models.fields.CharField')(max_length=1, default='n'), keep_default=False)
def backwards(self, orm):
db.delete_column(u'auth_user', 'avatar_type')
diff --git a/askbot/migrations/0122_auth_user__add_subscribed_tag_field.py b/askbot/migrations/0122_auth_user__add_subscribed_tag_field.py
index d84666fb..7f7ff971 100644
--- a/askbot/migrations/0122_auth_user__add_subscribed_tag_field.py
+++ b/askbot/migrations/0122_auth_user__add_subscribed_tag_field.py
@@ -3,15 +3,13 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
- try:
- # Adding field 'User.interesting_tags'
- db.add_column(u'auth_user', 'subscribed_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
- except:
- pass
+ # Adding field 'User.interesting_tags'
+ safe_add_column(u'auth_user', 'subscribed_tags', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
def backwards(self, orm):
# Deleting field 'User.interesting_tags'
diff --git a/askbot/migrations/0124_auto__add_field_post_is_private__add_field_replyaddress_reply_action.py b/askbot/migrations/0124_auto__add_field_post_is_private__add_field_replyaddress_reply_action.py
index b5a1e0c9..11b891da 100644
--- a/askbot/migrations/0124_auto__add_field_post_is_private__add_field_replyaddress_reply_action.py
+++ b/askbot/migrations/0124_auto__add_field_post_is_private__add_field_replyaddress_reply_action.py
@@ -3,6 +3,7 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
@@ -10,14 +11,14 @@ class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Post.is_private'
db.start_transaction()
- db.add_column('askbot_post', 'is_private',
- self.gf('django.db.models.fields.BooleanField')(default=False),
- keep_default=False)
+ safe_add_column('askbot_post', 'is_private',
+ self.gf('django.db.models.fields.BooleanField')(default=False),
+ keep_default=False)
# Adding field 'ReplyAddress.reply_action'
- db.add_column('askbot_replyaddress', 'reply_action',
- self.gf('django.db.models.fields.CharField')(default='auto_answer_or_comment', max_length=32),
- keep_default=False)
+ safe_add_column('askbot_replyaddress', 'reply_action',
+ self.gf('django.db.models.fields.CharField')(default='auto_answer_or_comment', max_length=32),
+ keep_default=False)
# Changing field 'ReplyAddress.post'
db.alter_column('askbot_replyaddress', 'post_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['askbot.Post']))
@@ -26,7 +27,7 @@ class Migration(SchemaMigration):
try:
db.start_transaction()
# Adding field 'User.interesting_tags'
- db.add_column(u'auth_user', 'email_signature', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
+ safe_add_column(u'auth_user', 'email_signature', self.gf('django.db.models.fields.TextField')(blank=True, default = ''), keep_default=False)
db.commit_transaction()
except:
db.rollback_transaction()
diff --git a/askbot/migrations/0125_add_show_tags_field_to_user.py b/askbot/migrations/0125_add_show_tags_field_to_user.py
index cb7ab2bd..fc299d18 100644
--- a/askbot/migrations/0125_add_show_tags_field_to_user.py
+++ b/askbot/migrations/0125_add_show_tags_field_to_user.py
@@ -3,6 +3,7 @@ import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
@@ -10,16 +11,13 @@ class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model show_marked_tags fields to the model auth_user
- try:
- db.add_column(
- u'auth_user',
- 'show_marked_tags',
- self.gf(
- 'django.db.models.fields.BooleanField'
- )(default=True, blank=True)
- )
- except:
- pass
+ safe_add_column(
+ u'auth_user',
+ 'show_marked_tags',
+ self.gf(
+ 'django.db.models.fields.BooleanField'
+ )(default=True, blank=True)
+ )
def backwards(self, orm):
diff --git a/askbot/migrations/0126_add_field__auth_user__is_fake.py b/askbot/migrations/0126_add_field__auth_user__is_fake.py
index e0928ed7..783d1e27 100644
--- a/askbot/migrations/0126_add_field__auth_user__is_fake.py
+++ b/askbot/migrations/0126_add_field__auth_user__is_fake.py
@@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-
from south.db import db
from south.v2 import SchemaMigration
+from askbot.migrations_api import safe_add_column
class Migration(SchemaMigration):
def forwards(self, orm):
- try:
- # Adding field 'User.is_fake'
- db.add_column(
- u'auth_user', 'is_fake',
- self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
- except:
- pass
+ safe_add_column(
+ u'auth_user', 'is_fake',
+ self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
def backwards(self, orm):
db.delete_column('auth_user', 'is_fake')
diff --git a/askbot/migrations/__init__.py b/askbot/migrations/__init__.py
index 86377b7b..b9683daf 100644
--- a/askbot/migrations/__init__.py
+++ b/askbot/migrations/__init__.py
@@ -1,5 +1,9 @@
from south.db import db
from south.utils import ask_for_it_by_name
+from south.v2 import SchemaMigration
+
+if not db.has_ddl_transactions:
+ SchemaMigration.no_dry_run = True
# Terminal ANSI codes for printing colored text:
# - http://code.google.com/p/testoob/source/browse/trunk/src/testoob/reporting/colored.py#20
@@ -67,3 +71,4 @@ def innodb_ready_rename_column(orm, models, table, old_column_name, new_column_n
# INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
# db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
db.alter_column(table, new_column_name, field)
+ db.clear_deferred_sql()
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):