Fix SQLite NULL from ALTER TABLE ADD COLUMN returns proper defaults - #72
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_columnreturned a raw null pointer for non-nullable types, and evenMaybefields read back as null instead ofNothing.Fix
read_sql_columnnow returns proper default values when the SQL column is NULL:'0'with COLLATE KNOT_INT)migrateblockTests
7 new tests: scalar defaults, Maybe→Nothing, SQLite backfill typing, nested-child-table fields, enum error, ADT invariants.
Verification
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}, ...]