fix(storage): ensure_schema converges a legacy SCHEMALESS change_log table - #232
Merged
Merged
Conversation
…table Databases that wrote change_log rows before the table was declared in the schema (an export/import preserves the shape) hold it as SCHEMALESS, where the DEFINE FIELD OVERWRITE payload ... FLEXIBLE statement is rejected — so every startup warned and the field never converged (issue #230). ensure_schema now probes INFO FOR DB and runs ALTER TABLE change_log SCHEMAFULL first: the documented schemaless-to-schemafull transition, keeping existing rows and rejecting nothing the writer produces (every column is declared). Probe and ALTER stay fail-soft — a failure merely preserves the previous behaviour.
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
ensure_schemaprobesINFO FOR DB; whenchange_logexists as a legacy SCHEMALESS table it runsALTER TABLE change_log SCHEMAFULLbefore the statement loop, so theDEFINE FIELD OVERWRITE payload … FLEXIBLEdefine becomes valid and the field finally converges.Why
Closes #230. Databases that predate the change_log declaration — including any carried through
surreal export | import— keep the implicit SCHEMALESS table forever, so the 3.9.2 schema fix warned on every startup and the field kept its oldnone | objectshape.ALTER TABLE … SCHEMAFULLis SurrealDB's documented transition for existing tables with data, and every column the writer produces is declared, so the tightening rejects nothing.Test plan
pytest tests/ -m "not stress" -n auto— 7340 passed (5 new: schemaless→ALTER-before-defines, schemafull untouched, fresh DB untouched, ALTER-fail and probe-fail fail-soft).ruff check/ruff format --checkclean;mypy src/clean.Verified by
@acidkill