After the new typeorm release I am having some troubles to work with migrations.
Some time ago I was using this code and it worked -
entities: ['./src/modules/**/infra/typeorm/entities/*.ts'],
migrations: ['./src/shared/infra/typeorm/migrations/*.ts'],
cli: {
migrationsDir: './src/shared/infra/typeorm/migrations'
}
But now I can't specify the CLI property. To create a new migration, I have to specify the entire migration path -
npm run typeorm migration:create ./src/database/migrations -n SomeTest
Is there another way to do that without specifying the entire path?
Create ormconfig.ts
import { DataSource } from 'typeorm';
export const AppDataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'password',
database: 'postgres',
entities: ['dist/**/*.entity.js'],
logging: true,
synchronize: false,
migrationsRun: false,
migrations: ['dist/**/migrations/*.js'],
migrationsTableName: 'history',
});
Install "cross-var" package Add commands in your package.json file
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli -d ormconfig.ts",
"migration:create": "cross-var ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:create ./src/migrations/$npm_config_name",
"migration:generate": "cross-var npm run typeorm -- migration:generate ./src/migrations/$npm_config_name",
"migration:run": "npm run build && npm run typeorm -- migration:run",
"migration:revert": "npm run typeorm -- migration:revert"
Example command
"npm run migration:create --name=Test1"
Look this project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With