1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/peeringdb_server/migrations/0015_email_address.py

26 lines
843 B
Python
Raw Permalink Normal View History

from django.db import migrations
2018-11-08 19:45:21 +00:00
def create_email_instances(apps, schema_editor):
users = apps.get_model("peeringdb_server", "User")
2019-12-05 16:57:52 +00:00
emailAddresses = apps.get_model("account", "EmailAddress")
2018-11-08 19:45:21 +00:00
all_emails = emailAddresses.objects.all()
emails = []
emails_dict = {}
for user in users.objects.all():
l_email = user.email.lower()
2019-12-05 16:57:52 +00:00
if not all_emails.filter(email=l_email).exists() and l_email not in emails_dict:
2018-11-08 19:45:21 +00:00
emails_dict[l_email] = 1
2019-12-05 16:57:52 +00:00
emails.append(emailAddresses(email=l_email, user=user, primary=True))
2018-11-08 19:45:21 +00:00
emailAddresses.objects.bulk_create(emails)
class Migration(migrations.Migration):
dependencies = [
2019-12-05 16:57:52 +00:00
("peeringdb_server", "0014_clt_description"),
2018-11-08 19:45:21 +00:00
]
operations = [
2019-12-05 16:57:52 +00:00
migrations.RunPython(create_email_instances, migrations.RunPython.noop),
2018-11-08 19:45:21 +00:00
]