【问题标题】:TypeORM CLI - How to run MIGRATIONS on a SPECIFIC DATABASETypeORM CLI - 如何在特定数据库上运行迁移
【发布时间】:2021-10-20 22:41:51
【问题描述】:

我的ormconfig.json 有多个数据库,如何为这个列表的SPECIFIC DB 运行迁移?在下面的示例中,我已经设置了迁移的 dev 数据库,现在我需要为名为 test 的另一个数据库设置迁移。

我想运行这样的命令:

yarn typeorm migration:run --database test

// ormconfig.json

[
  {
    "name": "dev",
    "type": "postgres",
    "host": "localhost",
    "port": 5432,
    "username": "postgres",
    "password": "postgres",
    "database": "postgres",
    "synchronize": true,
    "logging": true,
    "entities": ["src/typeorm/entity/**/*.ts"],
    "migrations": ["src/typeorm/migration/**/*.ts"],
    "subscribers": ["src/typeorm/subscriber/**/*.ts"],
    "cli": {
      "entitiesDir": "src/typeorm/entity",
      "migrationsDir": "src/typeorm/migration",
      "subscribersDir": "src/typeorm/subscriber"
    }
  },
  {
    "name": "test",
    "type": "postgres",
    "host": "localhost",
    "port": 5433,
    "username": "postgres",
    "password": "postgres",
    "database": "postgres",
    "synchronize": true,
    "logging": false,
    "entities": ["src/typeorm/entity/**/*.ts"],
    "migrations": ["src/typeorm/migration/**/*.ts"],
    "subscribers": ["src/typeorm/subscriber/**/*.ts"],
    "cli": {
      "entitiesDir": "src/typeorm/entity",
      "migrationsDir": "src/typeorm/migration",
      "subscribersDir": "src/typeorm/subscriber"
    }
  }
]

【问题讨论】:

    标签: postgresql orm typeorm node.js-typeorm


    【解决方案1】:

    只要运行:

    yarn typeorm migration:run -c configName 其中 configName 是您的 ormconfig.json 数据库列表中配置的 name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 2021-04-29
      • 2016-11-24
      • 1970-01-01
      • 2015-11-11
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多