Model API reference¶
This page is generated directly from the SQLAlchemy models in
hq/sql_models/template.py by mkdocstrings. It is the authoritative,
never-drifting reference for the template table group: the four live model
classes (Template,
TemplateBlock,
SiteBlockOverride,
PageType) and their history mirrors.
For the narrative explanations, see Data model overview, Page types, and sources / bind / call / params explained.
SQLAlchemy models for S3-backed CMS template and style registries.
Template and Style hold registry metadata plus bucket-relative
s3_key pointers; template shell markup and stylesheets no longer live in
the database. PageType and TemplateStyle retain their relational
configuration for templates. The models are the schema source of truth used by
Base.metadata.create_all() and the CMS drift check.
Template
¶
Bases: CMSBase, Base
A named, versioned S3-backed CMS template a site can adopt.
slug is unique; settings_schema / default_settings are JSON;
s3_key points to the template shell in the environment-selected bucket.
Source code in template.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
PageType
¶
Bases: CMSBase, Base
A data-driven page descriptor a template exposes (AISD P1.b).
One row per (page type, variant) a template renders. It replaces the
worker's hardcoded router.ts rules and pages/*.ts orchestrators: the
worker reads these rows (served inside the public /settings payload,
resolved for the site's active template) and runs one generic match route
-> fetch sources -> build -> wrap layout loop.
Scoped to a template_id (a template owns its page types). Unique on
(template_id, type, variant).
variant lets one template carry multiple layouts for the same page
type (e.g. a "listicle" article alongside the "default" article).
It is NOT NULL with a "default" server default so the unique key stays
clean (MySQL treats NULLs as distinct). The worker selects the variant from a
content field (e.g. content.settings.layout / content_type), falling
back to "default" -- so a route resolves to (type) first, then the
builder/content picks the variant.
JSON column contract (all interpreted by the worker engine):
routes: list of path patterns, e.g.["/{category}/{slug}"].{name}segments capture params; a trailing*segment is a catch-all.layout: ordered list of templateelement_typecontent slots to render into the page body. NB:header/footerare added by the worker'srenderLayoutwrapper and must NOT be listed here.sources: list of{bind, call, params, required}declared API calls (callin lists/pages/authors/sitemap/seo).required: falsesources degrade tonullon failure instead of failing the page.bindings: map of template-context key -> dotted path into the fetched sources, e.g.{"related": "related.items"}.grids/sidebar/partial/seo: declarative fill + SEO hints for pure-data page types (no code).transforms: ordered list of named editorial transforms the worker applies (e.g.article_content_blocks,editors_picks_sidebar).builder: optional named builder transform for page types whose shaping is too bespoke for the declarative fields (WK's existing pages use this for exact parity). When unset, the engine uses the declarative path.position: ascending match-priority hint; literal-segment specificity still wins within equal-length routes.
Source code in template.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
Style
¶
Bases: CMSBase, Base
A reusable S3-backed stylesheet in the CMS styles registry.
A Style is a first-class, named, versioned stylesheet a site can adopt
independently of its structural Template. This decouples skin (CSS)
from structure (template layout + page_types): a "reskin" is a new Style
row + a site pointer, not a cloned template. A site selects its style via the
site_settings key style_slug; cms-api resolves it into the public
/settings payload as active_style and serves the CSS at
/public/v2/styles/<slug>/css. The worker links + edge-caches it at
/_assets/styles/style/<slug>/<version>.css.
slug is unique; version carries a content hash so the worker's URL
cache-busts when the S3 object changes -- no worker redeploy needed.
Source code in template.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
TemplateStyle
¶
Bases: CMSBase, Base
A known-good (template, style) pairing selectable as one unit (AISD-220).
A style's CSS is authored for a specific template's markup, so pairings are
curated, not free-mixed. The site_settings key template_style_id
points a site at one row; cms-api resolves it to active_template +
active_style (N3). At most one active is_default row per template --
enforced at the app layer (this task's seed + N2's admin CRUD), since MySQL 8
has no partial / filtered unique index to express it. The hard
UNIQUE(template_id, style_id) constraint still forbids duplicate pairings.
No history mirror is added: epic AISD-207 drops the *_history tables, so a
new template_styles_history mirror + trigger would be immediately scheduled
for removal.
Source code in template.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
Action registry models¶
The forge action-registry table group (Action,
Step, ActionStep
and their history mirrors). See Action registry (forge recipe)
for the narrative.
Forge action-registry models (epic AISD-174, task AISD-175; rename AISD-199).
The action registry lets cms-ai-forge's generation pipeline recipe live in
cms_db instead of hardcoded Python. Three tables (ai_ prefix, AISD-199):
ai_actions-- a named workflow (the intent key, e.g.site_scaffold).ai_steps-- a reusable step definition: itsentity_type, theoutput_schemaa provider result must satisfy, an optionalprompt_templateandprovider_kind.ai_action_steps-- the ordered join binding steps into an action (position,chainflag, per-bindingparams).
cms-ai-forge's planner reads an action's ordered steps from here (AISD-177) and
its executor reads each step's schema/prompt/provider from the ai_steps row
(AISD-178), replacing the hardcoded planner._expand_* / GENERATORS path.
This task delivers ONLY the schema (models + history triggers); the cms-api
admin CRUD (AISD-176) and the seed of today's intents (AISD-179) are siblings.
The task state-machine graph and the provider-call / coercion logic stay in code by design -- only the pipeline composition (which steps, in what order, producing what schema, with what prompt) is data.
ai_actions and ai_steps are operator-editable (via cms-api /admin), so
each gets a flat history mirror + AFTER UPDATE trigger (the styles
registry pattern, AISD-126/AISD-136). ai_action_steps is a junction and gets
none.
Action
¶
Bases: CMSBase, Base
A named generation workflow (the intent an ai-forge job requests).
name is the stable intent key (unique), e.g. site_scaffold or
article_batch; description is human-facing. The ordered steps that
make up the action live in ai_action_steps. Inherits
id / created_at / updated_at / is_active from CMSBase.
Source code in pipeline.py
41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Step
¶
Bases: CMSBase, Base
A reusable pipeline step definition consumed by the ai-forge executor.
A Step describes one entity the executor can generate: slug is its
stable identifier (unique), entity_type selects the generation behaviour
in code (e.g. article, settings, image), output_schema is the
JSON schema a (non-stub) provider result must satisfy, required_keys is an
optional JSON list of keys the result must contain, prompt_template is the
prompt (with placeholders) sent to the provider, and provider_kind selects
the provider (e.g. openai_text, openai_image, stub). A step is
reusable across actions via ai_action_steps. Inherits the CMSBase columns.
Source code in pipeline.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
ActionStep
¶
Bases: IntPKMixin, TimestampMixin, Base
Ordered binding of a :class:Step into an :class:Action.
Junction table (own surrogate id PK, timestamps, no is_active):
action_id -> ai_actions.id and step_id -> ai_steps.id,
position is the 0-based order within the action, chain mirrors the
planner's chain flag (this step's output feeds the next), and params is
optional per-binding JSON overrides. Unique on (action_id, position) so
an action has exactly one step per position.
Source code in pipeline.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
ActionHistory
¶
Bases: IntPKMixin, Base
A flat audit mirror of an ai_actions row's prior state.
Decoupled mirror per the StyleHistory pattern: own surrogate id PK; a
plain indexed action_id INT (the OLD ai_actions.id) with no foreign
key; changed_at; every mirrored column nullable, no unique, no FK. Rows
are inserted only by the trg_ai_actions_history AFTER UPDATE trigger; the
column list stays in lock-step with that trigger's INSERT.
Source code in pipeline.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
StepHistory
¶
Bases: IntPKMixin, Base
A flat audit mirror of an ai_steps row's prior state.
Decoupled mirror per the StyleHistory pattern: own surrogate id PK; a
plain indexed step_id INT (the OLD ai_steps.id) with no foreign
key; changed_at; every mirrored column nullable, no unique, no FK --
including the JSON output_schema / required_keys so a prior step
definition is recoverable. Rows are inserted only by the
trg_ai_steps_history AFTER UPDATE trigger; the column list stays in
lock-step with that trigger's INSERT.
Source code in pipeline.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |