Skip to main content

Module model

Module model 

Source
Expand description

Page-builder storage models — migration-tracked, versioned.

No DDL runs when a Developer edits a schema: a structure change writes a new draft row, and publishing flips draft→published (version+1) while archiving the prior published row. Page values live in one stable JSON store (PageBuilderData) and upgrade lazily. Tables are created once by the generated 0006_page_builder migration, never altered by the builder.

Structs§

Component
A reusable field-group (a component), referenced from schemas by slug (c_<slug>).
PageBuilderData
The filled builder values for one page (additive to any code page type’s own extension table). One row per page.
PageTypeSchema
A versioned body-schema document attached to a page type.

Constants§

STATUS_ARCHIVED
STATUS_DRAFT
Lifecycle of a schema row. Exactly one draft and one published per page type at a time (code-enforced); archived rows are history.
STATUS_PUBLISHED

Functions§

all_components
Every reusable component, ordered by slug.
component_by_id
One component by id.
component_map
Component library as a slug → entry map for crate::page_builder::validate_schema / crate::page_builder::compile(). Malformed component docs are skipped.
component_reference_counts
How many live page-type schemas reference each of slugs, from one scan of the schemas (what component_references would count, for every slug at once).
component_references
Page types whose non-archived (draft or published) schema references a component slug — returns (page_type_id, status) pairs. Used to block deletion of an in-use component.
create_component
Create a component (version 1). document is a ComponentDoc JSON.
data_for_page
The stored builder values for a page, if any.
delete_component
Delete a component by id (no-op if it’s already gone).
draft_for
The draft schema row for a page type, if any.
list_versions
Published + archived rows for a page type, newest version first — the version history.
publish
Publish the draft: archive the current published row, flip the draft to published with version = prev_published + 1. Returns the new published row, or None when there is no draft to publish.
published_for
The published schema row for a page type, if any.
save_draft
Upsert the single draft for a page type with document. Creates the draft (version = published+1) if none exists.
update_component
Update a component’s metadata + document and bump its version so referencing schemas pick the change up lazily (next open / render). The slug is immutable (it’s the reference key).
upsert_data
Upsert a page’s builder values.