This plugin is part of the Kuzzle Enterprise Plan. If you are interested, please contact us.

Automation #

The API can be driven by a script, a CI job or an AI agent. This page gives the sequence that never applies a plan nobody reviewed, the steps that need a human's approval, and which errors to retry.

Exported types #

The package exports the types of what the API returns: MigrationPlan (what start returns), MappingChange, ChangeKind, MigrationJobView (a job in start, status and progress messages), JobPhase, ReindexView (reindex in status), ReindexState, ReindexFailure, the configuration (MappingMigrationConfig), and the error ids (MAPPING_MIGRATION_ERROR_IDS, type MappingMigrationErrorId).

import type {
  MigrationJobView,
  MigrationPlan,
} from "@kuzzleio/plugin-mapping-migration";

The routes, their arguments and error ids are also in the application's OpenAPI definition (GET /_openapi?scope=app).

Safe sequence #

  1. Dry run: start without apply. Keep the fingerprint.
  2. Review the changes, and get a human's approval when needed (below).
  3. Apply: the same request, with apply: true and the fingerprint in the body. On plan_changed (412), go back to 1: the plan is no longer the one reviewed. If copyRequired is false, applied: true means the model is live; follow the existing documents' reindex with status and the same index and collection until its state is done, and on failed fix the refused documents it lists.
  4. Follow the job (job.jobId in the response): status with that jobId until its phase is done or aborted, or subscribe (status with subscribe: true, WebSocket or MQTT).
  5. On aborted, read lastError and failures (jobId), fix the data or the model, and start again from 1.
  6. Purge (jobId) the archive once the new model is checked. It deletes the old values for good.

Ask a human first #

Before:

  • applying a plan with any change where inPlace is false: it copies the collection and closes its writes for the copy time (see Planning); a fieldRemoved change also drops the field's values from the new collection;
  • allowFailures: true: the documents that fail are dropped from the collection (kept in the archive only);
  • purge: the archive and the failed documents are deleted for good.

New fields only (every change inPlace: true) are applied at once with writes open, but read the in-place reindex failures first.

Polling #

Every 2 to 5 seconds is enough. Subscribing gets one message per phase change and at most one every 2 seconds (progressInterval) without polling.

Errors to retry #

ErrorRetry?
job_running (412)Yes, once the running job ends (status): one migration at a time
services.storage.collection_locked (503)Yes, later: a write on a collection being copied, or a collection locked by someone else
plan_changed (412)Not as is: dry run again, review again
not_enough_disk_space (412)After freeing space (purge old archives, with a human's approval)
Network errors, Kuzzle's 5xxYes, with a growing delay; check status first, the action may have gone through
invalid_* (400), forbidden (403), unknown_job (404), unsupported_engine (412), progress_* (403)No: fix the request, the rights or the platform

A job never needs a retry of its own: a transient error inside it is retried by the plugin, and a node that stops is replaced by another one. The full list is in Errors.