database-migration - 使用 tyeporm 迁移,如何指定特定连接?

标签 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"
  }
}]

如何从 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/

相关文章:

sql-server - 将数据从 DB2 迁移到 SQL Server - DB2 端需要什么?

postgresql - 如何在 TypeORM 中定义 varchar 和 enum?

mongodb - TypeOrm findOne 抛出 'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'

.net - 处理数据库模式中的更改

MySQL 数据库迁移和同步

node.js - 尽管存在数据,但在 GraphQL 查询中日期字段返回为 null

postgresql - TypeORM 找不到\"MyEntity\"的元数据

postgresql - 如果我从 typeorm 迁移表中删除一条记录会怎样?

ruby-on-rails-4 - 将 rake 版本从 10.1.1 降级到 10.1.0

ruby-on-rails - Rails 如何知道迁移正在等待中?