2022-05-10 16:56:30 +03:00
|
|
|
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
|
|
|
]
|