我正在尝试与 TypeOrm 建立 postgres 连接,该连接从机密源(异步)动态提取配置并生成新的迁移。
我尝试使用 async await 异步设置环境变量和局部变量,当 typeorm-cli 运行时,postgres.config.ts 文件将使用这些变量,但我不断收到错误消息。
// src/config/defaults/postgres.config.ts
const postgresConfig = (async () => {
try {
const db: PostgresConfig = await secretsSource.getSecret();
return {
type: 'postgres',
host: db.host,
port: db.port,
username: db.username,
password: db.password,
database: db.database,
entities: [path.join(__dirname, '../**/*.entity{.ts,.js}')],
migrationsRun: true,
logging: true,
logger: 'file',
migrations: [path.join(__dirname, '../migrations/**/*{.ts,.js}')],
cli: {
migrationsDir: 'src/migrations',
},
} as ConnectionOptions;
} catch (error) {
// ... handle error
}
})();
export default postgresConfig;
// package.json
{
scripts: …Run Code Online (Sandbox Code Playgroud)