RoomDefinition: version property

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The version property of a room definition is the version of the room’s room state format. A build that changes the shape of room state increments it and adds a migration to the new version.

Value

A number. Defaults to 1.

Description

Room state is saved with the version of the build that wrote it. When a room wakes with room state at an older version, it runs through each migration in turn, from the saved version to this one. A missing migration stops the room with a reason that says which.

Fields the build declares and the room state lacks get their defaults, so adding a field or a kind doesn’t need a new version. Renaming, removing or changing the type of one does: a kind or field the build doesn’t declare, or a value of the wrong type, stops the room.

There are no down migrations. irt build records version in the build, and when a rollback makes an older build live, a room whose room state is at a newer version wakes from the room state kept from before its migration; see New builds.

Each room type has its own version and migrations.

Examples

Version 2 of a room

// garden.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";

// Version 1 stored water as "u8"; version 2 stores it as "f32".
const Plant = entity("plant", { water: "f32" });

export default defineRoom({
  schema: defineSchema({ entities: [Plant] }),
  version: 2,
  migrations: {
    2: (data) => ({
      ...data,
      entities: data.entities.map((e) => (e.kind === "plant" ? { ...e, values: { water: Number(e.values.water) / 255 } } : e)),
    }),
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
version0.10.10.10.1