Factorio Auxiliary DocsVersion 2.0.55

Migrations

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 .lua or .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). All JSON migrations are applied before any Lua migrations. 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

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 storage stay valid. Changing an entity's type will however result in a new unit_number and an invalid reference in storage.

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.

JSON Example

The "wall" entity and item being renamed to "stone-wall":

{
  "entity":
  [
    ["wall", "stone-wall"]
  ],
  "item":
  [
    ["wall", "stone-wall"]
  ]
}

Available for migration

The following prototype types are available for migration:

  • "custom-input"
  • "equipment-grid"
  • "entity"
  • "item"
  • "tile"
  • "decorative"
  • "recipe-category"
  • "item-group"
  • "item-subgroup"
  • "recipe"
  • "fluid"
  • "ammo-category"
  • "fuel-category"
  • "resource-category"
  • "technology"
  • "noise-layer"
  • "noise-expression"
  • "autoplace-control"
  • "equipment"
  • "damage-type"
  • "virtual-signal"
  • "achievement"
  • "module-category"
  • "equipment-category"
  • "mod-setting"
  • "trivial-smoke"
  • "shortcut"

Lua migrations

Lua migrations allow altering the loaded game state before it starts running. The global game object is available in Lua migrations, which is how the game state can be modified.

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 anymore.