nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error during migration generation: TypeError: view.expression is not a function

teymur1986 opened this issue · comments

How to fix the bug with @ViewEntity?

Issue Description
In application of Nestjs (node.js framework) we are using typeorm.
This application is using Postgres DB and through 'pg' npm package and typeorm, stack of dependencies are written below.
Currently we are facing the issue with generating migration files.

ormconfig-migrations.js =>
module.exports = {
type: 'postgres',
host: process.env.HOST_PG,
port: parseInt(process.env.PORT_PG, 10),
username: process.env.USER_PG,
password: process.env.PASS_PG,
database: process.env.DB_PG,
entities: ["dist/**/.entity{.ts,.js}"],
synchronize: false,
migrations: ["dist/migrations/{.ts,.js}"],
migrationsTableName: "migrations_typeorm",
migrationsRun: true,
cli: {
migrationsDir: "migrations",
}
}

Expected Behavior
We are expecting that command: ./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:generate -f ormconfig-migrations.js -n
will generate a new migration file.

Actual Behavior
Currently receiving this exception:
Error during migration generation:
TypeError: view.expression is not a function
at PostgresQueryRunner.createViewSql (/home/teymur/git/api-backoffice-maccabi/src/driver/postgres/PostgresQueryRunner.ts:1830:86)
at PostgresQueryRunner. (/home/teymur/git/api-backoffice-maccabi/src/driver/postgres/PostgresQueryRunner.ts:434:29)
at step (/home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
at Object.next (/home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/node_modules/tslib/tslib.js:122:57)
at /home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/node_modules/tslib/tslib.js:115:75
at new Promise ()
at Object.__awaiter (/home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/node_modules/tslib/tslib.js:111:16)
at PostgresQueryRunner.createView (/home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:561:24)
at /home/teymur/git/api-backoffice-maccabi/src/schema-builder/RdbmsSchemaBuilder.ts:404:36
at step (/home/teymur/git/api-backoffice-maccabi/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api-backoffice-maccabi@2.0.10 migration:generate: ts-node ./node_modules/.bin/typeorm migration:generate -f ormconfig-migrations.js -n
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api-backoffice-maccabi@2.0.10 migration:generate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/teymur/.npm/_logs/2020-11-11T08_27_17_257Z-debug.log

// include the output in code tags like these!
Steps to Reproduce
1.Generate a new Nest project with typeorm as a entity manager.
2. add two entities.
3. add ViewEntity (@ViewEntity()) where entities above would generate it.
4. run ./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:generate -f ormconfig-migrations.js -n as we do.
or just try to use regular typeorm migration generation command with point on file -f ormconfig-migrations.js that is already explained above.

My Environment
Linux -> Ubuntu
NestJS v.7
typeorm: "^0.2.28",
typeorm-store: "^1.2.0"

here is a stack of dependencies we are using for the project:
"@godaddy/terminus": "^4.4.1",
"@nestjs/common": "^7.4.4",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.4.4",
"@nestjs/passport": "^7.1.0",
"@nestjs/platform-express": "^7.4.4",
"@nestjs/platform-socket.io": "^7.4.4",
"@nestjs/terminus": "^7.0.1",
"@nestjs/typeorm": "^7.1.4",
"@nestjs/websockets": "^7.4.4",
"@types/connect-flash": "^0.0.35",
"@types/express-handlebars": "^3.1.0",
"@types/express-session": "^1.17.0",
"@types/lodash": "^4.14.161",
"@types/passport-local": "^1.0.33",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"config": "^3.3.2",
"connect-flash": "^0.1.1",
"cors": "^2.8.5",
"crypto-js": "^4.0.0",
"dotenv": "^8.2.0",
"express-session": "^1.17.1",
"firebase-admin": "^9.2.0",
"fs": "0.0.1-security",
"lodash": "^4.17.20",
"moment": "^2.29.0",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"pg": "^8.4.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.3",
"typeorm": "^0.2.28",
"typeorm-store": "^1.2.0"
},

Please, report this issue in the typeorm repository

Already reported, please leave it open till we will receive a solution from the typeorm team.
The reason I'm asking is that it possibly this bug could be issue on nestjs@typeorm as well,
because as you may see there are Typescript exception which may be thrown from your wrapper or from them.
Thanks