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 #
- Dry run:
startwithoutapply. Keep thefingerprint. - Review the
changes, and get a human's approval when needed (below). - Apply: the same request, with
apply: trueand thefingerprintin the body. Onplan_changed(412), go back to 1: the plan is no longer the one reviewed. IfcopyRequiredisfalse,applied: truemeans the model is live; follow the existing documents' reindex withstatusand the sameindexandcollectionuntil itsstateisdone, and onfailedfix the refused documents it lists. - Follow the job (
job.jobIdin the response):statuswith thatjobIduntil itsphaseisdoneoraborted, or subscribe (statuswithsubscribe: true, WebSocket or MQTT). - On
aborted, readlastErrorandfailures(jobId), fix the data or the model, and start again from 1. - 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
inPlaceisfalse: it copies the collection and closes its writes for the copy time (see Planning); afieldRemovedchange 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 #
| Error | Retry? |
|---|---|
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 5xx | Yes, 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.