Codegen: emit column types, indexes and reducer signatures (foundation for 1.0) #25
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#25
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?
dev/tools/gen-schema.shfetches the full module schema and then throws away almost all of it. This is the foundation issue for 1.0: several other features are blocked on the generator keeping what it already has in hand.The evidence
The generator reads
.typespace.types[ref].Product.elementsand takes only.name.some:Every element carries its type right next to the name. Live 2.8.2 server,
chatmodule:Also discarded:
primary_keybeyond[0], every unique constraint, every index, and reducer parameter types (only names are kept).What to emit
Extend the generated module to carry, per table: column names and order (as now), pk, column types, unique constraints, and indexes. Per reducer and procedure: parameter names and types.
Type encoding in the generated Lua wants to be a compact string tag rather than nested tables — the Godot SDK settled on exactly this and it is the right shape for a table-driven decoder (a
BSATN_TYPESmap per row class, withopt_/vec_prefixes for nesting). Something like:Special types are structurally detectable
Confirmed against v2.8.2 (
crates/sats/src/product_type.rs:14-18) and by compiling a probe against the sats serializer: each special type is a single-field product with a magic field name, so detection needs no name heuristics and no guessing.Identity__identity__(U256)ConnectionId__connection_id__(U128)Timestamp__timestamp_micros_since_unix_epoch__(I64)TimeDuration__time_duration_micros__(I64)UuidScheduleAtInterval/TimeOption<T>some/noneNote that unit type variants serialize as
{"U64":[]}— an empty array, notnull— which the parser should encode explicitly rather than discover.Why this is the foundation
Blocked on this issue: #23 (special-type conversion must know which columns are special), typed per-table facades, unique-index lookups, typed reducer stubs, and any future BSATN work — a wire codec is impossible without column types.
Acceptance
dev/test/fixtures/chat_schema.luaregenerates with types, unique constraints and reducer parameter types, anddev/test/test_fixtures.luaasserts them against the live-captured schema rather than a hand-written expectation. A table with a compound pk, a unique non-pk column, and an index must be covered — which meansdev/server/index.jsneeds such a table, so add one.