Skip to Content
Config SystemMigrations

Migrations

When you remove a field from your config, the values stored under it do not disappear with it. foir push keeps them, tells you they are waiting, and asks what should happen to them before it finishes the removal.

That question is asked in a file, because foir push usually runs in CI where there is nobody to answer a prompt. You answer it in a commit, review it like the rest of your schema, and push again.

The two-push flow

Take a field you want to rename — subtitle becomes strapline. You edit your config and push.

The first push does everything it safely can. It adds strapline, applies every other change in the file, and stops short of removing subtitle. The old field is retained as deprecated, its values intact and still readable, and push writes a decision file:

migrations/20260827-093000-article.foir.ts

The push exits non-zero, so CI stops here rather than reporting a half-finished change as done.

You answer the file and push again. The second push records your decision. The release that carries the model runs it: it moves the values and then completes the removal. foir push --publish is that release; a plain push leaves the decision waiting, and foir release publish or the unpublished list on the home page releases it later.

The data risk starts at the release, not at the push. Until a release carries the model, the values stay where they are, the published model still declares the field, and a decision you recorded can still be changed. A migration only moves or drops data when the release that changes what production serves runs it.

The release says what it did to your records. Each release names the migrations it ran: the model, the fields each one decided, where it stands and the records it rewrote. You see them on the push’s ✓ Released line, in foir release list, and on the last release in the console’s unpublished list. A release that runs a migration for a model whose definition was already released carries no item for that model, and the migration is still listed. A release that ran migrations cannot be rolled back, because its records were moved into the shape it released.

The order matters and is not negotiable: strapline has to exist before anything can be moved into it, which is why the additive half of your change always applies first.

The decision file

Push writes the file with every waiting field commented out, along with how much data is involved and how long you have:

