nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

Including TypeORM migration in monorepo application #13106

Closed asijoumi closed 7 months ago

asijoumi commented 7 months ago

Is there an existing issue for this?

Current behavior

Hi !

I have an issue using NestJS + TypeORM with migration.

I use NestJS as a monorepo. I have my public api, batch for scheduled process. And I have 2 libs : config and database.

In database, there are the entities and the migrations. When I want to start the API, the entities are "compiled" into the dist folder, but not the migration.

PS : webpack is not used here.

With npm run build I have :

Capture d’écran 2024-01-28 à 14 37 06

But, when I run npm run build database :

Capture d’écran 2024-01-28 à 14 38 26

I don't understand why the migration are compiled with database but not with the api ..

Minimum reproduction code

https://github.com/asijoumi/nest-issue-typeorm

Steps to reproduce

  1. npm run build
  2. npm run build database

Expected behavior

We should have migration .js files in dist folder.

Package

Other package

@nestjs/typeorm

NestJS version

10.0.0

Packages versions

{
  "name": "app",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/apps/app/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./apps/app/test/jest-e2e.json",
    "migration:generate": "typeorm-ts-node-commonjs -d ./datasource.ts migration:generate ./libs/database/src/migrations/$npm_config_name",
    "migration:create": "typeorm-ts-node-commonjs -d ./datasource.ts migration:create ./libs/database/src/migrations/$npm_config_name",
    "migration:revert": "typeorm-ts-node-commonjs -d ./datasource.ts migration:revert"
  },
  "dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/mapped-types": "*",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/typeorm": "^10.0.1",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1",
    "sqlite3": "^5.1.7",
    "typeorm": "^0.3.20"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": ".",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node",
    "roots": [
      "<rootDir>/apps/",
      "<rootDir>/libs/"
    ],
    "moduleNameMapper": {
      "^@app/database(|/.*)$": "<rootDir>/libs/database/src/$1"
    }
  }
}

Node.js version

18.19.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 7 months ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.