Recently, I embarked on a project using NX (Nest.js + Angular) and set up TypeORM for database configuration. While everything runs smoothly in "serve" mode, I found myself struggling with configuring migrations.
In a typical Nest.js project, all files in the dist directory mirror the project's structure, including migrations. With TypeORM properly configured, setting the migrationsRun flag to true should trigger migrations upon app startup.
The issue arises with NX utilizing webpack, which consolidates everything into a single main.js file within the dist folder, omitting migration files.
My query now is: what would be the most effective approach to resolve this hurdle? Is tweaking webpack settings the best solution, or are there alternative methods worth exploring?
Below is an outline of my project's structure:
project/
├─ apps/
│ ├─ api/
│ │ ├─ src/
│ │ │ ├─ config/
│ │ │ │ ├─ database/
│ │ │ │ │ ├─ typeorm.config.ts
│ │ │ ├─ database/
│ │ │ │ ├─ migrations/
| | | | | ├─ 1668904379611-SomeMigration.ts
├─ dist/
│ ├─ apps/
│ │ ├─ api/
│ │ │ ├─ main.js
typeorm.config.ts
host: process.env.MYSQL_HOST,
port: +process.env.MYSQL_PORT,
username: process.env.MYSQL_USER,
database: process.env.MYSQL_DATABASE,
password: process.env.MYSQL_PASSWORD,
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
migrations: [__dirname + '/../../**/database/migrations/*{.ts,.js}'],
extra: {
charset: 'utf8mb4_unicode_ci',
},
synchronize: false,
migrationsRun: true,
logging: true,
autoLoadEntities: true,
//edit
After further investigation, it appears that the issue lies with Webpack itself rather than NX directly. Webpack bundles all files into one main.js file.