<commit_before>import { each, has } from 'lodash';
require("babel-polyfill");

/**
 * A migration runner.
 */
export default class MigrationRunner {
  /**
   * Creates a new Migration runner.
   *
   * @param {MigrationLogger} logger A logger instance.
   * @param {KbnServer.server} server A server instance.
   */
  constructor(server, logger) {
    this._server = server;
    this._logger = logger;
  }

  /**
   * Gets migration classes from plugins that expose the `getMigrations`
   * method and instantiates them.
   *
   * The runner passes a configuration object to the migration constructor which
   * contains the following attributes:
   *
   * - index: the name of the Kibi index.
   * - client: an instance of an Elasticsearch client configured to connect to the Kibi cluster.
   *
   * Each migration must expose the following:
   *
   * - `count`: returns the number of objects that can be upgraded.
   * - `upgrade`: runs the migration and returns the number of upgraded
   *              objects.
   *
   * Migrations are cached and executed in the order returned by each plugin;
   * the plugins are scanned in the order returned by the PluginCollection in
   * server.plugins.
   *
   * Currently it is not possible to defined dependencies between migrations
   * declared in different plugins, so be careful about modifying objects
   * shared by more than one plugin.
   */
  getMigrations() {
    if (this._migrations) {
      return this._migrations;
    }
    const migrations = [];
    each(this._server.plugins, (plugin) => {
      if (has(plugin, 'getMigrations')) {
        for (const Migration of plugin.getMigrations()) {
          const configuration = {
            config: this._server.config(),
            client: this._server.plugins.elasticsearch.getCluster("admin").getClient(),
            logger: this._logger,
            server: this._server
          };
          const migration = new Migration(configuration);
          migrations.push(migration);
        }
      }
    });
    this._migrations = migrations;
    return this._migrations;
  }

  /**
   * Counts objects that can be upgraded by executing the `count` method of each migration returned by the installed plugins.
   *
   * @returns The number of objects that can be upgraded.<commit_msg>Put core migrations last<commit_after>import { each, has } from 'lodash';
require("babel-polyfill");

/**
 * A migration runner.
 */
export default class MigrationRunner {
  /**
   * Creates a new Migration runner.
   *
   * @param {MigrationLogger} logger A logger instance.
   * @param {KbnServer.server} server A server instance.
   */
  constructor(server, logger) {
    this._server = server;
    this._logger = logger;
  }

  /**
   * Gets migration classes from plugins that expose the `getMigrations`
   * method and instantiates them.
   *
   * The runner passes a configuration object to the migration constructor which
   * contains the following attributes:
   *
   * - index: the name of the Kibi index.
   * - client: an instance of an Elasticsearch client configured to connect to the Kibi cluster.
   *
   * Each migration must expose the following:
   *
   * - `count`: returns the number of objects that can be upgraded.
   * - `upgrade`: runs the migration and returns the number of upgraded
   *              objects.
   *
   * Migrations are cached and executed in the order returned by each plugin;
   * the plugins are scanned in the order returned by the PluginCollection in
   * server.plugins.
   *
   * Currently it is not possible to defined dependencies between migrations
   * declared in different plugins, so be careful about modifying objects
   * shared by more than one plugin.
   */
  getMigrations() {
    if (this._migrations) {
      return this._migrations;
    }
    const migrations = [];
    const coreMigrations = [];
    each(this._server.plugins, (plugin) => {
      if (has(plugin, 'getMigrations')) {
        for (const Migration of plugin.getMigrations()) {
          const configuration = {
            config: this._server.config(),
            client: this._server.plugins.elasticsearch.getCluster("admin").getClient(),
            logger: this._logger,
            server: this._server
          };
          const migration = new Migration(configuration);
          if (plugin.name === 'siren_investigate') {
            migrations.push(coreMigrations);
          } else {
            migrations.push(migration);
          }
        }
      }
    });
    this._migrations = migrations.concat(coreMigrations);
    return this._migrations;
  }

  /**
   * Counts objects that can be upgraded by executing the `count` method of each migration returned by the installed plugins.
   *
   * @returns The number of objects that can be upgraded.
{'fraction_non_alphanumeric': 0.088800668616799, 'fraction_numerical': 0.0, 'mean_word_length': 2.6514111365369946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5197476', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1248, 'n_words': 463}