code: def upgrade():
      bind = op.get_bind()
      inspector = sa.inspect(bind)
      column_names = [
          c["name"]
          for c in inspector.get_columns("trial_intermediate_values")
      ]
  
      sa.Enum(IntermediateValueModel.TrialIntermediateValueType).create(
          bind, checkfirst=True
      )
  
      # MySQL and PostgreSQL supports DEFAULT clause like 'ALTER TABLE <tbl_name>
      # ADD COLUMN <col_name> ... DEFAULT "FINITE_OR_NAN"', but seemingly Alembic
      # does not support such a SQL statement. So first add a column with schema-level
      # default value setting, then remove it by `batch_op.alter_column()`.
      if "intermediate_value_type" not in column_names:
          with op.batch_alter_table(
              "trial_intermediate_values"
          ) as batch_op:
              batch_op.add_column(
                  sa.Column(
                      "intermediate_value_type",
                      sa.Enum(
                          "FINITE",
                          "INF_POS",
                          "INF_NEG",
                          "NAN",
                          name="trialintermediatevaluetype",
                      ),
                      nullable=False,
                      server_default="FINITE",
                  ),
              )
      with op.batch_alter_table(
          "trial_intermediate_values"
      ) as batch_op:
          batch_op.alter_column(
              "intermediate_value_type",
              existing_type=sa.Enum(
                  "FINITE",
                  "INF_POS",
                  "INF_NEG",
                  "NAN",
                  name="trialintermediatevaluetype",
              ),
              existing_nullable=False,
              server_default=None,
          )
  
      session = orm.Session(bind=bind)
      try:
          records = (
              session.query(IntermediateValueModel)
              .filter(
                  sa.or_(
                      IntermediateValueModel.intermediate_value > 1e16,
                      IntermediateValueModel.intermediate_value < -1e16,
                      IntermediateValueModel.intermediate_value.is_(
                          None
                      ),
                  )
              )
              .all()
          )
          mapping = []
          for r in records:
              value: float
              if r.intermediate_value is None or np.isnan(
                  r.intermediate_value
              ):
                  value = float("nan")
              elif np.isclose(
                  r.intermediate_value, RDB_MAX_FLOAT
              ) or np.isposinf(r.intermediate_value):
                  value = float("inf")
              elif np.isclose(
                  r.intermediate_value, RDB_MIN_FLOAT
              ) or np.isneginf(r.intermediate_value):
                  value = float("-inf")
              else:
                  value = r.intermediate_value
              (
                  stored_value,
                  float_type,
              ) = IntermediateValueModel.intermediate_value_to_stored_repr(
                  value
              )
              mapping.append(
                  {
                      "trial_intermediate_value_id": r.trial_intermediate_value_id,
                      "intermediate_value_type": float_type,
                      "intermediate_value": stored_value,
                  }
              )
          session.bulk_update_mappings(IntermediateValueModel, mapping)
          session.commit()
      except SQLAlchemyError as e:
          session.rollback()
          raise e
      finally:
          session.close()
  
file_path: optuna/optuna/storages/_rdb/alembic/versions/v3.0.0.c.py
imports: import enum
  import numpy
  from alembic import op
  import sqlalchemy
  from sqlalchemy.exc import SQLAlchemyError
  from sqlalchemy import orm
  from typing import Optional
  from typing import Tuple
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade() without return types