Adding sanity checks in FeedData data migration.

This commit is contained in:
Samuel Clay 2011-01-17 21:07:56 -05:00
parent a105606874
commit ad0fea6c7c

View file

@ -12,27 +12,31 @@ class Migration(DataMigration):
def forwards(self, orm): def forwards(self, orm):
print "FeedData: %s" % FeedData.objects.count() print "FeedData: %s" % FeedData.objects.count()
feeds = Feed.objects.all().order_by('-average_stories_per_month') f = 0
feed_count = feeds.count() while True:
i = 0 feeds = Feed.objects.all().order_by('-average_stories_per_month')[f:f+10000]
for feed in feeds: f += 10000
i += 1 feed_count = feeds.count()
print "%s/%s: %s" % (i, feed_count, feed,) i = int(f)
sys.stdout.flush() if not feed_count: break
data = { for feed in feeds:
'feed_tagline': feed.feed_tagline and feed.feed_tagline[:1023], i += 1
'story_count_history': feed.story_count_history, print "%s/%s: %s" % (i, feed_count, feed,)
'popular_tags': feed.popular_tags and feed.popular_tags[:1023], sys.stdout.flush()
'popular_authors': feed.popular_authors and feed.popular_authors[:2047], data = {
} 'feed_tagline': feed.feed_tagline and feed.feed_tagline[:1023],
try: 'story_count_history': feed.story_count_history,
sid = transaction.savepoint() 'popular_tags': feed.popular_tags and feed.popular_tags[:1023],
FeedData.objects.create(feed=feed, **data) 'popular_authors': feed.popular_authors and feed.popular_authors[:2047],
transaction.savepoint_commit(sid) }
except Exception, e: try:
print "!!!!!!!!!!!!!!! Exception: %s" % e sid = transaction.savepoint()
transaction.savepoint_rollback(sid) FeedData.objects.create(feed=feed, **data)
pass transaction.savepoint_commit(sid)
except Exception, e:
print "!!!!!!!!!!!!!!! Exception: %s" % e
transaction.savepoint_rollback(sid)
pass
def backwards(self, orm): def backwards(self, orm):
print "Start FeedData: %s" % (FeedData.objects.count()) print "Start FeedData: %s" % (FeedData.objects.count())