def move_limits_to_user(apps, schema_editor):
    """Move limits from Pool to User."""
    LimitsPool = apps.get_model('limits', 'LimitsPool')
    UserObjectLimit = apps.get_model('limits', 'UserObjectLimit')
    ContentType = apps.get_model('contenttypes', 'ContentType')
    if not ContentType.objects.exists():
        return
    name_to_content_type = {'domains_limit': ContentType.objects.get(
        app_label='admin', model='domain'), 'domain_aliases_limit':
        ContentType.objects.get(app_label='admin', model='domainalias'),
        'mailboxes_limit': ContentType.objects.get(app_label='admin', model
        ='mailbox'), 'mailbox_aliases_limit': ContentType.objects.get(
        app_label='admin', model='alias'), 'domain_admins_limit':
        ContentType.objects.get(app_label='core', model='user')}
    to_create = []
    qset = LimitsPool.objects.select_related('user').prefetch_related(
        'limit_set')
    for pool in qset:
        for limit in pool.limit_set.all():
            objlimit = UserObjectLimit(user=pool.user, max_value=limit.
                maxvalue, name=limit.name.replace('_limit', ''),
                content_type=name_to_content_type[limit.name])
            to_create.append(objlimit)
    UserObjectLimit.objects.bulk_create(to_create)
