Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(db): open the move's SQLite source through openDatabase, keep the drop failure as the cause

Maurice5316362e9ea8
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<object>, cause: unknown): Promise<void> {
+async function emptyAgain(db: Kysely<object>, failure: unknown): Promise<void> {
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<typeof openDatabase>;
+
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');