fix(db): fail plugin-data erasure on errors other than a missing table

deletePluginUserData swallowed every error from its three DELETEs, so a
lost connection or a refused statement on Postgres looked like success
and left the user's plugin rows behind. It now skips only a table that
does not exist, the case its comment described (a slimmed-down schema),
and rethrows anything else. The missing-table test moves to
isMissingTableError in migration-utils, which already decided this for
the migrations: the ORM maps SQLite's "no such table" and Postgres's
42P01 to TableNotFoundException. The docstring keeps the intent and drops
the plan history.
This commit is contained in:
Isaias Tavares
2026-11-05 01:15:15 -03:00
parent 1551f6d474
commit 2318308674
3 changed files with 43 additions and 49 deletions
+11 -3
View File
@@ -80,12 +80,20 @@ export async function execUnlessTableMissing(migration: Migration, sql: string,
try {
await migration.execute(sql, params);
} catch (err: unknown) {
const missing =
err instanceof TableNotFoundException || (err instanceof Error && err.message.includes('no such table'));
if (!missing) throw err;
if (!isMissingTableError(err)) throw err;
}
}
/**
* True when a statement failed because its table does not exist. The ORM maps
* SQLite's "no such table" and Postgres's SQLSTATE 42P01 to
* `TableNotFoundException`; the raw SQLite message is checked too, for an error
* that reached the caller unconverted.
*/
export function isMissingTableError(err: unknown): boolean {
return err instanceof TableNotFoundException || (err instanceof Error && err.message.includes('no such table'));
}
/**
* Runs a group of statements the legacy step wrapped in a single swallowing
* try/catch. A failure part-way through leaves the earlier statements applied,