code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      for slc in (
          session.query(Slice).filter(Slice.viz_type == "pie").all()
      ):
          try:
              params = json.loads(slc.params)
  
              if "metrics" in params:
                  if params["metrics"]:
                      params["metric"] = params["metrics"][0]
  
                  del params["metrics"]
                  slc.params = json.dumps(params, sort_keys=True)
          except Exception:
              pass
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2018-06-14_14-31_80a67c5192fa_single_pie_chart_metric.py
imports: import json
  from alembic import op
  from sqlalchemy import Column, Integer, String, Text
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade() without return types