MCPcopy
hub / github.com/colbymchenry/codegraph / initialize

Method initialize

src/db/index.ts:67–93  ·  view source on GitHub ↗

* Initialize a new database at the given path

(dbPath: string)

Source from the content-addressed store, hash-verified

65 * Initialize a new database at the given path
66 */
67 static initialize(dbPath: string): DatabaseConnection {
68 // Ensure parent directory exists
69 const dir = path.dirname(dbPath);
70 if (!fs.existsSync(dir)) {
71 fs.mkdirSync(dir, { recursive: true });
72 }
73
74 // Create and configure database
75 const { db, backend } = createDatabase(dbPath);
76
77 configureConnection(db);
78
79 // Run schema initialization
80 const schemaPath = path.join(__dirname, 'schema.sql');
81 const schema = fs.readFileSync(schemaPath, 'utf-8');
82 db.exec(schema);
83
84 // Record current schema version so migrations aren't re-applied on open
85 const currentVersion = getCurrentVersion(db);
86 if (currentVersion < CURRENT_SCHEMA_VERSION) {
87 db.prepare(
88 'INSERT OR IGNORE INTO schema_versions (version, applied_at, description) VALUES (?, ?, ?)'
89 ).run(CURRENT_SCHEMA_VERSION, Date.now(), 'Initial schema includes all migrations');
90 }
91
92 return new DatabaseConnection(db, dbPath, backend);
93 }
94
95 /**
96 * Open an existing database

Callers 12

initMethod · 0.45
initSyncMethod · 0.45
recreateMethod · 0.45
indexAllMethod · 0.45
reinitializeResolverMethod · 0.45
security.test.tsFile · 0.45
db-perf.test.tsFile · 0.45
foundation.test.tsFile · 0.45

Calls 7

createDatabaseFunction · 0.90
getCurrentVersionFunction · 0.90
configureConnectionFunction · 0.85
joinMethod · 0.80
execMethod · 0.65
runMethod · 0.65
prepareMethod · 0.65

Tested by

no test coverage detected