feat(db): integrate PostgreSQL into factory, config, and TypeORM data source

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-04-05 10:29:57 +08:00
parent 16b2882729
commit 54a3ac680a
4 changed files with 70 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
* TypeORM Data Source Configuration
*
* Provides a centralized database connection for TypeORM entities.
* Supports both MySQL and SQL Server based on configuration.
* Supports MySQL, SQL Server, and PostgreSQL based on configuration.
*
* Note: Configuration is now loaded from config.yaml via ConfigManager,
* not from environment variables.
@@ -18,10 +18,14 @@ const log = createLogger('DataSource')
/**
* Get database type from config manager
*/
function getDatabaseType(): 'mysql' | 'mssql' {
function getDatabaseType(): 'mysql' | 'mssql' | 'postgres' {
const configManager = ConfigManager.getInstance()
const dbType = configManager.getDatabaseType()
return dbType === 'sqlserver' ? 'mssql' : 'mysql'
switch (dbType) {
case 'sqlserver': return 'mssql'
case 'postgresql': return 'postgres'
default: return 'mysql'
}
}
/**
@@ -54,6 +58,17 @@ function buildDataSourceOptions(): DataSourceOptions {
},
...commonOptions
} as DataSourceOptions
} else if (type === 'postgres') {
const dbConfig = config.database.postgresql
return {
type: 'postgres',
host: dbConfig.host,
port: dbConfig.port,
username: dbConfig.username,
password: dbConfig.password,
database: dbConfig.database,
...commonOptions
} as DataSourceOptions
}
const dbConfig = config.database.mysql