games_app/backend/src/scripts/rotateEncryptionKey.ts
2026-07-07 15:03:17 +02:00

25 lines
828 B
TypeScript

/**
* CLI: re-encrypt database secrets with the current ENCRYPTION_KEY.
* Usage:
* 1. Set ENCRYPTION_KEY_PREVIOUS to the old key
* 2. Set ENCRYPTION_KEY to the new key
* 3. npm run rotate-encryption-key
*/
import { rotateAllEncryptedData } from '../services/encryptionRotationService';
import { recordEncryptionKeyRotatedAt } from '../services/encryptionRotationReminderService';
async function main(): Promise<void> {
const stats = await rotateAllEncryptedData();
await recordEncryptionKeyRotatedAt();
console.log('[rotate-encryption-key] Completed:', stats);
console.log(
'Remove ENCRYPTION_KEY_PREVIOUS from the environment after verifying the application.'
);
}
main().catch((e) => {
console.error('[rotate-encryption-key] Failed:', e instanceof Error ? e.message : e);
process.exit(1);
});