fix(db): rotate the encryption key on Postgres through the server's engine

The rotation ran on the SQLite file only and refused when TREK_DB_URL was
set. Its statements now go through a small store per engine: better-sqlite3
for the file, unchanged, and on Postgres the server's own MikroORM
connection, in one transaction that takes the engine's write lock first. The
Postgres path checks that it reaches a database holding TREK's tables and
that the data directory is writable before it asks for a key, writes a
pg_dump copy before it changes anything, refuses DB_PATH or TREK_DB_FILE
beside the URL, and reads the jsonb addon config the driver hands back
parsed. The SQLite transaction is now BEGIN IMMEDIATE, since better-sqlite3
takes no async function.
This commit is contained in:
Maurice
2026-11-17 13:54:25 +01:00
parent 4eb2c3be58
commit 7065f87dc0
5 changed files with 841 additions and 553 deletions
+1 -1
View File
@@ -4,5 +4,5 @@
"rootDir": ".",
"noEmit": true
},
"include": ["scripts/generate-entities.ts", "scripts/generate-db-types.ts", "scripts/generate-pg-baseline.ts", "scripts/generate-pg-migration.ts", "scripts/migrate-encryption.ts", "scripts/pg-probe.ts", "scripts/pg-probe/*.ts"]
"include": ["scripts/generate-entities.ts", "scripts/generate-db-types.ts", "scripts/generate-pg-baseline.ts", "scripts/generate-pg-migration.ts", "scripts/migrate-encryption.ts", "scripts/migrate-encryption-stores.ts", "scripts/pg-probe.ts", "scripts/pg-probe/*.ts"]
}