code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      query = (
          session.query(Slice, Database)
          .filter(Slice.datasource_type == "table")
          .filter(Slice.datasource_id == Table.id)
          .filter(Table.database_id == Database.id)
          .all()
      )
  
      for slc, database in query:
          try:
              params = json.loads(slc.params)
              duration_dict = duration_by_name(database)
              granularity = params.get("time_grain_sqla")
              if granularity in duration_dict:
                  params["time_grain_sqla"] = duration_dict[granularity]
                  slc.params = json.dumps(params, sort_keys=True)
          except Exception:
              pass
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2020-04-29_09-24_620241d1153f_update_time_grain_sqla.py
imports: import json
  from alembic import op
  from sqlalchemy import Column, ForeignKey, Integer, Text
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db, db_engine_specs
  from superset.databases.utils import make_url_safe
label_desc: Use image node_id 2 for calling a global function with example usage: upgrade() without return types