load().
How schema versioning works
When you set aversion number on the Configurate constructor, the plugin stores a __configurate_version__ key alongside your data on every write. On load, it compares the stored version to the current version. If the stored version is lower, the plugin runs the applicable migration steps in order, then auto-saves the migrated data back to storage.
The process is entirely automatic — you define the steps; the plugin handles when and in what order they run.
The version field
Passversion (a non-negative integer) to the Configurate constructor:
create, save, or patch call writes __configurate_version__: 2 into the stored file. On load, the plugin reads this value and uses it to determine which migrations, if any, need to run.
Files written before you added
version to the constructor are treated as version 0. This means your first set of migrations should use version: 0 as the “from” version.MigrationStep
AMigrationStep describes a single schema transform:
migrations option. Steps are applied in ascending order of version whenever the loaded data’s stored version is less than the current version.
Auto-save after migration
After running migrations, the plugin automatically saves the migrated data back to storage. This means the nextload() will find already-migrated data and skip the migration steps entirely. If the auto-save fails (for example, due to a permissions error), the failure is logged as a warning but does not surface to the caller — the migrated data is still returned for the current session.
Step-by-step example
Starting state
Your app is at version 0 with the following schema:app.json):
Migration 1: adding a new field
In version 1, you add alanguage field. Existing files won’t have it, so the migration provides a default value.
app.json with __configurate_version__: 0 (or no version key), the plugin runs the version: 0 step, producing:
Migration 2: renaming a field
In version 2, you renamefontSize to textSize. The migration copies the old value and removes the old key.
The version key in stored data
The plugin stores the version under the key"__configurate_version__" in the config object. You can read this key directly from raw config data if you need it for debugging or logging:
This key is managed internally by the plugin. Do not set or delete it manually — it is written automatically on every
create, save, patch, or migration auto-save when version is set on the constructor.Best practices
Start versioning early
Add
version: 0 to the constructor even before you have any migrations. This ensures the version key is present in all new files from the start, making future migrations easier to reason about.Keep migration functions pure
Each
up function receives old data and must return new data. Do not produce side effects (API calls, storage writes) inside a migration step — the plugin manages persistence.Never modify or remove a past migration
Once a migration has shipped to users, treat it as immutable. Existing users may be at any version — removing a step leaves files stranded at an intermediate version. Add new steps for new changes.