docs: def _migrate_ledger(data_directory,
                      old_ledger_file, new_ledger_file,
                      serializer: MappingSerializer = None):
      """
      Test for the directory, open old and new ledger, migrate data, rename directories
      """
  
      # we should have ChunkedFileStorage implementation of the Ledger
      if not os.path.isdir(os.path.join(data_directory, old_ledger_file)):
          msg = 'Could not find directory {} for migration.'.format(
              old_ledger_file)
          logger.error(msg)
          raise Exception(msg)
  
      # open the current ledger using the specified serializer
      old_txn_log_store = ChunkedFileStore(data_directory,
                                           old_ledger_file,
                                           isLineNoKey=True,
                                           storeContentHash=False)
      logger.info("Old ledger folder: {}, {}".format(
          data_directory, old_ledger_file))
      old_ledger = Ledger(CompactMerkleTree(),
                          dataDir=data_directory,
                          txn_serializer=serializer,
                          hash_serializer=serializer,
                          fileName=old_ledger_file,
                          transactionLogStore=old_txn_log_store)
      logger.info("old size for {}: {}".format(
          old_ledger_file, str(old_ledger.size)))
  
      # open the new ledger with new serialization
      new_ledger_file_backup = new_ledger_file + "_new"
      logger.info("New ledger folder: {}, {}".format(
          data_directory, new_ledger_file_backup))
      new_ledger = Ledger(CompactMerkleTree(),
                          dataDir=data_directory,
                          fileName=new_ledger_file_backup)
  
      # add all txns into the new ledger
      for _, txn in old_ledger.getAllTxn():
          if txn[TXN_TYPE] == SCHEMA:
              if DATA in txn:
                  txn[DATA] = json.loads(txn[DATA])
          if txn[TXN_TYPE] == CLAIM_DEF:
              if DATA in txn:
                  txn[DATA] = json.loads(txn[DATA])
          new_ledger.add(txn)
      logger.info("new size for {}: {}".format(
          new_ledger_file, str(new_ledger.size)))
  
      old_ledger.stop()
      new_ledger.stop()
  
      # now that everything succeeded, remove the old files and move the new
      # files into place
      shutil.rmtree(
          os.path.join(data_directory, old_ledger_file))
      os.rename(
          os.path.join(data_directory, new_ledger_file_backup),
          os.path.join(data_directory, new_ledger_file))
  
      logger.info("Final new ledger folder: {}".format(
          os.path.join(data_directory, new_ledger_file)))