Fix PostgreSQL SSL configuration for Azure

- Explicitly configure SSL in PostgresAdapter Pool
- Always require SSL for Azure PostgreSQL connections
- Add logging for database connection details
This commit is contained in:
2026-01-22 01:51:20 +01:00
parent b8d7e7a229
commit 71480cedd6
2 changed files with 12 additions and 1 deletions

View File

@@ -30,10 +30,13 @@ export function createDatabaseAdapter(dbType?: string, dbPath?: string, allowClo
const name = process.env.DATABASE_NAME || 'cmdb';
const user = process.env.DATABASE_USER || 'cmdb';
const password = process.env.DATABASE_PASSWORD || '';
const ssl = process.env.DATABASE_SSL === 'true' ? '?sslmode=require' : '';
// Azure PostgreSQL requires SSL - always use sslmode=require for Azure
const isAzure = host.includes('.postgres.database.azure.com');
const ssl = (process.env.DATABASE_SSL === 'true' || isAzure) ? '?sslmode=require' : '';
const constructedUrl = `postgresql://${user}:${password}@${host}:${port}/${name}${ssl}`;
logger.info('Creating PostgreSQL adapter with constructed connection string');
logger.info(`Database: ${name}, SSL: ${ssl ? 'required' : 'not required'}`);
return new PostgresAdapter(constructedUrl, allowClose);
}