Skip to content

Move a record through states

A lifecycle gives a table a state column and the moves between its states. Use it for an editorial workflow, an approval, or any record that is not only created and edited.

table posts "Posts" {
display: title
title text required "Title"
body markdown required "Content"
lifecycle status "Status" {
state draft default "Draft"
state review "In review"
state published public "Published"
state archived gone "Archived"
transition submit draft -> review "Send for review" {
access {
author where author = :user.person_id
editor
}
}
transition publish review -> published "Publish" {
access: editor
set published_at = now
after -> logic/post-published.ts
}
transition archive published -> archived "Archive" {
access: editor
}
}
}

The lifecycle declares the state column status: an enum of the states, with their labels as captions. It stands where the lifecycle is written. To put it between other columns, write status lifecycle on the line where it belongs; see place the column.

The state column is engine-owned. It never appears in a form, and a request can never set it. A state changes only through a transition.

default names the state a new row starts in. public marks a state whose rows a public page can read, and status.public is then usable in a condition.

A transition carries its own access:. The author can send a post for review; only an editor can publish it.

A button is absent when the transition’s access rule excludes the reader or row, or the record is not in a source state. A deny when condition keeps the button visible and explains the refusal after the person presses it. Use access with where to hide the button instead.

A transition is an action of the page rather than of a region. Which row the page is about already has one answer, so the transition does not restate it.

The source state and the reader’s row filter are both conditions of the update. If somebody left a page open and the record moved on in the meantime, their button does nothing and says so.

after -> runs a script after the move is committed. It sees the record after the move and receives the previous row as well, so it can say what changed.

lifecycle status "Status" {
state review default "In review"
state published public "Published"
transition publish review -> published "Publish" {
access: editor
after -> logic/post-published.ts
}
}

A transition’s set values, the table’s own checks over the moved row, and a before hook all run in one transaction with the move. The after hook runs after the commit, so it cannot roll the move back and cannot make a successful move look failed.

A table’s insert and update hooks do not run on a transition. A move is not an edit.

A record in a gone state, such as archived above, is left out of every report, list, sheet, export and calendar feed, of every stats region and count, of every matrix axis, and of the choices of a ref or multi field. A record that already points at it keeps it. At its address on a public page it answers 410 Gone. A page that only staff can open still shows it, so an editor can move it back if a transition allows that.

To give editors a way back, add a page that lists the archived records and links each one to its staff page:

report of posts "Archive" {
columns: title, author
where: status = archived
gone: show
row -> post_edit
}

gone: show is required here. Without it, the report reads no archived record, and the compiler refuses the where:. See The table block: state.

Add approvals: 2 to the transition that accepts a submitted record. Use including for roles that must be represented by different people, excluding to separate maker and checker, and covers for child content such as expense lines. See independent approvals for the full declarations.

Provide a review page with the owner form and a report of all covered lines. Each approver needs access to the complete content and its sensitive fields. They open the content disclosure, review it, and press Approve, optionally adding a comment. The first confirmation leaves the record submitted; the press meeting both the count and role requirements completes it.

Add a reopen: approve transition from every protected branch back to a draft. Completed content is protected until somebody authorized presses Reopen for changes. After editing, submit again and collect fresh approvals. The earlier completed round remains in history.

The sports club example contains the complete expense workflow and a workflow test for the €40-to-€400 edit refusal.

Website privacy policy