Skip to content

Commit e619143

Browse files
committed
Updated person migration 0017 to avoid database referential inconsistency due to missing person records.
- Legacy-Id: 13371
1 parent 355c5cb commit e619143

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

ietf/person/migrations/0017_add_email_address_from_parsed_rfcs.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,39 @@
148148
}
149149

150150

151+
known_missing_person_records = [
152+
(3150, "Steve Kille"),
153+
]
154+
151155
def forward(apps,schema_editor):
152156

153157
Email=apps.get_model('person','Email')
158+
Person = apps.get_model('person', 'Person')
159+
160+
for id, name in known_missing_person_records:
161+
if not Person.objects.filter(id=id).exists():
162+
Person.objects.create(id=id, name=name, ascii=name)
154163

155164
# Sanity check
156-
for addr in new_addresses.keys():
165+
for addr, id in new_addresses.items():
157166
if Email.objects.filter(address__iexact=addr).exists():
158167
raise Exception("%s already exists in the Email table"%addr)
168+
if not Person.objects.filter(id=id).exists():
169+
raise Exception("ID #%s is missing in the Person table"%id)
159170

160171
for addr in new_addresses.keys():
161172
Email.objects.create(address=addr,person_id=new_addresses[addr],active=False,primary=False)
162173

163174
def reverse(apps,schema_editor):
164175
Email=apps.get_model('person','Email')
176+
Person = apps.get_model('person', 'Person')
165177
#Person=apps.get_model('person','Person')
166178
#print "new_addresses = {"
167179
#for addr in sorted(new_addresses.keys()):
168180
# print "'%s': %s, # %s"%(addr,new_addresses[addr],Person.objects.get(pk=new_addresses[addr]).name)
169181
#print "}"
170182
Email.objects.filter(address__in=new_addresses.keys()).delete()
183+
Person.objects.filter(id__in=[ id for id,name in known_missing_person_records ]).delete()
171184

172185
class Migration(migrations.Migration):
173186

0 commit comments

Comments
 (0)