@@ -6,7 +6,7 @@ import { type Plugin, type DatabaseExtension } from '../plugin-system/types'; //
66import { getDbConfig , saveDbConfig , type DbConfig , type SQLiteConfig } from './config' ;
77
88// Schema Definitions
9- import { baseTableDefinitions , pluginTableDefinitions as inputPluginTableDefinitions } from './schema' ;
9+ import { /* baseTableDefinitions, */ pluginTableDefinitions as inputPluginTableDefinitions } from './schema' ;
1010
1111// Drizzle SQLite
1212import { drizzle as drizzleSqliteAdapter , type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3' ;
@@ -36,11 +36,12 @@ function getColumnBuilder(type: 'text' | 'integer' | 'timestamp') {
3636 throw new Error ( `Unsupported column type ${ type } ` ) ;
3737}
3838
39+ import * as staticSchema from './schema.sqlite' ;
40+
3941function generateSchema ( ) : AnySchema {
4042 // Import the static schema instead of generating it dynamically
4143 // This avoids SQL syntax errors caused by dynamic schema generation
42- const staticSchema = require ( './schema.sqlite' ) ;
43- const generatedSchema = { ...staticSchema } ;
44+ const generatedSchema : AnySchema = { ...staticSchema } ;
4445
4546 // Add plugin tables to the static schema
4647 for ( const [ tableName , tableColumns ] of Object . entries ( inputPluginTableDefinitions ) ) {
@@ -60,7 +61,7 @@ function generateSchema(): AnySchema {
6061 return generatedSchema ;
6162}
6263
63- async function ensureMigrationsTable ( _db : AnyDatabase ) { // db param not used due to raw exec
64+ async function ensureMigrationsTable ( ) { // db param not used due to raw exec
6465 const createTableQuery = `
6566 CREATE TABLE IF NOT EXISTS ${ MIGRATIONS_TABLE_NAME } (
6667 id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -72,7 +73,7 @@ async function ensureMigrationsTable(_db: AnyDatabase) { // db param not used du
7273 ( dbConnection as SqliteDriver . Database ) . exec ( createTableQuery ) ;
7374}
7475
75- async function applyMigrations ( db : AnyDatabase ) {
76+ async function applyMigrations ( ) {
7677 const projectRootMigrationsDir = path . join ( process . cwd ( ) , 'drizzle' ) ;
7778
7879 // fs.stat is async with fs/promises, so await it or use fs.existsSync
@@ -93,7 +94,7 @@ async function applyMigrations(db: AnyDatabase) {
9394 }
9495
9596 console . log ( `[INFO] Checking for new migrations in ${ migrationsPath } ...` ) ;
96- await ensureMigrationsTable ( db ) ;
97+ await ensureMigrationsTable ( ) ;
9798
9899 let appliedMigrations : { name : string } [ ] = [ ] ;
99100 const selectAppliedQuery = `SELECT migration_name as name FROM ${ MIGRATIONS_TABLE_NAME } ` ;
@@ -173,7 +174,7 @@ export async function initializeDatabase(): Promise<boolean> {
173174 if ( ! dbExists ) console . log ( `[INFO] SQLite database created at: ${ absoluteDbPath } ` ) ;
174175
175176 if ( dbInstance ) { // Ensure dbInstance is not null
176- await applyMigrations ( dbInstance ) ;
177+ await applyMigrations ( ) ;
177178 } else {
178179 throw new Error ( "Database instance could not be created." ) ;
179180 }
@@ -284,7 +285,7 @@ export function registerPluginTables(plugins: Plugin[]) {
284285 }
285286}
286287
287- export async function createPluginTables ( _db : AnyDatabase , plugins : Plugin [ ] ) { // db param not used
288+ export async function createPluginTables ( plugins : Plugin [ ] ) { // db param not used
288289 console . log ( '[INFO] Attempting to create plugin tables (Note: Better handled by migrations)...' ) ;
289290 if ( ! currentDbConfig ) {
290291 console . error ( "[ERROR] Cannot create plugin tables: DB config unknown." ) ;
0 commit comments