首页 > 解决方案 > TypeORM CLI - 如何在特定数据库上运行迁移

问题描述

ormconfig.json有多个数据库,如何为此列表的特定数据库运行迁移?在下面的示例中,我dev已经设置了迁移的数据库,现在我需要为另一个名为test.

我想运行这样的命令:

yarn typeorm migration:run --database test

// ormconfig.json

[
  {
    "name": "dev",
    "type": "postgres",
    "host": "localhost",
    "port": 5432,
    "username": "postgres",
    "password": "postgres",
    "database": "postgres",
    "synchronize": true,
    "logging": true,
    "entities": ["src/typeorm/entity/**/*.ts"],
    "migrations": ["src/typeorm/migration/**/*.ts"],
    "subscribers": ["src/typeorm/subscriber/**/*.ts"],
    "cli": {
      "entitiesDir": "src/typeorm/entity",
      "migrationsDir": "src/typeorm/migration",
      "subscribersDir": "src/typeorm/subscriber"
    }
  },
  {
    "name": "test",
    "type": "postgres",
    "host": "localhost",
    "port": 5433,
    "username": "postgres",
    "password": "postgres",
    "database": "postgres",
    "synchronize": true,
    "logging": false,
    "entities": ["src/typeorm/entity/**/*.ts"],
    "migrations": ["src/typeorm/migration/**/*.ts"],
    "subscribers": ["src/typeorm/subscriber/**/*.ts"],
    "cli": {
      "entitiesDir": "src/typeorm/entity",
      "migrationsDir": "src/typeorm/migration",
      "subscribersDir": "src/typeorm/subscriber"
    }
  }
]

标签: postgresqlormtypeormnode.js-typeorm

解决方案


赶紧跑:

yarn typeorm migration:run -c configName其中 configName 是name您的ormconfig.json数据库列表中的配置。


推荐阅读