<commit_before>
module.exports.up = function () {
  require('util.promisify/shim')();
  const log = require('migrate/lib/log');
  const path = require('path');
  const fs = require('fs');
  const util = require('util');

  const writeFile = util.promisify(fs.writeFile);
  const copyFile = util.promisify(fs.copyFile);
  const access = util.promisify(fs.access);

  let modelPath;
  if (process.env.EG_CONFIG_DIR) {
    log('modelPath', 'EG_CONFIG_DIR set.');
    modelPath = path.join(process.env.EG_CONFIG_DIR, 'models');
  } else {
    log('modelPath', 'EG_CONFIG_DIR not set. Guessing the config dir…');
    modelPath = path.join(__dirname, '../../../', 'config/models');
  }

  log('modelPath', `set to: ${modelPath}`);

  return access(modelPath)
    .then(() => Promise.all(
      [copyFile(path.join(__dirname, '../lib/config/models/credentials.json'), path.join(modelPath, 'credentials.json'))]
        .concat(['users', 'applications']
          .map(model => ({ modelName: model, modelDefinition: require(path.join(modelPath, path.format({ name: model, ext: '.js' }))) }))
          .map(({ modelName, modelDefinition }) => {
            const newModel = {
              $id: `http://express-gateway.io/models/${modelName}.json`,
              type: 'object',
              properties: {},
              required: []
            };

            if (modelDefinition.properties) {
              Object.entries(modelDefinition.properties).forEach(([propertyName, propertyValue]) => {
                newModel.properties[propertyName] = {
                  type: 'string'
                };

                if (propertyName === 'email') {
                  newModel.properties[propertyName].format = 'email';
                }

                if (propertyName === 'redirectUri') {
                  newModel.properties[propertyName].format = 'uri';
                }

                if (propertyValue.isRequired) {
                  newModel.required.push(propertyName);
                }
              });
            }

            if (modelName === 'users') {
              newModel.required.push('username');
              newModel.properties.username = {
                type: 'string'
              };
            }

            return { modelName, modelDefinition: newModel };
          }).map(({ modelName, modelDefinition }) =>
            writeFile(
              path.join(modelPath, path.format({ name: modelName, ext: '.json' })),
              JSON.stringify(modelDefinition, null, 2)
            )
          )
        )
    ).then(() => Promise.resolve()));
};

module.exports.down = function (next) {
  throw new Error('I\'m sorry, I can\'t make that happen');
};
<commit_msg>Tell the user what to do after the migration<commit_after>
module.exports.up = function () {
  require('util.promisify/shim')();
  const log = require('migrate/lib/log');
  const path = require('path');
  const fs = require('fs');
  const util = require('util');

  const writeFile = util.promisify(fs.writeFile);
  const copyFile = util.promisify(fs.copyFile);
  const access = util.promisify(fs.access);

  let modelPath;
  if (process.env.EG_CONFIG_DIR) {
    log('modelPath', 'EG_CONFIG_DIR set.');
    modelPath = path.join(process.env.EG_CONFIG_DIR, 'models');
  } else {
    log('modelPath', 'EG_CONFIG_DIR not set. Guessing the config dir…');
    modelPath = path.join(__dirname, '../../../', 'config/models');
  }

  log('modelPath', `set to: ${modelPath}`);

  return access(modelPath)
    .then(() => Promise.all(
      [copyFile(path.join(__dirname, '../lib/config/models/credentials.json'), path.join(modelPath, 'credentials.json'))]
        .concat(['users', 'applications']
          .map(model => ({ modelName: model, modelDefinition: require(path.join(modelPath, path.format({ name: model, ext: '.js' }))) }))
          .map(({ modelName, modelDefinition }) => {
            const newModel = {
              $id: `http://express-gateway.io/models/${modelName}.json`,
              type: 'object',
              properties: {},
              required: []
            };

            if (modelDefinition.properties) {
              Object.entries(modelDefinition.properties).forEach(([propertyName, propertyValue]) => {
                newModel.properties[propertyName] = {
                  type: 'string'
                };

                if (propertyName === 'email') {
                  newModel.properties[propertyName].format = 'email';
                }

                if (propertyName === 'redirectUri') {
                  newModel.properties[propertyName].format = 'uri';
                }

                if (propertyValue.isRequired) {
                  newModel.required.push(propertyName);
                }
              });
            }

            if (modelName === 'users') {
              newModel.required.push('username');
              newModel.properties.username = {
                type: 'string'
              };
            }

            return { modelName, modelDefinition: newModel };
          }).map(({ modelName, modelDefinition }) =>
            writeFile(
              path.join(modelPath, path.format({ name: modelName, ext: '.json' })),
              JSON.stringify(modelDefinition, null, 2)
            )
          )
        )
    ).then(() => {
      log('Complete', 'You can now remove the old .js files');
      Promise.resolve();
    }));
};

module.exports.down = function (next) {
  throw new Error('I\'m sorry, I can\'t make that happen');
};

{'fraction_non_alphanumeric': 0.1552693633230546, 'fraction_numerical': 0.00036277888626881915, 'mean_word_length': 2.0213698630136987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142549', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1508, 'n_words': 297}