code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
      for dashboard in paginated_update(session.query(Dashboard)):
          #
          # This is needed in order to work-around a potential issue
          # that some folks may have run into where their json_metadata's
          # were left partially upgraded.
          #
          needs_upgrade = True
          try:
              json_metadata = json.loads(
                  dashboard.json_metadata or "{}"
              )
              new_chart_configuration = {}
              for config in json_metadata.get(
                  "chart_configuration", {}
              ).values():
                  if not isinstance(config, dict):
                      continue
                  chart_id = int(config.get("id", 0))
                  scope = config.get("crossFilters", {}).get(
                      "scope", {}
                  )
  
                  # Skip any JSON's that have the "new" structure
                  if not isinstance(scope, dict):
                      needs_upgrade = False
                      continue
  
                  excluded = [
                      int(excluded_id)
                      for excluded_id in scope.get("excluded", [])
                  ]
                  new_chart_configuration[chart_id] = copy.deepcopy(
                      config
                  )
                  new_chart_configuration[chart_id]["id"] = chart_id
                  new_chart_configuration[chart_id]["crossFilters"][
                      "scope"
                  ]["excluded"] = excluded
                  if scope.get("rootPath") == [
                      "ROOT_ID"
                  ] and excluded == [chart_id]:
                      new_chart_configuration[chart_id]["crossFilters"][
                          "scope"
                      ] = "global"
  
              json_metadata[
                  "chart_configuration"
              ] = new_chart_configuration
  
              if needs_upgrade:
                  dashboard.json_metadata = json.dumps(json_metadata)
  
          except Exception as e:
              logger.exception("Failed to run up migration")
              raise e
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2023-05-11_12-41_4ea966691069_cross_filter_global_scoping.py
imports: import copy
  import json
  import logging
  import sqlalchemy
  from alembic import op
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db
  from superset.migrations.shared.utils import paginated_update
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade() without return types