Files
Ludv1gL 204f633035 fix(schema): V10 schema conversion drops column default values (#5508)
## Description of Changes

`impl From<TableDef> for RawTableDefV10` hardcodes `default_values:
Vec::new()`, so converting a validated `ModuleDef` back to
`RawModuleDefV10` silently drops every column default. This affects
anything that serializes a module's schema as V10 — notably the `GET
/v1/database/:name_or_identity/schema?version=10` endpoint and
`extract-schema` — while `?version=9` correctly preserves defaults via
`misc_exports` (`RawMiscModuleExportV9::ColumnDefaultValue`).

Concretely: a table column declared with `#[default(...)]` shows up in
the V9 schema but its default is absent from the V10 schema, so V10
consumers (schema diff/compat tooling, codegen, migration checks) cannot
see defaults at all.

The fix mirrors what the V9 conversion already does: emit
`default_values` from `ColumnDef::default_value`, BSATN-encoding each
value (`RawColumnDefaultValueV10 { col_id, value }`). Validation already
round-trips these — `ModuleValidatorV10::validate_table_def` decodes
`default_values` and attaches them to columns — so this closes the loop.

Also adds `v10_roundtrip_preserves_column_defaults`: builds a module
with a column default via `RawModuleDefV10Builder`, validates it into a
`ModuleDef`, converts back to `RawModuleDefV10`, and asserts the default
survives with the expected encoding.

## API and ABI breaking changes

None. `RawColumnDefaultValueV10` and the `default_values` field already
exist in the V10 format and are already consumed by validation; this
only populates a field that was previously always empty on the
serialization side.

## Expected complexity level and risk

1 — small, self-contained fix in one conversion impl, plus a unit test.

## Testing

- `cargo test -p spacetimedb-schema --lib`: 110 passed, including the
new round-trip test.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
2026-07-21 15:04:45 +00:00
..
2026-04-30 09:00:13 +00:00
2025-08-12 18:20:58 +00:00

⚠️ Internal Crate ⚠️

This crate is intended for internal use only. It is not stable and may change without notice.