Home > Software engineering >  TypeORM CLI - How to run MIGRATIONS on a SPECIFIC DATABASE
TypeORM CLI - How to run MIGRATIONS on a SPECIFIC DATABASE

Time:10-21

My ormconfig.json has multiple DBs, how to run migrations for a SPECIFIC DB of this list? In the example below I have the dev db with migrations already set, now I need to set migrations for the other db called test.

I wanted to run a command like this:

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

CodePudding user response:

Just run:

yarn typeorm migration:run -c configName where configName is the name of the configuration in your ormconfig.json db list.

  • Related