56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
/**
|
|
* PostgreSQL configuration using Yup
|
|
*/
|
|
import { cleanEnv, envValidators } from './env-utils';
|
|
|
|
const { str, port, bool, num } = envValidators;
|
|
|
|
/**
|
|
* PostgreSQL configuration with validation and defaults
|
|
*/
|
|
export const postgresConfig = cleanEnv(process.env, {
|
|
// PostgreSQL Connection Settings
|
|
POSTGRES_HOST: str('localhost', 'PostgreSQL host'),
|
|
POSTGRES_PORT: port(5432, 'PostgreSQL port'),
|
|
POSTGRES_DATABASE: str('stockbot', 'PostgreSQL database name'),
|
|
POSTGRES_USERNAME: str('stockbot', 'PostgreSQL username'),
|
|
POSTGRES_PASSWORD: str('', 'PostgreSQL password'),
|
|
|
|
// Connection Pool Settings
|
|
POSTGRES_POOL_MIN: num(2, 'Minimum pool connections'),
|
|
POSTGRES_POOL_MAX: num(10, 'Maximum pool connections'),
|
|
POSTGRES_POOL_IDLE_TIMEOUT: num(30000, 'Pool idle timeout in ms'),
|
|
|
|
// SSL Configuration
|
|
POSTGRES_SSL: bool(false, 'Enable SSL for PostgreSQL connection'),
|
|
POSTGRES_SSL_REJECT_UNAUTHORIZED: bool(true, 'Reject unauthorized SSL certificates'),
|
|
|
|
// Additional Settings
|
|
POSTGRES_QUERY_TIMEOUT: num(30000, 'Query timeout in ms'),
|
|
POSTGRES_CONNECTION_TIMEOUT: num(5000, 'Connection timeout in ms'),
|
|
POSTGRES_STATEMENT_TIMEOUT: num(30000, 'Statement timeout in ms'),
|
|
POSTGRES_LOCK_TIMEOUT: num(10000, 'Lock timeout in ms'),
|
|
POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT: num(60000, 'Idle in transaction timeout in ms'),
|
|
});
|
|
|
|
// Export typed configuration object
|
|
export type PostgresConfig = typeof postgresConfig;
|
|
|
|
// Export individual config values for convenience
|
|
export const {
|
|
POSTGRES_HOST,
|
|
POSTGRES_PORT,
|
|
POSTGRES_DATABASE,
|
|
POSTGRES_USERNAME,
|
|
POSTGRES_PASSWORD,
|
|
POSTGRES_POOL_MIN,
|
|
POSTGRES_POOL_MAX,
|
|
POSTGRES_POOL_IDLE_TIMEOUT,
|
|
POSTGRES_SSL,
|
|
POSTGRES_SSL_REJECT_UNAUTHORIZED,
|
|
POSTGRES_QUERY_TIMEOUT,
|
|
POSTGRES_CONNECTION_TIMEOUT,
|
|
POSTGRES_STATEMENT_TIMEOUT,
|
|
POSTGRES_LOCK_TIMEOUT,
|
|
POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
|
|
} = postgresConfig;
|