refactor(db): split the Postgres client-tool module by concern

pg-tools.ts held six concerns in 366 lines: tool resolution and process
running, the libpq connection environment, the CVE-2025-8714 version policy,
the CLEAR-SCHEMA SQL and the operations themselves. Each now has its own
module, and pg-tools.ts keeps only the operations the backup and the boot
restore call, so their import paths do not change.

- pg-process.ts: PgTool, resolvePgTool, pgConnectionEnv, PgToolMissingError
  and run (stderr is summarized there, as before).
- restore-safety.ts: hasRestrictFix and the refusal. The minimum versions in
  the error are built from the RESTRICT_SINCE table, so the message cannot
  drift from the policy.
- clear-schema.ts: the SQL that empties the schema before a load, unchanged.

The version floor also no longer keeps its own OLDEST_MAJOR and
LAST_MAJOR_WITHOUT_IT constants: both are read from the table. Behaviour is
unchanged. The literal /dev/null is os.devNull, and the COPY parsing of a
dump's migration history is its own function.
This commit is contained in:
Isaias Tavares
2026-11-05 00:20:22 -03:00
parent ae005fc582
commit 1c73ac4c35
5 changed files with 242 additions and 216 deletions
@@ -6,15 +6,9 @@
* refusal when a tool is missing. The real tools against a real database are
* exercised by the Postgres lane.
*/
import {
hasRestrictFix,
pgConnectionEnv,
pgDump,
pgDumpMigrations,
pgRestore,
PgToolMissingError,
resolvePgTool,
} from '../../../../../src/db/engine/postgres/pg-tools';
import { PgToolMissingError, pgConnectionEnv, resolvePgTool } from '../../../../../src/db/engine/postgres/pg-process';
import { pgDump, pgDumpMigrations, pgRestore } from '../../../../../src/db/engine/postgres/pg-tools';
import { hasRestrictFix } from '../../../../../src/db/engine/postgres/restore-safety';
import fs, {
chmodSync,