Database migration 使用tyeporm迁移,如何指定特定连接?
我正在使用typeorm并尝试在测试连接上运行迁移。在我的ormconfig.json中,我指定了两个独立的连接,如下所示:Database migration 使用tyeporm迁移,如何指定特定连接?,database-migration,typeorm,Database Migration,Typeorm,我正在使用typeorm并尝试在测试连接上运行迁移。在我的ormconfig.json中,我指定了两个独立的连接,如下所示: [{ "name": "default", "type": "postgres", "host": "localhost", "port": 5432, "username": "username", "password": "", "database": "database", "entities": [ "build/entit
[{
"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节点运行):
在我的或mconfig.json
中,我指定了一个默认和测试连接,就像您的一样
也许这就像说“迁移”一样简单,而不是像你所说的“迁移”?当我使用“迁移”时,我只是将帮助信息打印出来。这就是你看到的吗?这正是我的问题。只是一个打字错误让我如此伤心。谢谢你的回复!这也是我遇到的一个问题,typeorm没有读取我的或mconfig.ts
,我必须使用$(npm bin)/typeorm
路径才能工作。
$(npm bin)/ts-node $(npm bin)/typeorm migration:run -c test