Skip to content

Fix SQLite NULL from ALTER TABLE ADD COLUMN returns proper defaults - #72

Merged
ilyakooo0 merged 1 commit into
masterfrom
push-lwuxxolplnlm
Jul 12, 2026
Merged

Fix SQLite NULL from ALTER TABLE ADD COLUMN returns proper defaults#72
ilyakooo0 merged 1 commit into
masterfrom
push-lwuxxolplnlm

Conversation

@ilyakooo0

Copy link
Copy Markdown
Owner

Summary

Adding a new field to a record type in a source relation and running without a migrate block left SQL NULL for existing rows. read_sql_column returned a raw null pointer for non-nullable types, and even Maybe fields read back as null instead of Nothing.

Fix

read_sql_column now returns proper default values when the SQL column is NULL:

  • Int: 0 (backfilled as TEXT '0' with COLLATE KNOT_INT)
  • Text: empty string
  • Bool: False
  • Float: 0.0
  • tag (enum): panics with actionable message pointing at migrate block
  • Maybe: Nothing (NULL naturally maps to Nothing)
  • json: Nothing (documented tradeoff)

Tests

7 new tests: scalar defaults, Maybe→Nothing, SQLite backfill typing, nested-child-table fields, enum error, ADT invariants.

Verification

cargo test -p knot-runtime
# 156 passed

End-to-end repro: {name, age} grown to {name, age, nickname: Maybe Text, score: Int, active: Bool} with no migrate block. Before: null pointers. Now: [{active: False, age: 30, name: "Alice", nickname: Nothing, score: 0}, ...]

…lt values

Adding a new field to a record type in a source relation and running
without a migrate block left SQL NULL for existing rows. read_sql_column
returned a raw null pointer for non-nullable types, and even Maybe
fields read back as null instead of Nothing.

Fix: read_sql_column now returns proper default values when the SQL
column is NULL:
- Int: 0 (backfilled as TEXT '0' with COLLATE KNOT_INT)
- Text: empty string
- Bool: False
- Float: 0.0
- tag (enum): panics with actionable message pointing at migrate block
- Maybe: Nothing (NULL naturally maps to Nothing)
- json: Nothing (documented tradeoff — can't distinguish Maybe from
  other json-column shapes without descriptor format change)

7 new tests covering scalar defaults, Maybe→Nothing, SQLite backfill,
nested-child-table fields, enum error, and ADT invariants.
cargo test -p knot-runtime: 156 passed.
@ilyakooo0 ilyakooo0 added the bug Something isn't working label Jul 12, 2026
@ilyakooo0
ilyakooo0 merged commit 7eb77e6 into master Jul 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant