code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      dashboards = (
          session.query(Dashboard)
          .filter(
              Dashboard.json_metadata.like(
                  '%"filter_sets_configuration"%'
              )
          )
          .all()
      )
      changed_filter_sets, changed_filters = 0, 0
      for dashboard in dashboards:
          try:
              json_metadata = json.loads(dashboard.json_metadata)
  
              # upgrade native select filter metadata
              native_filters = json_metadata.get(
                  "native_filter_configuration"
              )
              if native_filters:
                  upgrade_select_filters(native_filters)
  
              # upgrade filter sets
              filter_sets = json_metadata["filter_sets_configuration"]
              for filter_set in filter_sets:
                  changed_filter_sets += 1
                  changed_filters += upgrade_filter_set(filter_set)
  
              dashboard.json_metadata = json.dumps(
                  json_metadata, sort_keys=True
              )
  
          except Exception as e:
              print(
                  f"Parsing json_metadata for dashboard {dashboard.id} failed."
              )
              raise e
  
      session.commit()
      session.close()
      print(
          f"Updated {changed_filter_sets} filter sets with {changed_filters} filters."
      )
  
file_path: superset/superset/migrations/versions/2021-04-12_12-38_fc3a3a8ff221_migrate_filter_sets_to_new_format.py
imports: import json
  from collections.abc import Iterable
  from typing import Any
  from alembic import op
  from sqlalchemy import Column, Integer, Text
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db
label_desc: Use image node_id 4 for calling a global function with example usage: upgrade() without return types