fix(schema): kg_entities.attributes + vec dim guard + ESM __dirname + user_version - #18
Merged
Merged
Conversation
[P0] kg_entities: add attributes TEXT to CREATE TABLE + idempotent ALTER after the CREATE block so existing DBs created pre-fix also get the column. Without this, `kg-extract`/`kg-build` crashed "no column named attributes" on every fresh install because migrateToV7 ran before ensureGraphTables. [P1] ensureVecTable: detect embedding dim mismatch before IF NOT EXISTS. If vec_chunks already exists with a different dim, throw a clear actionable error instead of a cryptic vec0 crash on the first INSERT after a provider switch (e.g. Gemini 3072d → OpenAI 1536d). [P1] embed.ts: fix __dirname ReferenceError in ESM fallback path. import.meta.dirname is undefined on Node 20 LTS; fallback was __dirname which is NOT defined in ESM. Replaced with dirname(fileURLToPath(import.meta.url)) and added the required node:path/node:url imports. [P1] db.ts ensureSchema: set PRAGMA user_version = SCHEMA_VERSION after migrations so pragma-alignment tests pass and op-audit records correct value. Build: tsc clean (exit 0). Smoke: ingest + stats OK, kg_entities schema confirmed (id,name,entity_type,attributes,...), user_version=18. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Verified pre-launch schema/runtime fixes (review swarm lane 3).
kg_entitieswas created without anattributescolumn →kg-extract/kg-buildcrashed (no column named attributes, via index.ts INSERT) on every clean install. Added the column to the CREATE + idempotent ALTER for existing DBs. Confirmed viaPRAGMA table_info(kg_entities).embed.tsused__dirname(undefined in ESM) as the sqlite-vec fallback →ReferenceErrorif the optional dep was missing. Now usesfileURLToPath(import.meta.url).PRAGMA user_versionwas never set (stayed 0) → pragma-alignment test failed, op-audit recorded 0. Now set toSCHEMA_VERSIONat end ofensureSchema.Build clean; ingest+search smoke passed.