@@ -28,6 +28,7 @@ import type {
2828 Kysely ,
2929 QueryCompiler ,
3030 QueryResult ,
31+ TransactionSettings ,
3132} from "kysely" ;
3233
3334import type { Database } from "../database/types.js" ;
@@ -108,8 +109,8 @@ class LazyMigrationDriver implements Driver {
108109 return new LazyMigrationConnection ( conn , this . #dialect) ;
109110 }
110111
111- async beginTransaction ( conn : DatabaseConnection ) : Promise < void > {
112- return this . #inner. beginTransaction ( conn ) ;
112+ async beginTransaction ( conn : DatabaseConnection , settings : TransactionSettings ) : Promise < void > {
113+ return this . #inner. beginTransaction ( conn , settings ) ;
113114 }
114115
115116 async commitTransaction ( conn : DatabaseConnection ) : Promise < void > {
@@ -146,14 +147,14 @@ class LazyMigrationConnection implements DatabaseConnection {
146147 migrationsRun = true ;
147148 // Create a fresh Kysely instance for migration using the inner
148149 // dialect (unwrapped) to avoid infinite retry loops.
150+ // Do NOT destroy() this instance: its driver shares the underlying
151+ // connection/handle (e.g. better-sqlite3 Database) with the outer
152+ // Kysely, and destroy() would close it. The instance is released
153+ // to GC instead.
149154 const { Kysely } = await import ( "kysely" ) ;
150155 const db = new Kysely < Database > ( { dialect : this . #dialect } ) ;
151- try {
152- const { runMigrations } = await import ( "../database/migrations/runner.js" ) ;
153- await runMigrations ( db ) ;
154- } finally {
155- await db . destroy ( ) ;
156- }
156+ const { runMigrations } = await import ( "../database/migrations/runner.js" ) ;
157+ await runMigrations ( db ) ;
157158 // Retry the original query
158159 return this . #inner. executeQuery ( compiledQuery ) ;
159160 }
0 commit comments