export default function () {
  logger.info('Updating statement client ids...');
  Client.find({}).lean()
    .then(docs =>
      Promise.mapSeries(docs, doc => migrateDoc(doc))
    )
    .then(logSuccess, logError)
    .then(() => process.exit());
}
export default function () {
  logger.info('Updating clients authorities...');
  Client.find({}).lean()
    .then(docs =>
      Promise.all(docs.map((doc) => {
        const hasConstructor = doc.authority !== undefined && doc.authority !== null;
        const shouldMigrate = hasConstructor && doc.authority.constructor === Object;

        // Because the Client model currently parses the authority and returns an Object.
        // It will always migrate. So keep calm and carry on migrating.
        if (shouldMigrate) return migrateDoc(doc);

        logger.debug(`Not migrating ${doc.title}`);
        return Promise.resolve();
      }))
    )
    .then(logSuccess, logError)
    .then(() => process.exit());
}