<commit_before>var _ = require('lodash');

module.exports = function (sails) {
  return {
    configure: function () {

    },
    initialize: function (next) {

      sails.after('hook:orm:loaded', function () {
        var models = _.filter(sails.controllers, function (controller, name) {
          var model = sails.models[name];
          return model && model.globalId && model.identity;
        });

        Model.count()
          .then(function (count) {
            if (count < models.length) {
              sails.log('Expecting', models.length, 'models, found', count);
              sails.log('Installing fixtures');
              initializeFixtures(next);
            }
            else {
              next();
            }
          })
          .catch(function (error) {
            sails.log.error(error);
            next(error);
          });
      });
    }
  };
};

/**
 * Install the application. Sets up default Roles, Users, Models, and
 * Permissions, and creates an admin user.
 */
function initializeFixtures (next) {
  var roles, models;

  sails.log('Creating models');
  require('../../../config/fixtures/model').createModels()
    .then(function (_models) {
      models = _models;
      return require('../../../config/fixtures/role').create();
    })
    .then(function (_roles) {
      roles = _roles;
      sails.log('Creating permissions');
      return require('../../../config/fixtures/permission').create(roles, models);
    })
    .then(function (permissions) {
      var model = _.find(models, { name: 'User' });
      sails.log('Creating admin user');
      return require('../../../config/fixtures/user').create(roles, model, function (err, user) {
        if (err) return next(err);
        user.owner = user.id;
        user.save().then(function (user) {
          next();
        });
      });
    })
    .catch(function (error) {
      sails.log.error(error);
      next(error);
    });
}
<commit_msg>attempt to bypass waterline#630 issue<commit_after>var _ = require('lodash');

module.exports = function (sails) {
  return {
    configure: function () {

    },
    initialize: function (next) {

      sails.after('hook:orm:loaded', function () {
        var models = _.filter(sails.controllers, function (controller, name) {
          var model = sails.models[name];
          return model && model.globalId && model.identity;
        });

        Model.count()
          .then(function (count) {
            if (count < models.length) {
              sails.log('Expecting', models.length, 'models, found', count);
              sails.log('Installing fixtures');
              initializeFixtures(next);
            }
            else {
              next();
            }
          })
          .catch(function (error) {
            // FIXME https://github.com/balderdashy/waterline/issues/630
            sails.log.warn(error);
            initializeFixtures(next);
          });
      });
    }
  };
};

/**
 * Install the application. Sets up default Roles, Users, Models, and
 * Permissions, and creates an admin user.
 */
function initializeFixtures (next) {
  var roles, models;

  sails.log('Creating models');
  require('../../../config/fixtures/model').createModels()
    .then(function (_models) {
      models = _models;
      return require('../../../config/fixtures/role').create();
    })
    .then(function (_roles) {
      roles = _roles;
      sails.log('Creating permissions');
      return require('../../../config/fixtures/permission').create(roles, models);
    })
    .then(function (permissions) {
      var model = _.find(models, { name: 'User' });
      sails.log('Creating admin user');
      return require('../../../config/fixtures/user').create(roles, model, function (err, user) {
        if (err) return next(err);
        user.owner = user.id;
        user.save().then(function (user) {
          next();
        });
      });
    })
    .catch(function (error) {
      sails.log.error(error);
      next(error);
    });
}

{'fraction_non_alphanumeric': 0.16296481157973547, 'fraction_numerical': 0.0014973795857249812, 'mean_word_length': 2.015801354401806, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4872066', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1137, 'n_words': 236}