TypeORM CLI - 如何 运行 特定数据库上的迁移
TypeORM CLI - How to run MIGRATIONS on a SPECIFIC DATABASE
我的ormconfig.json
有多个数据库,如何运行迁移这个列表的特定数据库?在下面的示例中,我已经设置了迁移的 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"
}
}
]
就运行:
yarn typeorm migration:run -c configName
其中 configName 是 ormconfig.json
数据库列表中配置的 name
。
我的ormconfig.json
有多个数据库,如何运行迁移这个列表的特定数据库?在下面的示例中,我已经设置了迁移的 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"
}
}
]
就运行:
yarn typeorm migration:run -c configName
其中 configName 是 ormconfig.json
数据库列表中配置的 name
。