def METHOD_NAME(apps, schema):
    """Migrate the JSONB attribute map to a M2M relation."""
    ProductVariant = apps.get_model("product", "ProductVariant")
    AssignedVariantAttribute = apps.get_model("product", "AssignedVariantAttribute")
    variants_qs = ProductVariant.objects.prefetch_related(
        "product__product_type__attributevariant__attribute__values"
    )
    for variant in variants_qs:
        attribute_map = variant.old_attributes
        # Skip if no attribute is assigned to this variant
        if not attribute_map:
            continue
        product_type = variant.product.product_type
        for attribute_pk, values_pk in attribute_map.items():
            attribute_rel = product_type.attributevariant.filter(
                attribute_id=attribute_pk
            ).first()
            # Skip the assigned attribute if it is not assigned to the product type
            if attribute_rel is None:
                continue
            values = list(attribute_rel.attribute.values.filter(pk__in=values_pk))
            # If no values are associated, skip
            if not values:
                continue
            assignment = AssignedVariantAttribute.objects.create(
                variant=variant, assignment=attribute_rel
            )
            assignment.values.set(values)