How to use contentful-migration - 10 common examples

To help you get started, we’ve selected a few contentful-migration 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 deluan / contentful-migrate / lib / run.js View on Github external
const message = [
        chalk.red.bold(`${e.message}\n`),
        chalk.red.bold('🚨  Migration unsuccessful')
      ].join('\n')
      console.log(message)
      process.exit(1)
    }
    console.log(e)
    process.exit(1)
  }
  if (parseResult.hasStepsValidationErrors()) {
    stepsError.default(parseResult.stepsValidationErrors)
    process.exit(1)
  }
  if (parseResult.hasPayloadValidationErrors()) {
    stepsError.default(parseResult.payloadValidationErrors)
    process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
    await writeErrorsToLog.default(parseResult.getRuntimeErrors(), errorsFile)
    process.exit(1)
  }
  await renderMigration.renderPlan(batches)
github deluan / contentful-migrate / lib / run.js View on Github external
try {
    parseResult = await migrationParser(migrationFunction)
  } catch (e) {
    if (e instanceof SpaceAccessError) {
      const message = [
        chalk.red.bold(`${e.message}\n`),
        chalk.red.bold('🚨  Migration unsuccessful')
      ].join('\n')
      console.log(message)
      process.exit(1)
    }
    console.log(e)
    process.exit(1)
  }
  if (parseResult.hasStepsValidationErrors()) {
    stepsError.default(parseResult.stepsValidationErrors)
    process.exit(1)
  }
  if (parseResult.hasPayloadValidationErrors()) {
    stepsError.default(parseResult.payloadValidationErrors)
    process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
github deluan / contentful-migrate / lib / run.js View on Github external
const run = async ({
  spaceId, environmentId, accessToken, dryRun, migrationFunction
}) => {
  const config = { spaceId, environmentId, accessToken }
  const clientConfig = Object.assign({
    application: `contentful-migrate/${version}`
  }, config)
  const client = createManagementClient(clientConfig)

  const makeRequest = (requestConfig) => {
    // eslint-disable-next-line no-param-reassign
    requestConfig.url = path.join(config.spaceId, 'environments', environmentId, requestConfig.url)
    return client.rawRequest(requestConfig)
  }
  const migrationParser = migrationParser1.default(makeRequest, clientConfig)
  let parseResult
  try {
    parseResult = await migrationParser(migrationFunction)
  } catch (e) {
    if (e instanceof SpaceAccessError) {
      const message = [
        chalk.red.bold(`${e.message}\n`),
        chalk.red.bold('🚨  Migration unsuccessful')
      ].join('\n')
      console.log(message)
      process.exit(1)
    }
    console.log(e)
    process.exit(1)
  }
  if (parseResult.hasStepsValidationErrors()) {
github deluan / contentful-migrate / lib / run.js View on Github external
}
  if (parseResult.hasPayloadValidationErrors()) {
    stepsError.default(parseResult.payloadValidationErrors)
    process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
    await writeErrorsToLog.default(parseResult.getRuntimeErrors(), errorsFile)
    process.exit(1)
  }
  await renderMigration.renderPlan(batches)
  const serverErrorsWritten = []
  const tasks = batches.map((batch) => {
    return {
      title: batch.intent.toPlanMessage().heading,
      task: () => new Listr([
        {
          title: 'Making requests',
          task: async (_ctx, task) => {
            // TODO: We wanted to make this an async interator
            // So we should not inspect the length but have a property for that
            const numRequests = batch.requests.length
            const requestErrors = []
            let requestsDone = 0
github contentful-labs / continous-delivery-environments-example / scripts / migrate.js View on Github external
);
    }
    const migrationsToRun = availableMigrations.slice(currentMigrationIndex + 1);
    const migrationOptions = {
      spaceId: SPACE_ID,
      environmentId: ENVIRONMENT_ID,
      accessToken: CMA_ACCESS_TOKEN,
      yes: true
    };

    // ---------------------------------------------------------------------------
    console.log('Run migrations and update version entry');
    while(migrationToRun = migrationsToRun.shift()) {
      const filePath = path.join(__dirname, '..', 'migrations', getFileOfVersion(migrationToRun));
      console.log(`Running ${filePath}`);
      await runMigration(Object.assign(migrationOptions, {
        filePath
      }));
      console.log(`${migrationToRun} succeeded`);

      storedVersionEntry.fields.version[defaultLocale] = migrationToRun;
      storedVersionEntry = await storedVersionEntry.update();
      storedVersionEntry = await storedVersionEntry.publish();

      console.log(`Updated version entry to ${migrationToRun}`);
    }

    // ---------------------------------------------------------------------------
    console.log('Checking if we need to update master alias');
    if (ENVIRONMENT_INPUT == 'master'){
      console.log(`Running on master.`);
      console.log(`Updating master alias.`);
github deluan / contentful-migrate / lib / run.js View on Github external
process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
    await writeErrorsToLog.default(parseResult.getRuntimeErrors(), errorsFile)
    process.exit(1)
  }
  await renderMigration.renderPlan(batches)
  const serverErrorsWritten = []
  const tasks = batches.map((batch) => {
    return {
      title: batch.intent.toPlanMessage().heading,
      task: () => new Listr([
        {
          title: 'Making requests',
          task: async (_ctx, task) => {
            // TODO: We wanted to make this an async interator
            // So we should not inspect the length but have a property for that
            const numRequests = batch.requests.length
            const requestErrors = []
            let requestsDone = 0
            for (const request of batch.requests) {
              requestsDone += 1
github deluan / contentful-migrate / lib / run.js View on Github external
process.exit(1)
  }
  if (parseResult.hasPayloadValidationErrors()) {
    stepsError.default(parseResult.payloadValidationErrors)
    process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
    await writeErrorsToLog.default(parseResult.getRuntimeErrors(), errorsFile)
    process.exit(1)
  }
  await renderMigration.renderPlan(batches)
  const serverErrorsWritten = []
  const tasks = batches.map((batch) => {
    return {
      title: batch.intent.toPlanMessage().heading,
      task: () => new Listr([
        {
          title: 'Making requests',
          task: async (_ctx, task) => {
            // TODO: We wanted to make this an async interator
            // So we should not inspect the length but have a property for that
            const numRequests = batch.requests.length
            const requestErrors = []
github deluan / contentful-migrate / lib / run.js View on Github external
process.exit(1)
  }
  if (parseResult.hasStepsValidationErrors()) {
    stepsError.default(parseResult.stepsValidationErrors)
    process.exit(1)
  }
  if (parseResult.hasPayloadValidationErrors()) {
    stepsError.default(parseResult.payloadValidationErrors)
    process.exit(1)
  }
  // const migrationName = path.basename(argv.filePath, '.js');
  // const errorsFile = path.join(process.cwd(), `errors-${migrationName}-${Date.now()}.log`);
  const errorsFile = path.join(process.cwd(), `errors-${Date.now()}.log`)
  const { batches } = parseResult
  if (parseResult.hasValidationErrors()) {
    renderMigration.renderValidationErrors(batches)
    process.exit(1)
  }
  if (parseResult.hasRuntimeErrors()) {
    renderMigration.renderRuntimeErrors(batches, errorsFile)
    await writeErrorsToLog.default(parseResult.getRuntimeErrors(), errorsFile)
    process.exit(1)
  }
  await renderMigration.renderPlan(batches)
  const serverErrorsWritten = []
  const tasks = batches.map((batch) => {
    return {
      title: batch.intent.toPlanMessage().heading,
      task: () => new Listr([
        {
          title: 'Making requests',
          task: async (_ctx, task) => {
github contentful / contentful-cli / lib / cmds / space_cmds / migration.js View on Github external
const options = {
    ...argv,
    spaceId: activeSpaceId,
    managementApplication,
    managementFeature,
    accessToken: managementToken,
    environmentId: activeEnvironmentId
  }
  if (proxy) {
    // contentful-import and contentful-export
    // expect a string for the proxy config
    // and create agents from it
    options.proxy = proxyObjectToString(proxy)
    options.rawProxy = rawProxy
  }
  return runMigration(options)
}
github deluan / contentful-migrate / lib / run.js View on Github external
const run = async ({
  spaceId, environmentId, accessToken, dryRun, migrationFunction
}) => {
  const config = { spaceId, environmentId, accessToken }
  const clientConfig = Object.assign({
    application: `contentful-migrate/${version}`
  }, config)
  const client = createManagementClient(clientConfig)

  const makeRequest = (requestConfig) => {
    // eslint-disable-next-line no-param-reassign
    requestConfig.url = path.join(config.spaceId, 'environments', environmentId, requestConfig.url)
    return client.rawRequest(requestConfig)
  }
  const migrationParser = migrationParser1.default(makeRequest, clientConfig)
  let parseResult
  try {
    parseResult = await migrationParser(migrationFunction)
  } catch (e) {
    if (e instanceof SpaceAccessError) {
      const message = [
        chalk.red.bold(`${e.message}\n`),
        chalk.red.bold('🚨  Migration unsuccessful')
      ].join('\n')