Skip to content

Commit cf5ac68

Browse files
committed
Renumbered and updated the migrations merged in from the eventsaving work. Made the dochistory-adding migration idempotent, and added progress indication as this migration may take as much as an hour to run.
- Legacy-Id: 11854
1 parent d868371 commit cf5ac68

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

ietf/doc/migrations/0012_auto_20160207_0537.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

44
from django.db import models, migrations

ietf/doc/migrations/0011_auto_20151027_1127.py renamed to ietf/doc/migrations/0013_auto_20151027_1127.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
import sys
5+
46
from django.db import migrations
57

68
def fix_buggy_author_foreignkey(apps, schema_editor):
@@ -17,6 +19,10 @@ def save_all_documents_in_history(apps, schema_editor):
1719
DocumentAuthor = apps.get_model("doc", "DocumentAuthor")
1820
DocHistoryAuthor = apps.get_model("doc", "DocHistoryAuthor")
1921

22+
sys.stderr.write('\n'
23+
' Ensuring that all documents have document history entries.\n'
24+
' This could take as much as an hour to run.\n')
25+
2026
def canonical_name(self):
2127
name = self.name
2228
state = State.objects.filter(document=self, type_id=self.type_id).first()
@@ -38,6 +44,8 @@ def charter_name_for_group(group):
3844

3945
def save_document_in_history(doc):
4046
"""Save a snapshot of document and related objects in the database."""
47+
48+
4149
def get_model_fields_as_dict(obj):
4250
return dict((field.name, getattr(obj, field.name))
4351
for field in obj._meta.fields
@@ -48,8 +56,21 @@ def get_model_fields_as_dict(obj):
4856
fields["doc"] = doc
4957
fields["name"] = canonical_name(doc)
5058

51-
dochist = DocHistory(**fields)
52-
dochist.save()
59+
objs = DocHistory.objects.filter(**fields)
60+
if objs.exists():
61+
try:
62+
dochist = objs.get(**fields)
63+
sys.stderr.write('.')
64+
except DocHistory.MultipleObjectsReturned:
65+
dochist_list = list(objs)
66+
for dochist in dochist_list[1:]:
67+
dochist.delete()
68+
dochist = dochist_list[0]
69+
sys.stderr.write('-')
70+
else:
71+
dochist = DocHistory(**fields)
72+
dochist.save()
73+
sys.stderr.write('+')
5374

5475
# copy many to many
5576
for field in doc._meta.many_to_many:
@@ -82,8 +103,8 @@ def transfer_fields(obj, HistModel):
82103
class Migration(migrations.Migration):
83104

84105
dependencies = [
85-
('doc', '0010_auto_20150930_0251'),
86-
('group', '0007_auto_20150930_0758'),
106+
('doc', '0012_auto_20160207_0537'),
107+
('group', '0009_auto_20150930_0758'),
87108
]
88109

89110
operations = [

ietf/group/migrations/0007_auto_20150930_0758.py renamed to ietf/group/migrations/0009_auto_20150930_0758.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33
import os, datetime
44

@@ -108,7 +108,7 @@ class Migration(migrations.Migration):
108108

109109
dependencies = [
110110
('doc', '0010_auto_20150930_0251'),
111-
('group', '0006_auto_20150718_0509'),
111+
('group', '0008_auto_20160505_0523'),
112112
]
113113

114114
operations = [

0 commit comments

Comments
 (0)