mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Adding sanity checks in FeedData data migration.
This commit is contained in:
parent
a105606874
commit
ad0fea6c7c
1 changed files with 25 additions and 21 deletions
|
@ -12,27 +12,31 @@ class Migration(DataMigration):
|
|||
def forwards(self, orm):
|
||||
print "FeedData: %s" % FeedData.objects.count()
|
||||
|
||||
feeds = Feed.objects.all().order_by('-average_stories_per_month')
|
||||
feed_count = feeds.count()
|
||||
i = 0
|
||||
for feed in feeds:
|
||||
i += 1
|
||||
print "%s/%s: %s" % (i, feed_count, feed,)
|
||||
sys.stdout.flush()
|
||||
data = {
|
||||
'feed_tagline': feed.feed_tagline and feed.feed_tagline[:1023],
|
||||
'story_count_history': feed.story_count_history,
|
||||
'popular_tags': feed.popular_tags and feed.popular_tags[:1023],
|
||||
'popular_authors': feed.popular_authors and feed.popular_authors[:2047],
|
||||
}
|
||||
try:
|
||||
sid = transaction.savepoint()
|
||||
FeedData.objects.create(feed=feed, **data)
|
||||
transaction.savepoint_commit(sid)
|
||||
except Exception, e:
|
||||
print "!!!!!!!!!!!!!!! Exception: %s" % e
|
||||
transaction.savepoint_rollback(sid)
|
||||
pass
|
||||
f = 0
|
||||
while True:
|
||||
feeds = Feed.objects.all().order_by('-average_stories_per_month')[f:f+10000]
|
||||
f += 10000
|
||||
feed_count = feeds.count()
|
||||
i = int(f)
|
||||
if not feed_count: break
|
||||
for feed in feeds:
|
||||
i += 1
|
||||
print "%s/%s: %s" % (i, feed_count, feed,)
|
||||
sys.stdout.flush()
|
||||
data = {
|
||||
'feed_tagline': feed.feed_tagline and feed.feed_tagline[:1023],
|
||||
'story_count_history': feed.story_count_history,
|
||||
'popular_tags': feed.popular_tags and feed.popular_tags[:1023],
|
||||
'popular_authors': feed.popular_authors and feed.popular_authors[:2047],
|
||||
}
|
||||
try:
|
||||
sid = transaction.savepoint()
|
||||
FeedData.objects.create(feed=feed, **data)
|
||||
transaction.savepoint_commit(sid)
|
||||
except Exception, e:
|
||||
print "!!!!!!!!!!!!!!! Exception: %s" % e
|
||||
transaction.savepoint_rollback(sid)
|
||||
pass
|
||||
|
||||
def backwards(self, orm):
|
||||
print "Start FeedData: %s" % (FeedData.objects.count())
|
||||
|
|
Loading…
Add table
Reference in a new issue