За хора, които искат да изпълняват миграции с цел тестване:НЕ в производствена среда.
import {
createConnection,
ConnectionOptions,
Connection,
} from 'typeorm';
import { YourEntity } from 'path/to/your/entity.ts';
const testConfig: ConnectionOptions = {
type: 'mongodb',
url: 'mongodb://localhost:27017',
database: 'test',
useUnifiedTopology: true,
entities: [YourEntity],
synchronize: true,
migrations: ['migrations/*YourMigrations.ts'],
};
let connection: Connection;
connection = await createConnection({ ...testConfig });
await connection.synchronize(true);
await connection.runMigrations({
transaction: 'all',
});
Стартирайте с:
node -r ts-node/register ./path/to/migrations.ts
или
node ./path/to/compiled/migrations.js