fix(scripts): read the server's .env in the admin reset and the key rotation

Both scripts now load server/.env as the server does, so an install whose TREK_DB_URL lives there resets the admin and rotates the key in its Postgres database instead of in a SQLite file left behind by the move.
This commit is contained in:
Maurice
2026-11-23 15:02:04 +01:00
parent de1c3b8ea6
commit 52a6fbbc92
3 changed files with 48 additions and 0 deletions
+3
View File
@@ -32,6 +32,7 @@ import { MikroORM } from '@mikro-orm/core';
import Database from 'better-sqlite3';
import crypto from 'crypto';
import { config as loadDotenv } from 'dotenv';
import fs from 'fs';
import path from 'path';
import readline from 'readline';
@@ -861,6 +862,8 @@ async function mainPostgres(): Promise<void> {
}
async function main() {
// The server reads its .env too (index.ts), so TREK_DB_URL kept there picks the same database here.
loadDotenv({ path: path.join(__dirname, '../.env'), quiet: true });
openPrompts();
console.log('=== TREK Encryption Key Migration ===\n');
console.log('This script re-encrypts all stored secrets under a new ENCRYPTION_KEY.');