feat: add TenantConnectionManager with dynamic pool management

- Adds pg dependency for direct PostgreSQL connections to tenant DBs
- TenantConnectionManager: singleton managing Map<tenantId, Pool>
- provisionDatabase: creates new DB with tables and indexes
- deprovisionDatabase: soft-deletes by renaming DB
- Automatic idle pool cleanup every 60s (5min threshold)
- Max 3 connections per pool (6/tenant with 2 PM2 workers)
- Graceful shutdown support for all pools

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Consultoria AS
2026-03-15 23:17:54 +00:00
parent f96a9c55c5
commit d6b86dbbd3
3 changed files with 323 additions and 0 deletions

View File

@@ -30,6 +30,7 @@
"jsonwebtoken": "^9.0.2",
"node-cron": "^4.2.1",
"node-forge": "^1.3.3",
"pg": "^8.18.0",
"zod": "^3.23.0"
},
"devDependencies": {
@@ -41,6 +42,7 @@
"@types/node": "^22.0.0",
"@types/node-cron": "^3.0.11",
"@types/node-forge": "^1.3.14",
"@types/pg": "^8.18.0",
"prisma": "^5.22.0",
"tsx": "^4.19.0",
"typescript": "^5.3.0"