code: def upgrade_pickledb(database):
      """Update pickledb specific db scheme."""
  
      # pylint: disable=protected-access
      def upgrade_state(self, state):
          """Set state while ensuring backward compatibility"""
          self._documents = state["_documents"]
  
          # if indexes are from <=v0.1.6
          if state["_indexes"] and isinstance(
              next(iter(state["_indexes"].keys())), tuple
          ):
              self._indexes = {}
              for keys, values in state["_indexes"].items():
                  if isinstance(keys, str):
                      self._indexes[keys] = values
                  # Convert keys that were registered with old index signature
                  else:
                      keys = [(key, None) for key in keys]
                      self.create_index(keys, unique=True)
          else:
              self._indexes = state["_indexes"]
  
      old_setstate = getattr(EphemeralCollection, "__setstate__", None)
      EphemeralCollection.__setstate__ = upgrade_state
  
      document = database.read("experiments", {})[0]
      # One document update is enough to fix all collections
      database.write(
          "experiments", document, query={"_id": document["_id"]}
      )
  
      if old_setstate is not None:
          EphemeralCollection.__setstate__ = old_setstate
      else:
          del EphemeralCollection.__setstate__
  
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 9 for calling a global function with example usage: upgrade_pickledb(database) without return types