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

15
pnpm-lock.yaml generated
View File

@@ -68,6 +68,9 @@ importers:
node-forge:
specifier: ^1.3.3
version: 1.3.3
pg:
specifier: ^8.18.0
version: 8.18.0
zod:
specifier: ^3.23.0
version: 3.25.76
@@ -96,6 +99,9 @@ importers:
'@types/node-forge':
specifier: ^1.3.14
version: 1.3.14
'@types/pg':
specifier: ^8.18.0
version: 8.18.0
prisma:
specifier: ^5.22.0
version: 5.22.0
@@ -1106,6 +1112,9 @@ packages:
'@types/pako@2.0.4':
resolution: {integrity: sha512-VWDCbrLeVXJM9fihYodcLiIv0ku+AlOa/TQ1SvYOaBuyrSKgEcro95LJyIsJ4vSo6BXIxOKxiJAat04CmST9Fw==}
'@types/pg@8.18.0':
resolution: {integrity: sha512-gT+oueVQkqnj6ajGJXblFR4iavIXWsGAFCk3dP4Kki5+a9R4NMt0JARdk6s8cUKcfUoqP5dAtDSLU8xYUTFV+Q==}
'@types/prop-types@15.7.15':
resolution: {integrity: sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==}
@@ -3369,6 +3378,12 @@ snapshots:
'@types/pako@2.0.4': {}
'@types/pg@8.18.0':
dependencies:
'@types/node': 22.19.7
pg-protocol: 1.11.0
pg-types: 2.2.0
'@types/prop-types@15.7.15': {}
'@types/qs@6.14.0': {}