Generate schema.lua from spacetime describe --json #14
Labels
No labels
area:defold
area:docs
area:infra
area:protocol
area:testing
kind:bug
kind:chore
phase:breadth
phase:core
phase:hardening
phase:slice
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
yuris/spacetimedb-defold#14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Column order is now load-bearing:
TransactionUpdatesends rows as positional arrays, soschema.luaneedscolumns = { ... }in the order the module declared them. Hand-maintaining that is a footgun — reorder a column in the module and every client silently mis-maps fields.The server already publishes the answer:
spacetime describe --json <db>returns the typespace with product elements in declaration order, plus anExplicitNamessection mapping source names to canonical snake_case (which is what reducer calls must use).tools/gen-schema) that fetches the schema over HTTP and emits aschema.luaRelated: #3 (fixtures), #2 (vertical slice).
Closed in
ad3779ctools/gen-schema.sh <base-url> <db>reads/v1/database/<db>/schema?version=9and emits a Lua module:That HTTP endpoint turned out to be much friendlier than
spacetime describe --json:tables[].product_type_refindexes intotypespace.types[]for the ordered elements,primary_keyis a column-index array, and reducer names come back already canonical — noExplicitNamescross-referencing needed, and no CLI or docker required to run the generator.Made load-bearing, not optional
A generator nobody runs is worse than no generator. So:
tools/dev-server.shregeneratestest/fixtures/chat_schema.luaon every publishtest_fixtures.luaconsumes that generated file instead of a hand-typed schema, and asserts the column order, pk, canonical reducer name and paramsVerified the guard actually fires
Swapped
senderandtextinserver/index.js, republished, ran the suite:Reverted, suite green. So the failure mode this issue was filed against — a reordered column silently mis-mapping every row — now stops at the test instead of reaching a game.
Note for consumers
stdb.schema.new(generated.tables)is the intended usage;generated.reducersexists so callers can avoid hardcoding a name in the wrong case.pkgs.jqwas added to the dev shells for the generator.