小编Jos*_*rro的帖子

生成迁移时如何从机密存储动态添加 TypeOrm 配置?

我正在尝试与 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)

node.js typescript typeorm

6
推荐指数
0
解决办法
819
查看次数

标签 统计

node.js ×1

typeorm ×1

typescript ×1