diff --git a/server/src/db/engine/postgres/sqlite-move/move.ts b/server/src/db/engine/postgres/sqlite-move/move.ts index de6543674..8cf836049 100644 --- a/server/src/db/engine/postgres/sqlite-move/move.ts +++ b/server/src/db/engine/postgres/sqlite-move/move.ts @@ -256,15 +256,15 @@ async function copyAll( * empty before it, so everything in its schema is the move's). When even that * fails, the error says so, since the database then needs dropping by hand. */ -async function emptyAgain(db: Kysely, cause: unknown): Promise { +async function emptyAgain(db: Kysely, failure: unknown): Promise { try { await run(db, CLEAR_SCHEMA_SQL); } catch (err) { throw new Error( - `The move failed (${cause instanceof Error ? cause.message : String(cause)}), and the schema it had created ` + + `The move failed (${failure instanceof Error ? failure.message : String(failure)}), and the schema it had created ` + `could not be dropped (${err instanceof Error ? err.message : String(err)}). Drop the Postgres database and ` + 'create it again before the next attempt.', - { cause }, + { cause: err }, ); } } diff --git a/server/src/db/engine/sqlite/sqlite-source.ts b/server/src/db/engine/sqlite/sqlite-source.ts index 46a80cd5c..00df8709f 100644 --- a/server/src/db/engine/sqlite/sqlite-source.ts +++ b/server/src/db/engine/sqlite/sqlite-source.ts @@ -1,4 +1,5 @@ -import Database from 'better-sqlite3'; +import { openDatabase } from '../../connection'; + import fs from 'node:fs'; /** @@ -46,9 +47,12 @@ function quoteSqliteIdentifier(name: string): string { return `"${name.replaceAll('"', '""')}"`; } +/** A handle as `openDatabase` gives it: the driver itself stays behind src/db/connection.ts. */ +type SqliteHandle = ReturnType; + export class SqliteSource { private constructor( - private readonly db: Database.Database, + private readonly db: SqliteHandle, readonly file: string, ) {} @@ -58,7 +62,7 @@ export class SqliteSource { */ static open(file: string): SqliteSource { if (!fs.existsSync(file)) throw new Error(`There is no SQLite file at ${file}.`); - const db = new Database(file, { readonly: true, fileMustExist: true }); + const db = openDatabase(file, { readonly: true, fileMustExist: true }); try { db.defaultSafeIntegers(true); db.exec('BEGIN');