我正在使用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"
}
}]
如何从typeorm CLI指定名称为test
的连接?我尝试过这样的事情:
typeorm migrations:run -c test
但我没有运气。有更好的方法吗?
答案 0 :(得分:5)
虽然你说你没有运气,但这正是我所做的。也许一些支持信息会有所帮助。我的确切迁移命令看起来像这样(我正在使用TypeScript,所以我先通过ts-node
运行):
$(npm bin)/ts-node $(npm bin)/typeorm migration:run -c test
在我的ormconfig.json
中,我已经指定了默认和测试连接,就像你的一样。
也许这就像说“迁移”而不是像你那样的“迁移”一样简单?当我使用“迁移”时,我只是打印出帮助信息。这就是你所看到的吗?