Skip to main content

Data Upgrades

Some model changes leave existing data in a shape the new model no longer reads. A data upgrade is how you, the model builder, declare what has to happen to the stored data because of such a change. You write it next to the model change; the platform runs every upgrade a tenant has not had yet, once.

When you need one​

A data upgrade is needed when a change to the model leaves stored data in a shape the new model no longer reads. Currently the supported changes concern relations:

  • A relation moved to another declaring class. For example the relations to rulebooks.businessUnit and rulebooks.responsible were declared on an EXTENSION rulebooks.dossier and now sit on the ABSTRACT class rulebooks.rulebook. The links of existing objects are still stored under the old class, so the new model finds nothing: forward links may still resolve, but the inverse lists (all rulebooks of a business unit) are empty.
  • A relation was reversed. rulebooks.businessUnit used to link to its persons; now each commons.person links to its business units. The links have to be stored on the other side.

Reloading the model or rebuilding the database does not repair either case: a rebuild takes the stored data as it is and does not reinterpret it.

You do not need a data upgrade for additive changes (a new class, a new field, a new relation) or for changes the platform converts itself, such as definition format versions.

The supported actions are described per kind of change; more will follow.

ChangePage
Relations: move, remove or reverseRelation actions
Classes: remove a class from objectsClass actions

Declaring upgrades​

Data upgrades are declared in a dataUpgrades array on a class file, typically a dedicated CONFIG class (like scripts and archetypes):

{
"version": 1,
"class": "rulebooks.upgrades",
"kind": "CONFIG",
"dataUpgrades": [
{
"version": 1,
"description": "Relations of commons.dossier moved to rulebooks.rulebook",
"actions": [
{
"action": "MOVE_RELATION",
"when": { "class": "rulebooks.rulebook" },
"relation": { "from": "commons.dossier", "to": "rulebooks.businessUnit" },
"becomes": { "from": "rulebooks.rulebook" }
},
{
"action": "REMOVE_RELATION",
"relation": { "from": "commons.dossier", "to": "rulebooks.businessUnit" }
}
]
}
]
}
PropertyTypeDescription
versionintegerPositive and unique within the namespace. The top-level version of the file stays the definition format version; this one numbers the upgrade.
descriptionstringWhat the upgrade does and why. Shown in the upgrade history.
actionsAction[]At least one. Run in the order written.

One section per namespace​

A model is layered: commons, on top of it rulebooks, and possibly a client namespace on top of that. Each namespace has its own builder and moves at its own pace, so each namespace numbers its upgrades independently: moving a relation in commons is commons upgrade n, whatever the namespaces built on it have numbered. The namespace of an upgrade is the namespace of the class that declares it (rulebooks.upgrades → rulebooks).

  • A namespace has one dataUpgrades section, holding all its upgrades, in any module.
  • That section sits on a class that is loaded without selecting a module (reachable from the index class through imports, relations or inheritance). Every tenant then has it, whichever modules it selected.
  • An action may name classes of its own namespace and of the namespaces below it. Naming a commons class from rulebooks is fine, e.g. an EXTENSION of a commons class is a rulebooks change.

The platform refuses the model (and reports the problem with the file and path) when a namespace declares two sections, the section sits on a module-only class, a version is not positive or is used twice, an upgrade has no actions, or an action is malformed (see Relation actions).

The when precondition​

What makes an upgrade precise is the precondition, not the action. when is evaluated on the object before the upgrade, and the action only applies to objects for which it holds. It takes exactly one condition:

ConditionMeaning
{ "class": "rulebooks.rulebook" }The object has that class. An abstract ancestor or a role counts.
{ "notClass": "rulebooks.rulebook" }The opposite.

In the example above the dossiers that are rulebooks keep their business unit under the new declaring class (first action). On every other dossier the relation no longer exists in the model, and the second action drops it.

How actions run​

Actions work on the stored data and never consult the model. They run in the order written, each as its own pass over all objects of the tenant (system objects are left alone). So between two actions the data is half-upgraded by definition: after a first MOVE_RELATION a second relation still sits under its old class. An upgrade may therefore pass through states that the new model would not accept; that is fine and expected, because checking an intermediate state would refuse what the next action fixes.

