code: def upgrade():
      bind = op.get_bind()
      session = Session(bind=bind)
  
      if (
          session.query(TrialValueModel)
          .join(
              TrialModel,
              TrialValueModel.trial_id == TrialModel.trial_id,
          )
          .filter(
              and_(
                  TrialModel.state == TrialState.COMPLETE,
                  TrialValueModel.value.is_(None),
              )
          )
          .count()
      ) != 0:
          raise ValueError(
              "Found invalid trial_values records (value=None and state='COMPLETE')"
          )
      session.query(TrialValueModel).filter(
          TrialValueModel.value.is_(None)
      ).delete()
  
      with op.batch_alter_table(
          "trial_intermediate_values"
      ) as batch_op:
          batch_op.alter_column(
              "intermediate_value",
              type_=Float(precision=FLOAT_PRECISION),
              nullable=True,
          )
      with op.batch_alter_table("trial_params") as batch_op:
          batch_op.alter_column(
              "param_value",
              type_=Float(precision=FLOAT_PRECISION),
              existing_nullable=True,
          )
      with op.batch_alter_table("trial_values") as batch_op:
          batch_op.alter_column(
              "value",
              type_=Float(precision=FLOAT_PRECISION),
              nullable=False,
          )
  
file_path: optuna/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py
imports: import enum
  from alembic import op
  from sqlalchemy import and_
  from sqlalchemy import Column
  from sqlalchemy import Enum
  from sqlalchemy import Float
  from sqlalchemy import ForeignKey
  from sqlalchemy import Integer
  from sqlalchemy.orm import Session
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade() without return types