Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using TypeORM migrations, how do I specify a particular connection?

I'm using TypeORM and trying to run a migration on a test connection. In my ormconfig.json, I specify two separate connections as follows:

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

How do I specify the connection with name test from the TypeORM CLI? I'm trying things like:

typeorm migrations:run -c test

but I'm not having any luck. Is there a better way to do this?

like image 557
Blake Avatar asked Apr 26 '18 03:04

Blake


1 Answers

Though you said you weren't having luck with that, that's exactly what I do. Perhaps some supporting information will help. My exact migration command looks like this (I'm using TypeScript and so I'm running things through ts-node first):

$(npm bin)/ts-node $(npm bin)/typeorm migration:run -c test

in my ormconfig.json, I've specified that there's a default and test connection, just like yours.

Perhaps it's as simple as saying "migration" rather than "migrations" like you have? When I use "migrations" I just get the help information printed out. Is that what you're seeing?

like image 52
Chris Avatar answered Sep 28 '22 23:09

Chris