@@ -0,0 +1,1581 @@
+from django.db.models.functions import Lower%0Afrom django.db.models import Count%0A%0Afrom bluebottle.members.models import Member%0A%0Afrom bluebottle.clients.models import Client%0Afrom bluebottle.clients.utils import LocalTenant%0A%0Afrom bluebottle.activities.models import Activity, Contributor%0Afrom bluebottle.initiatives.models import Initiative%0A%0A%0Afor client in Client.objects.all():%0A    with LocalTenant(client):%0A        duplicate = Member.objects.annotate(%0A            lower=Lower('email')%0A        ).values('lower').annotate(count=Count('lower')).filter(count__gt=1)%0A        for result in duplicate:%0A            first = Member.objects.filter(email__iexact=result%5B'lower'%5D).order_by('date_joined').first()%0A            for duplicate in Member.objects.filter(%0A                email__iexact=result%5B'lower'%5D%0A            ).exclude(pk=first.pk).order_by('date_joined'):%0A                for activity in Activity.objects.filter(owner=duplicate):%0A                    activity.owner = first%0A                    activity.execute_triggers(send_messages=False)%0A                    activity.save()%0A%0A                for contributor in Contributor.objects.filter(user=duplicate):%0A                    contributor.user = first%0A                    contributor.execute_triggers(send_messages=False)%0A                    contributor.save()%0A%0A                for initiative in Initiative.objects.filter(owner=duplicate):%0A                    initiative.owner = first%0A                    initiative.execute_triggers(send_messages=False)%0A                    initiative.save()%0A%0A                duplicate.anonymize()%0A

Add dedplucate script