feat(schema): SQLite Schema Storage + Migration Ledger #8
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.
SQLite Schema Storage + Migration Ledger
TL;DR
Replace
.scaf-schema.yamlwith.scaf.db(SQLite). Store schema + nullability config + migration ledger + snapshots. Migrations stay as files; SQLite is the ledger.Design Decisions
Nullability Semantics
SQLite stores
nullable BOOLEAN DEFAULT FALSE. The internal representation is unambiguous.nullability_modeconfig only affects adapter extraction and YAML migration.Migration Storage
Options considered:
Chosen: B -
migrations/directory with text files. SQLite stores:version, name, checksum, applied_at, success, execution_ms.Rename Detection
Graph DB Migration Scope (Neo4j/Cypher)
Neo4j doesn't enforce schema - nodes can have arbitrary properties. The question is what migrations should generate.
Decision: Migration generation is driven by the schema's
nullablefield:nullable=truenullable=falseMATCH (n:Model) WHERE n.field IS NULL SET n.field = <default>unique=trueCREATE CONSTRAINTCREATE INDEXREMOVE n.field(with warning)nullable: true -> falseThe adapter extracts
nullablefrom ORM metadata (pointer types, struct tags, etc.) and populates the schema. Scaf's migration generator only sees the schema - it doesn't know ORM internals.Schema Design
SQLite Config
Interface Changes
SchemaLoader
SchemaRepository (new)
CLI Commands
Migration File Format
Each file:
Diff Algorithm
Breaking changes flagged:
nullable: true -> false(may have NULL data)Dialect Migration Interface
Cypher impl:
SET n.field = ...,REMOVE n.fieldSQL impl:
ALTER TABLE ... ADD COLUMN,DROP COLUMN