How to use the strapi-utils.knex function in strapi-utils

To help you get started, we’ve selected a few strapi-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strapi / strapi / packages / strapi / bin / strapi-migrate-run.js View on Github external
// Pass the original CLI arguments down to the generator.
  const cliArguments = Array.prototype.slice.call(arguments);

  // Build initial scope.
  const scope = {
    rootPath: process.cwd(),
    strapiRoot: path.resolve(__dirname, '..'),
    args: cliArguments,
    environment: process.NODE_ENV || 'development'
  };

  // Save the first argument as the name of the connection.
  scope.connection = cliArguments[0];

  // Make sure the connection is valid.
  knex(scope);

  // Run the migration.
  scope.db.migrate.latest()
    .then(() => {
      return scope.db.seed.run();
    })
    .then(() => {
      logger.info('Migration successfully made for the `' + scope.connection + '` connection!');
      process.exit(0);
    });
};
github strapi / strapi / packages / strapi / bin / strapi-migrate-rollback.js View on Github external
// Pass the original CLI arguments down to the generator.
  const cliArguments = Array.prototype.slice.call(arguments);

  // Build initial scope.
  const scope = {
    rootPath: process.cwd(),
    strapiRoot: path.resolve(__dirname, '..'),
    args: cliArguments,
    environment: process.NODE_ENV || 'development'
  };

  // Save the first argument as the name of the connection.
  scope.connection = cliArguments[0];

  // Make sure the connection is valid.
  knex(scope);

  // Run the rollback.
  scope.db.migrate.rollback()
    .then(function () {
      logger.info('Rollback successfully made for the `' + scope.connection + '` connection!');
      process.exit(0);
    });
};
github strapi / strapi / packages / strapi / bin / strapi-migrate-make.js View on Github external
const cliArguments = Array.prototype.slice.call(arguments);

  // Build initial scope.
  const scope = {
    rootPath: process.cwd(),
    strapiRoot: path.resolve(__dirname, '..'),
    generatorType: 'migrations',
    args: cliArguments,
    environment: process.NODE_ENV || 'development'
  };

  // Save the first argument as the name of the connection.
  scope.connection = cliArguments[0];

  // Make sure the connection is valid.
  knex(scope);

  // Return the scope and the response (`error` or `success`).
  return generate(scope, {

    // Log and exit the REPL in case there is an error
    // while we were trying to generate the migration files.
    error: function returnError(err) {
      logger.error(err);
      process.exit(1);
    },

    // Simply, log and exit the REPL in case of success.
    success: function returnSuccess() {
      logger.info('Migration file successfully generated at `' + path.resolve(scope.rootPath, 'data', 'migrations', scope.connection) + '`.');
      logger.info('Seed file created at `' + path.resolve(scope.rootPath, 'data', 'seeds', scope.connection) + '`.');
      logger.warn('This migration has been automatically generated.');
github strapi / strapi / packages / strapi / bin / strapi-migrate-rollback.js View on Github external
// Pass the original CLI arguments down to the generator.
  const cliArguments = Array.prototype.slice.call(arguments);

  // Build initial scope.
  const scope = {
    rootPath: process.cwd(),
    strapiRoot: path.resolve(__dirname, '..'),
    args: cliArguments,
    environment: process.NODE_ENV || 'development'
  };

  // Save the first argument as the name of the connection.
  scope.connection = cliArguments[0];

  // Make sure the connection is valid.
  knex(scope);

  // Run the rollback.
  scope.db.migrate.rollback()
    .then(() => {
      logger.info('Rollback successfully made for the `' + scope.connection + '` connection!');
      process.exit(0);
    });
};
github strapi / strapi / packages / strapi / bin / strapi-migrate-run.js View on Github external
// Pass the original CLI arguments down to the generator.
  const cliArguments = Array.prototype.slice.call(arguments);

  // Build initial scope.
  const scope = {
    rootPath: process.cwd(),
    strapiRoot: path.resolve(__dirname, '..'),
    args: cliArguments,
    environment: process.NODE_ENV || 'development'
  };

  // Save the first argument as the name of the connection.
  scope.connection = cliArguments[0];

  // Make sure the connection is valid.
  knex(scope);

  // Run the migration.
  scope.db.migrate.latest()
    .then(function () {
      return scope.db.seed.run();
    })
    .then(function () {
      logger.info('Migration successfully made for the `' + scope.connection + '` connection!');
      process.exit(0);
    });
};