mongo to sql convert: Better Ordering
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 22 Jan 2012 15:57:56 +0000 (16:57 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Thu, 23 Feb 2012 22:44:13 +0000 (23:44 +0100)
Order the conversion by the "created" attribute. That way
the sql ids are mostly in the order they would have been,
if sql was used earlier.

Makes things nicer to look at in a db dump.

mediagoblin/db/sql/convert.py

index 36d6fc7f6a442c44f3e2d2eeff6dcbdb8ef27eec..f5c93af51ef9fa1df4e5672b041dad24897c83f5 100644 (file)
@@ -49,7 +49,7 @@ def copy_reference_attr(entry, new_entry, ref_attr):
 def convert_users(mk_db):
     session = Session()
 
-    for entry in mk_db.User.find():
+    for entry in mk_db.User.find().sort('created'):
         print entry.username
 
         new_entry = User()
@@ -71,7 +71,7 @@ def convert_users(mk_db):
 def convert_media_entries(mk_db):
     session = Session()
 
-    for entry in mk_db.MediaEntry.find():
+    for entry in mk_db.MediaEntry.find().sort('created'):
         print repr(entry.title)
 
         new_entry = MediaEntry()
@@ -100,7 +100,7 @@ def convert_media_tags(mk_db):
     session = Session()
     session.autoflush = False
 
-    for media in mk_db.MediaEntry.find():
+    for media in mk_db.MediaEntry.find().sort('created'):
         print repr(media.title)
 
         for otag in media.tags:
@@ -127,7 +127,7 @@ def convert_media_tags(mk_db):
 def convert_media_comments(mk_db):
     session = Session()
 
-    for entry in mk_db.MediaComment.find():
+    for entry in mk_db.MediaComment.find().sort('created'):
         print repr(entry.content)
 
         new_entry = MediaComment()