Skip to content

Seed a Matrix and a Table field on the About page - #65

Merged
duguankui merged 1 commit into
mainfrom
seed-matrix-table-fields
Sep 6, 2026
Merged

Seed a Matrix and a Table field on the About page#65
duguankui merged 1 commit into
mainfrom
seed-matrix-table-fields

Conversation

@duguankui

Copy link
Copy Markdown
Member

Why

Neither composite field type appeared anywhere in the seed data — I checked the full git history of all four seed/test-data files, and Matrix has never been in any of them. So the only way to see either type render was to hand-build a configuration in the admin UI first.

That's worth fixing now specifically because Site no longer declares these types at all — they're flex-fields kernel built-ins as of 10.0.0-rc.16. A seeded example is the cheapest standing check on that integration.

What

Two fields on the About content type:

Field Type Shape
about_highlights Matrix two block types — paragraph (text) and stat (value + label)
about_milestones Table columns year, event

Matrix gets two block types on purpose, so the polymorphic-repeater shape is actually exercised rather than a single-block degenerate case.

Configurations are built from the kernel's own MatrixConfiguration / TableConfiguration / InlineFieldDefinition rather than hand-written dictionaries — an upstream rename or reshape then fails the build here, instead of silently seeding a configuration nothing can read. Values likewise use MatrixBlockValue / TableRow.

Test plan

Verified against a real seed run, not just a compile:

  • Pointed the host at a throwaway SQLite database and ran --migrate-database
  • Read the row back out of the FlexFields column. Both values are stored in the canonical camelCase wire shape, which also confirms Normalize and validation ran — ContentManager.CreateAsync would have thrown otherwise:
about_highlights = [{"blockTypeName":"paragraph","values":{"text":"..."}},
                    {"blockTypeName":"stat","values":{"value":"7","label":"..."}}]
about_milestones = [{"values":{"year":"2024","event":"First internal build"}}]
  • The seed stays idempotent by name, like everything else in this contributor — it won't touch an already-populated database, including this repo's own dev Host.db

Neither composite field type appeared anywhere in the seed data - checked the
full history of all four seed/test-data files, Matrix has never been in any of
them - so the only way to see either one render was to hand-build a
configuration in the admin UI first. That is worth fixing now specifically
because Site no longer declares these types at all: they are flex-fields kernel
built-ins as of 10.0.0-rc.16, and a seeded example is the cheapest way to keep
an eye on the integration.

Adds two fields to the About content type:
  - about_highlights (Matrix) with two block types, paragraph and stat, so the
    polymorphic-repeater shape is actually exercised rather than a single-block
    degenerate case
  - about_milestones (Table) with year/event columns

Configurations are built from the kernel's own MatrixConfiguration /
TableConfiguration and InlineFieldDefinition rather than hand-written
dictionaries, so an upstream rename or reshape fails the build here instead of
silently seeding a configuration nothing can read. Values likewise use
MatrixBlockValue / TableRow; ContentManager runs them through the field type's
own Normalize on the way in.

Verified against a real seed run, not just a compile: pointed the host at a
throwaway SQLite database, ran --migrate-database, and read the row back. Both
values are stored in the canonical camelCase wire shape -
[{"blockTypeName":"paragraph","values":{...}}] and [{"values":{...}}] - which
also confirms Normalize and the validation pass ran, since CreateAsync would
have thrown otherwise.
@duguankui
duguankui merged commit 7990043 into main Sep 6, 2026
1 check passed
@duguankui
duguankui deleted the seed-matrix-table-fields branch September 6, 2026 00:39
duguankui added a commit that referenced this pull request Sep 6, 2026
…w ones (#66)

#65 added about_highlights/about_milestones but only verified against a
throwaway database. Against a real, already-migrated database (this repo's
own dev Host.db), the seed's own idempotency worked against it:
GetOrCreateContentTypeAsync found the about content type already present and
returned it untouched, so both fields were created and left attached to
nothing.

The straightforward fix - attach fields created this run - doesn't cover this
exact database either: the fields were created by an earlier run of the OLD
code, before this content-type-append logic existed, so they predate the run
entirely.

Replaced that with "attached to no content type anywhere", computed once at
the start of SeedAsync and kept current as this run attaches more. A field
with zero usages anywhere is specific enough to this failure mode to touch
automatically for a local dev convenience seed; a field still in use
elsewhere is left alone either way. New usages are appended after the current
highest Order so a deliberate arrangement is not reshuffled.

Verified against this repo's own dev Host.db in the exact broken state
reported: the two fields moved from unattached to Order 2/3 on About, a
second run made no further change, and a from-scratch database still gets
all four fields in one pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant