code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
      with op.batch_alter_table("slices") as batch_op:
          for slc in (
              session.query(Slice)
              .filter(Slice.datasource_type != "table")
              .all()
          ):
              if slc.datasource_type == "query":
                  upgrade_slc(slc)
                  session.add(slc)
  
              else:
                  logger.warning(
                      "unknown value detected for slc.datasource_type: %s",
                      slc.datasource_type,
                  )
  
      # need commit the updated values for Slice.datasource_type before creating constraint
      session.commit()
  
      with op.batch_alter_table("slices") as batch_op:
          batch_op.create_check_constraint(
              "ck_chart_datasource", "datasource_type in ('table')"
          )
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py
imports: import json
  import logging
  import sqlalchemy
  from alembic import op
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db
label_desc: Use image node_id 2 for calling a global function with example usage: upgrade() without return types