我正在使用 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
但我没有任何运气。有一个更好的方法吗?
最佳答案
虽然你说你运气不好,但这正是我所做的。也许一些支持信息会有所帮助。我的确切迁移命令如下所示(我使用的是 TypeScript,所以我首先通过 ts-node
运行):
$(npm bin)/ts-node $(npm bin)/typeorm migration:run -c test
在我的
ormconfig.json
中,我已经指定有一个默认连接和测试连接,就像你的一样。也许就像说“迁移”而不是像您所说的“迁移”一样简单?当我使用“迁移”时,我只会打印出帮助信息。这是你看到的吗?
关于database-migration - 使用 tyeporm 迁移,如何指定特定连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50034430/