def METHOD_NAME():
    bind = op.get_bind()
    session = db.Session(bind=bind)
    # Delete the orphaned metrics records.
    for record in session.query(DruidMetric).all():
        if record.datasource_id is None:
            session.delete(record)
    session.commit()
    # Enforce that metrics.metric_name column be non-nullable.
    with op.batch_alter_table("metrics") as batch_op:
        batch_op.alter_column("metric_name", existing_type=String(255), nullable=False)
    # Enforce that metrics.json column be non-nullable.
    with op.batch_alter_table("metrics") as batch_op:
        batch_op.alter_column("json", existing_type=Text, nullable=False)
    # Delete the orphaned sql_metrics records.
    for record in session.query(SqlMetric).all():
        if record.table_id is None:
            session.delete(record)
    session.commit()
    # Reduce the size of the sql_metrics.metric_name column for constraint
    # viability and enforce that it to be non-nullable.
    with op.batch_alter_table("sql_metrics") as batch_op:
        batch_op.alter_column(
            "metric_name", existing_type=String(512), nullable=False, type_=String(255)
        )
    # Enforce that sql_metrics.expression column be non-nullable.
    with op.batch_alter_table("sql_metrics") as batch_op:
        batch_op.alter_column("expression", existing_type=Text, nullable=False)
    # Add the missing uniqueness constraint to the sql_metrics table.
    with op.batch_alter_table("sql_metrics", naming_convention=conv) as batch_op:
        batch_op.create_unique_constraint(
            "uq_sql_metrics_metric_name", ["metric_name", "table_id"]
        )