Migrations are a way to fix up a save file which was used in an older version of the game or mod. They have to be either
.json files in the mod's
"migrations" folder, depending on their purpose. They are typically used to change the type of a prototype or correct research and recipe states after changes.
The sequence in which migrations are executed is sorted by mod order first, migration file name second (using lexicographical comparison). Each save file remembers (by name) which migrations from which mods have been applied and will not apply the same migration twice. When adding a mod to an existing save, all migration scripts for that mod will be run.
JSON migrations allow changing one prototype into another. This is typically used to rename a prototype. Note that when an entity prototype's name is changed, it retains its previous unit_number and any references to it saved in global stay valid. Changing an entity's type will however result in a new
unit_number and an invalid reference in
Ghost entities are not always able to be migrated, in which case they are removed instead. Reasons for this include a change in the type of the entity, or the entity becoming unbuildable.
JSON migrations are applied as a map is being loaded. Multiple such migrations can be applied at once. All JSON migrations are applied before any Lua migrations.
The following prototype types are available for migration:
Lua migrations allow altering the loaded game state. Typically this is done when recipes or technologies have changed. The game resets recipes and technologies any time mods, prototypes, or startup settings change, so this does not need to be done by migration scripts.