使用tyeporm迁移,如何指定特定的连接?

Bla*_*ake 3 database-migration typeorm

我正在使用typeorm并尝试在测试连接上运行迁移。在我的ormconfig.json文件中,我指定了两个单独的连接,如下所示:

[{
  "name": "default",
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "username",
  "password": "",
  "database": "database",
  "entities": [
    "build/entity/**/*.js"
  ],
  "migrations": [
    "build/migration/**/*.js"
  ],
  "synchronize": false,
  "autoSchemaSync": true,
  "logging": false,
  "cli": {
    "migrationsDir": "src/migration",
    "entitiesDir": "src/entity",
    "subscribersDir": "src/subscriber"
  }
},
{
  "name": "test",
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "username",
  "password": "",
  "database": "database-test",
  "entities": [
    "build/entity/**/*.js"
  ],
  "migrations": [
    "build/migration/**/*.js"
  ],
  "synchronize": false,
  "autoSchemaSync": true,
  "logging": false,
  "cli": {
    "migrationsDir": "src/migration",
    "entitiesDir": "src/entity",
    "subscribersDir": "src/subscriber"
  }
}]
Run Code Online (Sandbox Code Playgroud)

如何test从typeorm CLI中使用名称指定连接?我正在尝试类似的事情:

typeorm migrations:run -c test
Run Code Online (Sandbox Code Playgroud)

但我没有运气。有一个更好的方法吗?

Chr*_*ris 5

尽管您说自己没有运气,但这正是我所做的。也许一些支持信息会有所帮助。我的确切迁移命令如下所示(我正在使用TypeScript,因此ts-node首先要进行一些操作):

$(npm bin)/ts-node $(npm bin)/typeorm migration:run -c test
Run Code Online (Sandbox Code Playgroud)

在我的中ormconfig.json,我已指定有一个默认连接和测试连接,就像您的连接一样。

也许只是说“迁移”而不是像您说的“迁移”那样简单?当我使用“迁移”时,我只会打印出帮助信息。那是你看到的吗?