def METHOD_NAME(apps, schema):
    """Migrate the JSONB attribute map to a M2M relation."""
    Product = apps.get_model("product", "Product")
    AssignedProductAttribute = apps.get_model("product", "AssignedProductAttribute")
    product_qs = Product.objects.prefetch_related(
        "product_type__attributeproduct__attribute__values"
    )
    for product in product_qs:
        attribute_map = product.old_attributes
        # Skip if no attribute is assigned to this product
        if not attribute_map:
            continue
        product_type = product.product_type
        for attribute_pk, values_pk in attribute_map.items():
            attribute_rel = product_type.attributeproduct.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 = AssignedProductAttribute.objects.create(
                product=product, assignment=attribute_rel
            )
            assignment.values.set(values)