code: def downgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      for dashboard in paginated_update(session.query(Dashboard)):
          try:
              json_metadata = json.loads(dashboard.json_metadata)
              new_chart_configuration = {}
              for config in json_metadata.get(
                  "chart_configuration", {}
              ).values():
                  if not isinstance(config, dict):
                      continue
                  chart_id = config.get("id")
                  if chart_id is None:
                      continue
                  scope = config.get("crossFilters", {}).get(
                      "scope", {}
                  )
                  new_chart_configuration[chart_id] = copy.deepcopy(
                      config
                  )
                  if scope in ("global", "Global"):
                      new_chart_configuration[chart_id]["crossFilters"][
                          "scope"
                      ] = {
                          "rootPath": ["ROOT_ID"],
                          "excluded": [chart_id],
                      }
  
              json_metadata[
                  "chart_configuration"
              ] = new_chart_configuration
  
              if "global_chart_configuration" in json_metadata:
                  del json_metadata["global_chart_configuration"]
  
              dashboard.json_metadata = json.dumps(json_metadata)
  
          except Exception as e:
              logger.exception("Failed to run down 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 2 for calling a global function with example usage: downgrade() without return types