@@ -0,0 +1,1316 @@
+# -*- coding: utf-8 -*-%0A# Generated by Django 1.11.1 on 2017-06-16 19:59%0A%22%22%22Removes Email objects that associated with unconfirmed users. These%0Awere incorrectly created in 0033_user_emails_to_fk.%0A%22%22%22%0Afrom __future__ import unicode_literals%0A%0Afrom django.db import migrations%0A%0A%0Adef remove_emails(state, *args, **kwargs):%0A    Email = state.get_model('osf', 'email')%0A    Email.objects.filter(user__date_confirmed__isnull=True).delete()%0A%0A# copied from 0033_user_emails_to_fk%0Adef restore_emails(state, *args, **kwargs):%0A    Email = state.get_model('osf', 'email')%0A    OSFUser = state.get_model('osf', 'osfuser')%0A    for user in OSFUser.objects.filter(date_confirmed__isnull=True).values('id', 'username', 'is_active'):%0A        uid = user%5B'id'%5D%0A        primary_email = user%5B'username'%5D.lower().strip()%0A        active = user%5B'is_active'%5D%0A        if active or not Email.objects.filter(address=primary_email).exists():%0A            _, created = Email.objects.get_or_create(address=primary_email, user_id=uid)%0A            assert created, 'Email object for username %7B%7D already exists'.format(primary_email)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('osf', '0036_auto_20170605_1520'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(%0A            remove_emails, restore_emails%0A        ),%0A    %5D%0A

Add migration to remove Emails associated with unconfirmed users