code: def _delete_old_permissions(
      session: Session,
      pvm_map: dict[PermissionView, list[PermissionView]],
  ) -> None:
      """
      Delete old permissions:
      - Delete the PermissionView
      - Deletes the Permission if it's an orphan now
      - Deletes the ViewMenu if it's an orphan now
      """
      # Delete old permissions
      for old_pvm, new_pvms in pvm_map.items():
          old_permission_name = old_pvm.permission.name
          old_view_name = old_pvm.view_menu.name
          logger.info(f"Going to delete pvm: {old_pvm}")
          session.delete(old_pvm)
          pvms_with_permission = (
              session.query(PermissionView)
              .join(Permission)
              .filter(Permission.name == old_permission_name)
          ).first()
          if not pvms_with_permission:
              logger.info(
                  f"Going to delete permission: {old_pvm.permission}"
              )
              session.delete(old_pvm.permission)
          pvms_with_view_menu = (
              session.query(PermissionView)
              .join(ViewMenu)
              .filter(ViewMenu.name == old_view_name)
          ).first()
          if not pvms_with_view_menu:
              logger.info(
                  f"Going to delete view_menu: {old_pvm.view_menu}"
              )
              session.delete(old_pvm.view_menu)
  
imports: import logging
  from dataclasses import dataclass
  from sqlalchemy import Column, ForeignKey, Integer, Sequence, String, Table, UniqueConstraint
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import Load, relationship, Session
label_desc: Use image node_id 6 for calling a global function with example usage: _delete_old_permissions(session, pvm_map) without return types