diff options
21 files changed, 191 insertions, 94 deletions
diff --git a/askbot/migrations/0066_transplant_accepted_answer_data.py b/askbot/migrations/0066_transplant_accepted_answer_data.py index 6d1b7ca0..6f5a81a0 100644 --- a/askbot/migrations/0066_transplant_accepted_answer_data.py +++ b/askbot/migrations/0066_transplant_accepted_answer_data.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.migrations import TERM_YELLOW, TERM_RESET + class Migration(DataMigration): def forwards(self, orm): @@ -12,12 +14,13 @@ class Migration(DataMigration): if question.answer_accepted: try: - accepted_answer = question.answers.get(accepted=True) # If this raises an error, we have a data integrity problem - except orm.Answer.DoesNotExist, orm.Answer.MultipleObjectsReturned: - #raise ValueError("There is a data integrity problem with some question/answers") + accepted_answer = question.answers.get(accepted=True) + except orm.Answer.DoesNotExist: # Unfortunately there's probably nothing we can do in this case, # there's no record of which answer has been accepted (HMM, MAYBE IN ACTIVITIES???) - print "!!! Found a thread with question.answer_accepted, but no answer actually marked as accepted, question.id=%d" % question.id + print TERM_YELLOW, "Found a thread with question.answer_accepted, " \ + "but no answer actually marked as accepted, question.id=%d." \ + "This happens so there's no need to panic." % question.id, TERM_RESET else: thread.accepted_answer = accepted_answer thread.answer_accepted_at = accepted_answer.accepted_at diff --git a/askbot/migrations/0088_install__post_view__for__development.py b/askbot/migrations/0088_install__post_view__for__development.py index 1ae333c7..e948299a 100644 --- a/askbot/migrations/0088_install__post_view__for__development.py +++ b/askbot/migrations/0088_install__post_view__for__development.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import warnings import datetime from south.db import db from south.v2 import SchemaMigration @@ -9,16 +10,16 @@ import askbot class Migration(SchemaMigration): def forwards(self, orm): - create_post_view_sql = open( - askbot.get_path_to('models/post_view.sql') - ).read() - import warnings +# create_post_view_sql = open( +# askbot.get_path_to('models/post_view.sql') +# ).read() warnings.filterwarnings("ignore", "Unknown table .*?\.askbot_post'") # DROP VIEW might raise a warning so let's filter that out db.execute('DROP VIEW IF EXISTS askbot_post') - db.execute(create_post_view_sql) +# db.execute(create_post_view_sql) def backwards(self, orm): - db.execute('DROP VIEW askbot_post') + warnings.filterwarnings("ignore", "Unknown table .*?\.askbot_post'") # DROP VIEW might raise a warning so let's filter that out + db.execute('DROP VIEW IF EXISTS askbot_post') models = { 'askbot.activity': { @@ -146,36 +147,6 @@ class Migration(SchemaMigration): 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_selections'", 'to': "orm['askbot.Tag']"}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tag_selections'", 'to': "orm['auth.User']"}) }, -# 'askbot.post': { -# 'Meta': {'object_name': 'Post', 'managed': 'False'}, -# 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), -# 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['auth.User']"}), -# 'comment_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), -# 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), -# 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), -# 'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_posts'", 'null': 'True', 'to': "orm['auth.User']"}), -# 'html': ('django.db.models.fields.TextField', [], {'null': 'True'}), -# 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), -# 'is_anonymous': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), -# 'last_edited_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), -# 'last_edited_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'last_edited_posts'", 'null': 'True', 'to': "orm['auth.User']"}), -# 'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), -# 'locked_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), -# 'locked_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locked_posts'", 'null': 'True', 'to': "orm['auth.User']"}), -# 'offensive_flag_count': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), -# 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Post']", 'null': 'True', 'blank': 'True'}), -# 'post_type': ('django.db.models.fields.CharField', [], {'max_length': '255'}), -# 'score': ('django.db.models.fields.IntegerField', [], {'default': '0'}), -# 'self_answer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Answer']", 'null': 'True', 'blank': 'True'}), -# 'self_question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Question']", 'null': 'True', 'blank': 'True'}), -# 'summary': ('django.db.models.fields.CharField', [], {'max_length': '180'}), -# 'text': ('django.db.models.fields.TextField', [], {'null': 'True'}), -# 'thread': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Thread']"}), -# 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), -# 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), -# 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), -# 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) -# }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, 'answer': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'revisions'", 'null': 'True', 'to': "orm['askbot.Answer']"}), diff --git a/askbot/migrations/0089_auto__add_post.py b/askbot/migrations/0089_auto__add_post.py index 83452f6a..9b11cc71 100644 --- a/askbot/migrations/0089_auto__add_post.py +++ b/askbot/migrations/0089_auto__add_post.py @@ -42,6 +42,11 @@ class Migration(SchemaMigration): ('self_question', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='+', null=True, to=orm['askbot.Question'])), ('self_comment', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='+', null=True, to=orm['askbot.Comment'])), ('thread', self.gf('django.db.models.fields.related.ForeignKey')(related_name='posts', to=orm['askbot.Thread'])), + + # "Post-processing" - added manually to add support for URL mapping + ('old_question_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True, default=None, unique=True)), + ('old_answer_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True, default=None, unique=True)), + ('old_comment_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True, default=None, unique=True)), )) db.send_create_signal('askbot', ['Post']) @@ -207,7 +212,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0090_postize_q_a_c.py b/askbot/migrations/0090_postize_q_a_c.py index 050028aa..62bb214e 100644 --- a/askbot/migrations/0090_postize_q_a_c.py +++ b/askbot/migrations/0090_postize_q_a_c.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.migrations import TERM_YELLOW, TERM_RESET + class Migration(DataMigration): def forwards(self, orm): @@ -12,10 +14,26 @@ class Migration(DataMigration): # TODO: start post.id from max(q.id, a.id, c.id) + store old_q_id, old_a_id, old_c_id inside - this is to make sure # we can make old URLs work flawlessly + post_id = max( + # 'or 0' protects against None + orm.Question.objects.aggregate(max_id=models.Max('id'))['max_id'] or 0, + orm.Answer.objects.aggregate(max_id=models.Max('id'))['max_id'] or 0, + orm.Comment.objects.aggregate(max_id=models.Max('id'))['max_id'] or 0, + ) + + print TERM_YELLOW, '[DEBUG] Initial Post.id ==', post_id + 1, TERM_RESET + for q in orm.Question.objects.all(): + post_id += 1 orm.Post.objects.create( + id=post_id, + post_type='question', + old_answer_id=None, + old_question_id=q.id, + old_comment_id=None, + self_answer=None, self_question=q, self_comment=None, @@ -47,9 +65,16 @@ class Migration(DataMigration): ) for ans in orm.Answer.objects.all(): + post_id += 1 orm.Post.objects.create( + id=post_id, + post_type='answer', + old_answer_id=ans.id, + old_question_id=None, + old_comment_id=None, + self_answer=ans, self_question=None, self_comment=None, @@ -94,9 +119,16 @@ class Migration(DataMigration): else: raise ValueError('comment.content_object is neither question nor answer!') + post_id += 1 orm.Post.objects.create( + id=post_id, + post_type='comment', + old_answer_id=None, + old_question_id=None, + old_comment_id=cm.id, + self_answer=None, self_question=None, self_comment=cm, @@ -292,7 +324,12 @@ class Migration(DataMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0091_auto__add_field_vote_voted_post__add_field_activity_question_post.py b/askbot/migrations/0091_auto__add_field_vote_voted_post__add_field_activity_question_post.py index be752bae..dbdbe555 100644 --- a/askbot/migrations/0091_auto__add_field_vote_voted_post__add_field_activity_question_post.py +++ b/askbot/migrations/0091_auto__add_field_vote_voted_post__add_field_activity_question_post.py @@ -180,7 +180,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0092_postize_vote_and_activity.py b/askbot/migrations/0092_postize_vote_and_activity.py index e55df71e..65fb1cf3 100644 --- a/askbot/migrations/0092_postize_vote_and_activity.py +++ b/askbot/migrations/0092_postize_vote_and_activity.py @@ -1,9 +1,12 @@ # encoding: utf-8 import datetime +import sys from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.migrations import TERM_RED_BOLD, TERM_GREEN, TERM_RESET + class Migration(DataMigration): def forwards(self, orm): @@ -26,7 +29,8 @@ class Migration(DataMigration): # (if migrations are applied in a row then contenttypes update is not called between them) ct_post, c = orm['contenttypes.ContentType'].objects.get_or_create(app_label='askbot', model='post', defaults={'name': 'post'}) - print "!!! [Red] Remember to not remove the old content types for Question, Answer and Comment models until all migrations succeed!" + if 'test' not in sys.argv: # Don't confuse users + print TERM_RED_BOLD, "!!! Remember to not remove the old content types for Question, Answer and Comment models until further notice from migration 0101!", TERM_RESET abandoned_activities = [] @@ -39,9 +43,10 @@ class Migration(DataMigration): save = False - model = a.content_type.model - if a.content_type.app_label == 'askbot' and model in ('question', 'answer', 'comment'): - a.object_id = orm.Post.objects.get(**{'self_%s__id' % model: a.object_id}).id + ct = a.content_type + if ct.app_label == 'askbot' and ct.model in ('question', 'answer', 'comment'): + a.content_type = ct_post + a.object_id = orm.Post.objects.get(**{'self_%s__id' % ct.model: a.object_id}).id save = True if a.question: @@ -49,7 +54,6 @@ class Migration(DataMigration): save = True if save: - a.content_type = ct_post a.save() if abandoned_activities: @@ -58,7 +62,8 @@ class Migration(DataMigration): (a.id, '.'.join([a.content_type.app_label, a.content_type.model]), a.object_id) for a in abandoned_activities ] - print "!!! Abandoned activities (num=%d):" % len(abandoned_activities), abandoned_activities_lst + print TERM_RED_BOLD, "!!! Abandoned activities num=%d, total num=%d:" % (len(abandoned_activities), orm.Activity.objects.count()), TERM_RESET + print TERM_GREEN, abandoned_activities_lst, TERM_RESET for a in abandoned_activities: a.delete() @@ -223,7 +228,12 @@ class Migration(DataMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0093_auto__del_field_vote_content_type__del_field_vote_object_id__chg_field.py b/askbot/migrations/0093_auto__del_field_vote_content_type__del_field_vote_object_id__chg_field.py index 1be25360..830a3cd6 100644 --- a/askbot/migrations/0093_auto__del_field_vote_content_type__del_field_vote_object_id__chg_field.py +++ b/askbot/migrations/0093_auto__del_field_vote_content_type__del_field_vote_object_id__chg_field.py @@ -203,7 +203,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0094_auto__add_field_repute_question_post.py b/askbot/migrations/0094_auto__add_field_repute_question_post.py index f231ad65..1235118e 100644 --- a/askbot/migrations/0094_auto__add_field_repute_question_post.py +++ b/askbot/migrations/0094_auto__add_field_repute_question_post.py @@ -173,7 +173,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0095_postize_award_and_repute.py b/askbot/migrations/0095_postize_award_and_repute.py index db18d0d7..bca50617 100644 --- a/askbot/migrations/0095_postize_award_and_repute.py +++ b/askbot/migrations/0095_postize_award_and_repute.py @@ -8,38 +8,15 @@ from django.db import models class Migration(DataMigration): def forwards(self, orm): - if 'test' in sys.argv: # This migration fails when running tests... - return + # ContentType for Post model should be created no later than in migration 0092 + ct_post = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='post') - if orm.Award.objects.exists(): - # Note that for an empty database (most likely a fresh one) - # there are no contenttypes for Question/Answer/Comment models installed, - # because there are no such models anymore - # Therefore we only run this section if there are any Award-s to migrate, - # i.e. there is some legacy data and legacy contenttypes are likely to be present in the database - ct_question = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='question') - ct_answer = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='answer') - ct_comment = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='comment') - - ct_post = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='post') - - for aw in orm.Award.objects.all(): - ct = aw.content_type - postize = False - - if ct == ct_question: - aw.object_id = orm.Post.objects.get(self_question__id=aw.object_id).id - postize = True - elif ct == ct_answer: - aw.object_id = orm.Post.objects.get(self_answer__id=aw.object_id).id - postize = True - elif ct == ct_comment: - aw.object_id = orm.Post.objects.get(self_comment__id=aw.object_id).id - postize = True - - if postize: - aw.content_type = ct_post - aw.save() + for aw in orm.Award.objects.all(): + ct = aw.content_type + if ct.app_label == 'askbot' and ct.model in ('question', 'answer', 'comment'): + aw.content_type = ct_post + aw.object_id = orm.Post.objects.get(**{'self_%s__id' % ct.model: aw.object_id}).id + aw.save() ### @@ -208,7 +185,12 @@ class Migration(DataMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0096_auto__del_field_repute_question.py b/askbot/migrations/0096_auto__del_field_repute_question.py index 5a566976..32d1e446 100644 --- a/askbot/migrations/0096_auto__del_field_repute_question.py +++ b/askbot/migrations/0096_auto__del_field_repute_question.py @@ -173,7 +173,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0097_auto__add_field_thread_accepted_answer_post__add_field_anonymousanswer.py b/askbot/migrations/0097_auto__add_field_thread_accepted_answer_post__add_field_anonymousanswer.py index 5ab266fe..9104422d 100644 --- a/askbot/migrations/0097_auto__add_field_thread_accepted_answer_post__add_field_anonymousanswer.py +++ b/askbot/migrations/0097_auto__add_field_thread_accepted_answer_post__add_field_anonymousanswer.py @@ -192,7 +192,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py b/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py index d269ac32..e253613e 100644 --- a/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py +++ b/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py @@ -7,6 +7,8 @@ from django.db import models class Migration(DataMigration): def forwards(self, orm): + # TODO: Speed this migration up by prefetching data ? + for thread in orm.Thread.objects.all(): if thread.accepted_answer: thread.accepted_answer_post = orm.Post.objects.get(self_answer__id=thread.accepted_answer.id) @@ -191,7 +193,12 @@ class Migration(DataMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('answer', 'revision'), ('question', 'revision'))", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0099_auto__del_field_thread_accepted_answer__del_field_anonymousanswer_ques.py b/askbot/migrations/0099_auto__del_field_thread_accepted_answer__del_field_anonymousanswer_ques.py index d47ea202..ac9507a5 100644 --- a/askbot/migrations/0099_auto__del_field_thread_accepted_answer__del_field_anonymousanswer_ques.py +++ b/askbot/migrations/0099_auto__del_field_thread_accepted_answer__del_field_anonymousanswer_ques.py @@ -227,7 +227,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0100_auto__del_field_post_self_question__del_field_post_self_answer__del_fi.py b/askbot/migrations/0100_auto__del_field_post_self_question__del_field_post_self_answer__del_fi.py index 08552f15..106f8619 100644 --- a/askbot/migrations/0100_auto__del_field_post_self_question__del_field_post_self_answer__del_fi.py +++ b/askbot/migrations/0100_auto__del_field_post_self_question__del_field_post_self_answer__del_fi.py @@ -182,7 +182,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0101_megadeath_of_q_a_c.py b/askbot/migrations/0101_megadeath_of_q_a_c.py index 417463a0..7e63a999 100644 --- a/askbot/migrations/0101_megadeath_of_q_a_c.py +++ b/askbot/migrations/0101_megadeath_of_q_a_c.py @@ -1,9 +1,12 @@ # encoding: utf-8 import datetime +import sys from south.db import db from south.v2 import SchemaMigration from django.db import models +from askbot.migrations import TERM_YELLOW, TERM_RESET + class Migration(SchemaMigration): def forwards(self, orm): @@ -18,6 +21,8 @@ class Migration(SchemaMigration): # Deleting model 'Question' db.delete_table(u'question') + if 'test' not in sys.argv and not db.dry_run: # Don't confuse users + print TERM_YELLOW, 'You are free now to remove content types for Question/Answer/Comment models', TERM_RESET def backwards(self, orm): @@ -213,7 +218,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0102_rename_post_fields_back_1.py b/askbot/migrations/0102_rename_post_fields_back_1.py index 332015b0..9d155ddd 100644 --- a/askbot/migrations/0102_rename_post_fields_back_1.py +++ b/askbot/migrations/0102_rename_post_fields_back_1.py @@ -128,7 +128,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0103_rename_post_fields_back_2.py b/askbot/migrations/0103_rename_post_fields_back_2.py index 87feb037..6640ff83 100644 --- a/askbot/migrations/0103_rename_post_fields_back_2.py +++ b/askbot/migrations/0103_rename_post_fields_back_2.py @@ -128,7 +128,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0104_auto__del_field_repute_question_post__add_field_repute_question.py b/askbot/migrations/0104_auto__del_field_repute_question_post__add_field_repute_question.py index 3a1a87a1..4044cef1 100644 --- a/askbot/migrations/0104_auto__del_field_repute_question_post__add_field_repute_question.py +++ b/askbot/migrations/0104_auto__del_field_repute_question_post__add_field_repute_question.py @@ -128,7 +128,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/0105_restore_anon_ans_q.py b/askbot/migrations/0105_restore_anon_ans_q.py index 3f56332b..05429728 100644 --- a/askbot/migrations/0105_restore_anon_ans_q.py +++ b/askbot/migrations/0105_restore_anon_ans_q.py @@ -128,7 +128,12 @@ class Migration(SchemaMigration): 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + + # "Post-processing" - added manually to add support for URL mapping + 'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), + 'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': True, 'blank': True, 'default': None, 'unique': 'True'}), }, 'askbot.postrevision': { 'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'}, diff --git a/askbot/migrations/__init__.py b/askbot/migrations/__init__.py index e69de29b..ac6b3d47 100644 --- a/askbot/migrations/__init__.py +++ b/askbot/migrations/__init__.py @@ -0,0 +1,7 @@ +# Terminal ANSI codes for printing colored text: +# - http://code.google.com/p/testoob/source/browse/trunk/src/testoob/reporting/colored.py#20 +# - http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python +TERM_RED_BOLD = '\x1b[31;01m\x1b[01m' +TERM_YELLOW = "\x1b[33;01m" +TERM_GREEN = "\x1b[32;06m" +TERM_RESET = '\x1b[0m' diff --git a/askbot/models/post.py b/askbot/models/post.py index 715140c4..0ed57101 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -395,6 +395,11 @@ class PostManager(BaseQuerySetManager): class Post(models.Model): post_type = models.CharField(max_length=255) + + old_question_id = models.PositiveIntegerField(null=True, blank=True, default=None, unique=True) + old_answer_id = models.PositiveIntegerField(null=True, blank=True, default=None, unique=True) + old_comment_id = models.PositiveIntegerField(null=True, blank=True, default=None, unique=True) + parent = models.ForeignKey('Post', blank=True, null=True, related_name='comments') # Answer or Question for Comment thread = models.ForeignKey('Thread', related_name='posts') |