22from __future__ import unicode_literals
33
44import sys
5+ from tqdm import tqdm
56
67from django .db import migrations
78
@@ -60,17 +61,14 @@ def get_model_fields_as_dict(obj):
6061 if objs .exists ():
6162 try :
6263 dochist = objs .get (** fields )
63- sys .stderr .write ('.' )
6464 except DocHistory .MultipleObjectsReturned :
6565 dochist_list = list (objs )
6666 for dochist in dochist_list [1 :]:
6767 dochist .delete ()
6868 dochist = dochist_list [0 ]
69- sys .stderr .write ('-' )
7069 else :
7170 dochist = DocHistory (** fields )
7271 dochist .save ()
73- sys .stderr .write ('+' )
7472
7573 # copy many to many
7674 for field in doc ._meta .many_to_many :
@@ -97,9 +95,13 @@ def transfer_fields(obj, HistModel):
9795 from django .conf import settings
9896 settings .DEBUG = False # prevent out-of-memory problems
9997
100- for d in Document .objects .iterator ():
98+ docs = Document .objects .all ()
99+ for d in tqdm (docs ):
101100 save_document_in_history (d )
102101
102+ def noop_backward (apps , schema_editor ):
103+ pass
104+
103105class Migration (migrations .Migration ):
104106
105107 dependencies = [
@@ -108,6 +110,6 @@ class Migration(migrations.Migration):
108110 ]
109111
110112 operations = [
111- migrations .RunPython (fix_buggy_author_foreignkey ),
112- migrations .RunPython (save_all_documents_in_history )
113+ migrations .RunPython (fix_buggy_author_foreignkey , noop_backward ),
114+ migrations .RunPython (save_all_documents_in_history , noop_backward )
113115 ]
0 commit comments