Only afterwards are the objects the upgrades changed checked against the new model, and the result is reported (see Issues). A tenant that is several upgrades behind gets them in one run: all pending actions run in order, followed by one rebuild and one check, reported on the last upgrade record of the run.

Further rules:

  • Idempotent. A change that is already in place is skipped.
  • One bad object does not stop the run. A change that cannot be made is reported and skipped.
  • Order of upgrades. Per namespace in ascending version. Across namespaces, base first: commons, then rulebooks, then a client namespace on top. An upgrade of a namespace is written against the namespaces below it as they are after their own upgrades.
  • Classes outside the model. An action naming a class the tenant's model does not have is skipped for that tenant. Usually that is intended: the module of that class is not selected, so the tenant has no data of it, and a tenant that selects the module later does not rerun earlier upgrades. The platform only reports an informational notice when the model loads, so a class you removed or misspelled is skipped just as silently. REMOVE_CLASS is the exception for its own class, which is typically gone from the model.
  • New tenants start at the highest version of each namespace and run no upgrades.

When it runs​

Upgrades are applied lazily, per tenant. Loading a new model does not touch data: the first time a tenant is used after that, the platform sees that its data is behind the model and runs the pending upgrades. Many tenants on one model therefore do not all upgrade the moment you push.

The tenant is unavailable meanwhile​

During the run the tenant is temporarily unavailable:

  • API requests get 503 Service Unavailable with a Retry-After header and an application/problem+json body whose reason is DATA_UPGRADE. The body carries the state, the versions, the upgrade currently running and its progress, so an application can show a wait screen:

    {
    "type": "https://mosterd.com/problems/tenant-unavailable",
    "title": "Tenant temporarily unavailable",
    "status": 503,
    "reason": "DATA_UPGRADE",
    "details": {
    "state": "RUNNING",
    "versions": { "commons": { "from": 2, "to": 2 }, "rulebooks": { "from": 0, "to": 2 } },
    "current": { "namespace": "rulebooks", "version": 1, "description": "Relations of commons.dossier moved to rulebooks.rulebook" },
    "startedAt": "2026-11-17T10:12:03Z",
    "progress": { "actionsDone": 1, "actionsTotal": 3 }
    }
    }
  • Background work for the tenant (including scheduled updates) is postponed, not failed, and continues afterwards on the new model.

When the actions are done the database is rebuilt, so tables and filters on relations are correct from the moment the tenant is available again.

Computed values catch up afterwards​

Every object an action changed is recalculated after the tenant is released. Until that has run, computed values lag behind: formula fields, names built from a formula, and table columns, sorting and filters on them. Everything else is current.

Issues and what the platform does not check​

After the run, every changed object is compared with the new model: each stored relation must be declared on one of its classes under that key, and a single relation holds one target. What does not fit is recorded as an issue, with the object, the action and the problem. Examples: an object that ends up with two conflicting classes, or with two targets on a relation that is single on its new declaring class.

Issues do not block the tenant, and they do not change the data: it stays as the actions left it. The upgrade is marked as completed with issues. Issues are listed in the data status (GET /admin/{tenantId}/dataStatus), which also shows the data version per namespace against the model's, and the history of upgrades with their status and counts.

Your responsibility​

The platform guarantees that an upgrade runs once and reports what it could not do. It does not guarantee that your rules are right.

  • An upgrade is never rerun, whatever its outcome, even when it completed with issues. If something is wrong, fix it with a new upgrade (a higher version with extra actions). Editing the old upgrade has no effect on tenants that have already passed it.
  • Never reuse a version number. Removing old upgrades from the section is allowed once every tenant is past them, but never remove the highest one and then number a new upgrade the same.
  • Write the upgrade together with the model change, in the same commit.
  • Cover the objects outside your when. An action for part of a class usually needs another action for the rest, as in the relation example.
  • Name relations as stored, i.e. as in the old model. The stored relation is not checked against the new model, since it is typically the one the new model no longer has.
  • Test the upgrade on a copy of the tenant before pushing the model.

A technical interruption (an instance stops, a database is unreachable) is different: the upgrade is resumed from the start by the next access. Because actions are idempotent, objects already converted are skipped.