Skip to content

fix(schema): V10 schema conversion drops column default values#5508

Open
Ludv1gL wants to merge 1 commit into
clockworklabs:masterfrom
Ludv1gL:fix/v10-schema-column-defaults
Open

fix(schema): V10 schema conversion drops column default values#5508
Ludv1gL wants to merge 1 commit into
clockworklabs:masterfrom
Ludv1gL:fix/v10-schema-column-defaults

Conversation

@Ludv1gL

@Ludv1gL Ludv1gL commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

…0 conversion

The From<TableDef> impl hardcoded default_values: Vec::new(), so any
V10 serialization of a validated ModuleDef (e.g. the /schema?version=10
endpoint and 'extract-schema') silently dropped all column defaults,
while the V9 path preserved them via misc_exports. Emit them from
ColumnDef.default_value using the same BSATN encoding the V9 conversion
uses, and add a V10 round-trip test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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