code: def upgrade_documents(storage):
      """Upgrade scheme of the documents"""
      for experiment in storage.fetch_experiments({}):
          add_version(experiment)
          uid = experiment.pop("_id")
          algorithm = None
          if "algorithms" in experiment:
              algorithm = experiment.pop("algorithms")
          if "algorithm" in experiment:
              algorithm = experiment.pop("algorithm")
  
          if algorithm is None:
              raise ConfigurationError(
                  "The data was corrupted, as there was no algorithm in the experiment"
              )
  
          storage.update_experiment(uid=experiment, **experiment)
          storage.write_algorithm_lock(uid, algorithm)
  
          for trial in storage.fetch_trials(uid=uid):
              # trial_config = trial.to_dict()
              assert trial.id_override is not None
              # This will overwrite the trial with correct dict structure
              # (ex: have _id set to id_override and id set to trial.hash_name == trial.id.
              # storage.update_trial(trial, uid=trial.id_override)
              # pylint: disable=protected-access
              storage._db.write(
                  "trials",
                  data=trial.to_dict(),
                  query={"_id": trial.id_override},
              )
  
file_path: orion/src/orion/core/cli/db/upgrade.py
imports: import argparse
  import logging
  import sys
  from orion.core.io import experiment_builder
  from orion.core.io.config import ConfigurationError
  from orion.core.io.database.ephemeraldb import EphemeralCollection
  from orion.core.io.database.mongodb import MongoDB
  from orion.core.io.database.pickleddb import PickledDB
  from orion.storage.legacy import Legacy
label_desc: Use image node_id 5 for calling a global function with example usage: upgrade_documents(storage) without return types