refactor(schema): consolidate schema definition to single source of truth

This commit is contained in:
2026-04-15 08:10:39 -04:00
parent dfd61f899a
commit ac343a5477
5 changed files with 57 additions and 58 deletions

View File

@@ -15,27 +15,10 @@ import { existsSync } from "node:fs";
import { join } from "node:path";
import Database from "better-sqlite3";
const SCHEMA = `-- .codexis/index.db schema:
--
-- files: indexed source files
-- id INTEGER PRIMARY KEY
-- path TEXT NOT NULL UNIQUE -- relative to repo root
-- language TEXT NOT NULL -- e.g. 'go', 'typescript', 'python', 'tsx', 'proto'
-- package TEXT -- package/module name (from AST or directory)
-- hash TEXT NOT NULL -- sha256, for incremental indexing
-- indexed_at DATETIME
--
-- symbols: definitions extracted via tree-sitter
-- id INTEGER PRIMARY KEY
-- file_id INTEGER NOT NULL REFERENCES files(id)
-- name TEXT NOT NULL
-- kind TEXT NOT NULL -- one of: 'function','method','class','type','interface','constant','variable','constructor'
-- line INTEGER NOT NULL -- 1-indexed
-- line_end INTEGER -- end of definition body
-- col INTEGER
-- col_end INTEGER
-- exported BOOLEAN -- language-specific visibility
-- parent_id INTEGER REFERENCES symbols(id) -- e.g. method→class, field→struct`;
// @ts-expect-error - generated file
import schema from "./schema.sql?raw";
const SCHEMA = schema;
const DESCRIPTION = `Query the code index database (.codexis/index.db). Run read-only SQL to find symbols, files, and line numbers across the codebase.

34
extension/schema.sql Normal file
View File

@@ -0,0 +1,34 @@
-- CREATE TABLE files (
-- id INTEGER PRIMARY KEY,
-- path TEXT NOT NULL UNIQUE,
-- language TEXT NOT NULL,
-- package TEXT,
-- hash TEXT NOT NULL,
-- indexed_at DATETIME DEFAULT CURRENT_TIMESTAMP
-- );
--
-- CREATE TABLE symbols (
-- id INTEGER PRIMARY KEY,
-- file_id INTEGER NOT NULL REFERENCES files(id) ON DELETE CASCADE,
-- name TEXT NOT NULL,
-- kind TEXT NOT NULL CHECK(kind IN (
-- 'function', 'method', 'class', 'type',
-- 'interface', 'constant', 'variable', 'constructor'
-- )),
-- line INTEGER NOT NULL,
-- line_end INTEGER,
-- col INTEGER,
-- col_end INTEGER,
-- exported BOOLEAN,
-- parent_id INTEGER REFERENCES symbols(id),
-- UNIQUE(file_id, name, kind, line)
-- );
--
-- CREATE INDEX idx_symbols_name ON symbols(name);
-- CREATE INDEX idx_symbols_kind ON symbols(kind);
-- CREATE INDEX idx_symbols_file_line ON symbols(file_id, line);
-- CREATE INDEX idx_symbols_parent ON symbols(parent_id);
-- CREATE INDEX idx_symbols_exported ON symbols(exported, kind);
-- CREATE INDEX idx_files_path ON files(path);
-- CREATE INDEX idx_files_language ON files(language);
-- CREATE INDEX idx_files_package ON files(package);