import { migration } from '@foir/cli/migrations'; export default migration('2026-08-27T09:30:00Z', { article: { // subtitle: text — 1,240 rows with data — 40 records, 1,200 versions, readable until 2026-09-26 // // Uncomment ONE: // subtitle: { renameTo: 'newKey' }, // subtitle: { fillFrom: { field: 'otherKey' } }, // subtitle: { drop: true }, // subtitle: { hold: 'why' }, }, });

Uncomment one decision per field and fill it in:

import { migration } from '@foir/cli/migrations'; export default migration('2026-08-27T09:30:00Z', { article: { subtitle: { renameTo: 'strapline' }, }, });

Everything is commented out on purpose. A field you have not answered has to fail the next push exactly as it failed this one, and an empty block is the one thing that cannot be mistaken for an answer.

The file is never overwritten. Re-running an incomplete push finds the file it wrote last time, with your half-typed answers still in it.

Decision files live in a migrations/ directory beside your config file. Commit them.

Every push carries the whole directory, so a decision reaches every project the config names, including one that never held the field it is about: a staging project created after production dropped it, say. There the decision has nothing to move. It settles as applied with no rows moved, on the push that carries it. A decision about a field the project does hold is checked as usual, so a misspelt field name is still caught: the field you meant stays waiting for a decision, and the push says so.

What you can say

Eight decisions, one per field.

renameTo, splitInto, drop and hold decide what happens to the values of a field you removed. They answer a removal, so they only name a field your config no longer declares: naming one it still declares fails the migration, and the field’s values stay where they are. retype, remapValues, fillFrom and joinFrom change a field in place or fill one, so they may name a field that stays.

renameTo

Move the values to a field with a different key.

subtitle: { renameTo: 'strapline' }

retype

Convert the values to another type.

price: { retype: { to: 'decimal' } } // Values that will not convert become null instead of failing the migration price: { retype: { to: 'decimal', onError: 'null' } }

onError decides what happens to a value that will not convert — fail (the default), null, or skip. The default fails the whole migration, because a conversion that quietly discards what it could not handle is a migration that reports success having lost data. Choose null or skip only when you know what is in the column.

remapValues

Rewrite stored values through a lookup table.

status: { remapValues: { values: { draft: 'DRAFT', live: 'PUBLISHED', archived: 'ARCHIVED' }, failOnUnmapped: true, }, }

failOnUnmapped stops the migration when it meets a value your table does not cover, rather than leaving it as it was.

splitInto

Split one field’s value across several, on a separator.

fullName: { splitInto: { into: ['firstName', 'lastName'], on: ' ' } }

joinFrom

Join several fields into this one, with a separator.

fullName: { joinFrom: { from: ['firstName', 'lastName'], with: ' ' } }

fillFrom

Fill this field from another field on the same record.

// From another field on the same record summary: { fillFrom: { field: 'subtitle' } } // Leave records that already have a value alone summary: { fillFrom: { field: 'subtitle', onlyWhenEmpty: true } }

onlyWhenEmpty leaves records that already have a value alone.

The field being filled has to be on the published model already. A field the same unreleased change adds has nothing stored under it yet, so a decision naming it is refused. To move values into a new field, use renameTo on the field you removed.

The file’s types also offer fillFrom: { constant: … }, but foir push does not send the constant yet, so a decision written that way is refused for naming neither a field nor a constant.

drop

Discard the values, deliberately.

legacyNotes: { drop: true }

This is different from leaving a field undecided, which push refuses. drop is a signature on the loss, not something you can fall into by forgetting.

hold

Leave the data alone because you are handling it yourself.

imported: { hold: 'migrating these from the old CMS by hand in Q4' }

The reason is recorded, so a migration that ran nothing still says why. The field keeps its deprecated status and its grace period, and it will keep appearing in foir migrations status until you deal with it.

Checking what is outstanding

foir migrations status

Shows what has run and, first, anything still waiting on a decision with the time left on it.

It exits non-zero when anything is unfinished, so it works as a CI step on its own — add it to your pipeline and a forgotten decision fails the build instead of quietly running down its grace period. A migration that is FAILED, RUNNING or PENDING counts as unfinished; a discarded one does not. See when a migration fails for how to settle one.

Show more history with --limit:

foir migrations status --limit 50

Records that name no owner

Moving a model onto an owned plane (ownerPlane: 'user' or 'organization') means every record needs an owner of that kind from the release on. When some of the model’s records name none, the push drafts the move, holds it back from every release (--publish included) and writes the question into the decision file, naming the model and how many records are affected:

export default migration('2026-09-26T10:00:00Z', { order: { // Moving onto the user plane: 312 records name no user owner. // // Uncomment ONE: // $owner: { assignFrom: 'fieldKey' }, // $owner: { hold: 'why' }, }, });

$owner: { assignFrom: 'placedBy' } gives each record the owner its placedBy field names, inside the release that moves the model, through the same write path an edit takes, so each reassignment is audited and served. The release refuses if any record’s field names no owner of that kind in the project, and names how many. $owner: { hold: 'why' } leaves the records as they are while you assign them yourself; the move is then released without them.

Until one of the two is answered, a release that would carry the move refuses, naming the model and the count. A release assigns up to 2,000 records inside its transaction; beyond that, hold them and assign their owners before the model moves.

Records that name an owner on a project model

A model with no ownerPlane (or ownerPlane: 'project') holds records that belong to the project, whoever creates them. Moving a model off an owned plane leaves its existing records naming the owners they had. When some do, the push drafts the move, holds it back from every release and writes the question into the decision file:

export default migration('2026-10-08T10:00:00Z', { comment: { // On the project's plane: 2 records name an owner. // // Uncomment ONE: // $owner: { toProject: true }, // $owner: { hold: 'why' }, }, });

$owner: { toProject: true } makes each of those records the project’s, inside the release that carries the model, through the same write path an edit takes. A record’s versions and variants go with it, the key it is found by moves from its owner’s keys to the project’s, and each one is audited with the owner it had. Two records that hold the same key under different owners cannot both become the project’s: the release refuses, naming both, until one of them changes or they are held. $owner: { hold: 'why' } leaves the records their owners’ own. The model is released, new records are the project’s, and the held ones stay as they are until you decide.

A record made the project’s is read like any other record of the project’s. On a model that is private by default, the user who owned it no longer reads it. Hold the records if they should stay private to the people who made them.

Until one of the two is answered, a release that would carry the move refuses, naming the model and the count.

The same answer works for a model that is already on the project’s plane and still holds records that name an owner, such as records created before a project model’s records belonged to the project. Nothing asks about those: write $owner: { toProject: true } for the model in a migration file, push it, and the next release makes them the project’s. A release clears up to 2,000 records inside its transaction; beyond that, hold them and clear each record’s owner yourself.

The grace period

A removed field’s values stay readable for a grace period, shown as a date against each waiting field. Answer before it expires.

The period is what protects the data: while a field is deprecated its values are held safely, and ordinary edits to those records will not disturb them. Once the window closes, that protection ends.

foir migrations status shows the days remaining, and says so plainly when a window has already closed.

Large collections

A migration over a small collection runs as soon as its release commits. A larger one is queued and continues in the background, so the release reports it as running rather than finished, which is accurate: the work is accepted and not yet done. Check foir migrations status for progress, or read the release again: it reports each migration as it stands, so foir release list shows where a running one ended.

When a migration fails

Push exits non-zero and tells you the schema change was released but the data did not convert.

Worth understanding, because it decides what you do next: the schema half of your change is already live at that point. The migration runs after its release, since it needs the new fields to exist before it can write to them. So a failure leaves your models released and your data unconverted, not a rolled-back release. The field it was answering keeps its values and stays declared until a migration that succeeds contracts it.

There are two ways forward, and the failed entry stays in the ledger until you take one of them. Until then foir migrations status keeps exiting non-zero, so a failure you walked away from keeps your build red rather than aging quietly out of view.

Fix the decision and push again. The usual answer when the migration was wrong and the conversion is still wanted.

Or discard it:

foir migrations discard <id> --reason "converted by hand in the 2026-09 backfill"

Discard settles the ledger entry and touches no records. It does not undo the schema change, does not convert anything, and does not roll anything back — it records that this migration is not going to complete and why. Reach for it when the conversion happened another way, or when it is no longer wanted.

A discarded entry is deliberately excluded from the gate’s arithmetic, which is the whole point: FAILED, RUNNING and PENDING all keep migrations status red, and DISCARDED does not. The --reason is what makes that safe to read later, so write one that says what actually happened to the data.

Removing a field without any of this

foir push --drop-now

Drops omitted fields outright instead of retaining them as deprecated, and reports what it cost.

Caution: This skips the grace period, which is the thing keeping a removed field’s stored values readable and safe. Use it only when the data has already been dealt with — or when you are certain there is none you want.

Renaming a model

The flow above is for fields. Renaming a model key is a create plus a delete, and on a pruning push the old model’s records go with it. See Push and Remove before renaming one.

Last updated on