Factorio Auxiliary DocsVersion 2.0.26

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

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

Example

When the rail-chain-signal and additional tank ammo were added to the game, existing technology was changed so it would unlock the recipes for these. In any particular game, those technologies could potentially already have been researched, leaving these new items disabled forever. This Lua migration prevents this:

for index, force in pairs(game.forces) do
  local technologies = force.technologies
  local recipes = force.recipes

  recipes["rail-chain-signal"].enabled = technologies["rail-signals"].researched

  if technologies["tank"].researched then
    recipes["explosive-cannon-shell"].enabled = true
  end
end