While running a database migration I do get the following errors:
apps/mtb-api/src/dbconfig_entity/User.ts:11:4 - error TS1240: Unable to resolve signature of property decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'Object'.
11 @PrimaryColumn("varchar", { name: "userId", length: 50, nullable: false })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apps/mtb-api/src/dbconfig_entity/User.ts:12:3 - error TS2564: Property 'userId' has no initializer and is not definitely assigned in the constructor.
12 userId: string;
~~~~~~
apps/mtb-api/src/dbconfig_entity/User.ts:14:4 - error TS1240: Unable to resolve signature of property decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'Object'.
14 @ManyToMany(() => Tenant)
~~~~~~~~~~~~~~~~~~~~~~~~
apps/mtb-api/src/dbconfig_entity/User.ts:15:4 - error TS1240: Unable to resolve signature of property decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'Object'.
15 @JoinTable()
~~~~~~~~~~~
Is was trying to generate a migration file for a MySql database.
Actually in code, typeorm is running just fine. The problem is when I use the typeorm cli to generate new migrations, I do receieve errors.
I run the following command:
npm run typeorm — migration:generate apps/mtb-api/src/db_mirations/dbconfig_migration/new -d apps/mtb-api/src/db_migrations/mtbConfigDataSource.ts
Here is the tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2020", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowUnusedLabels": true,
"useUnknownInCatchVariables": false,
"paths": {
"@mtb/mtb-core": ["libs/mtb-core/src/index.ts"],
"@mtb/mtb-requests": ["libs/mtb-requests/src/index.ts"],
"@mtb/mtb-style": ["libs/mtb-style/src/index.ts"],
"@mtb/mtb-ui": ["libs/mtb-ui/src/index.ts"],
"@mtb/svc-IAMAuth0": ["libs/svc-IAMAuth0/src/index.ts"],
"@mtb/svc-IAMProvider": ["libs/svc-IAMProvider/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
}
The package.json:
{
"name": "@mtb/source",
"version": "2.0.0",
"license": "MIT",
"scripts": {
"start:api": "npx nx run mtb-api:serve",
"start:admin": "npx nx run mtb-admin-app:serve",
"start:guest": "npx nx run mtb-guest-app-v1:serve",
"install:guest": "cd apps/guestv1 && npm install --legacy-peer-deps",
"build api doc": "cd apps/mtb-api && npx tsoa spec",
"rebuild test environment": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./infra/buildtest.ps1",
"backup_mtb_dev_db": "docker exec -i mtb_development-mysql-1 /usr/bin/mysqldump --all-databases -u root --password=P@ssword1 > ./BackupMtbDev/mtbdevdb.sql",
"restore_mtb_dev_db": "docker exec -i mtb_development-mysql-1 /usr/bin/mysql -u root --password=P@ssword1 < ./BackupMtbDev/mtbdevdb_noel_30.sql",
"typeorm": "typeorm-ts-node-commonJs"
},
"private": true,
"devDependencies": {
"@babel/core": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@nx/eslint": "17.1.3",
"@nx/eslint-plugin": "17.1.3",
"@nx/express": "^17.1.3",
"@nx/jest": "17.1.3",
"@nx/js": "17.2.8",
"@nx/node": "17.1.3",
"@nx/react": "17.2.8",
"@nx/webpack": "17.1.3",
"@nx/workspace": "17.1.3",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@svgr/webpack": "^8.0.1",
"@swc-node/register": "~1.6.7",
"@swc/cli": "~0.1.62",
"@swc/core": "~1.3.85",
"@testing-library/jest-dom": "^6.4.1",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/bcryptjs": "^2.4.6",
"@types/cookie-parser": "^1.4.6",
"@types/cors": "^2.8.17",
"@types/express": "4.17.13",
"@types/geojson": "^7946.0.13",
"@types/jest": "^29.5.11",
"@types/jsonwebtoken": "^9.0.5",
"@types/leaflet": "^1.9.8",
"@types/lodash": "^4.14.202",
"@types/multer": "^1.4.11",
"@types/multer-s3": "^3.0.3",
"@types/node": "18.14.2",
"@types/react": "18.2.33",
"@types/react-dom": "18.2.14",
"@types/react-world-flags": "^1.4.5",
"@types/supertest": "^6.0.1",
"@types/swagger-ui-express": "^4.1.6",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"babel-jest": "^29.4.1",
"eslint": "~8.46.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.4.1",
"jest-environment-node": "^29.4.1",
"nx": "17.1.3",
"prettier": "^2.6.2",
"react-refresh": "^0.10.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node": "10.9.1",
"typescript": "~5.5.4",
"url-loader": "^4.1.1"
},
"dependencies": {
"@auth0/auth0-react": "^2.2.4",
"@aws-sdk/client-s3": "^3.465.0",
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@swc/helpers": "~0.5.2",
"axios": "^1.0.0",
"bcryptjs": "^2.4.3",
"chakra-react-select": "^4.7.6",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"express": "^4.18.1",
"express-oauth2-jwt-bearer": "^1.6.0",
"express-validator": "^7.0.1",
"geojson": "^0.5.0",
"i18next-browser-languagedetector": "^7.2.0",
"jsonwebtoken": "^9.0.2",
"leaflet": "^1.9.4",
"lodash": "^4.17.21",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
"mysql2": "^3.6.5",
"react": "18.2.0",
"react-cookie": "^7.0.2",
"react-cropper": "^2.3.3",
"react-dom": "18.2.0",
"react-drag-drop-files": "^2.3.10",
"react-hook-form": "^7.50.0",
"react-i18next": "^14.0.1",
"react-icons": "^5.0.1",
"react-leaflet": "4.2.1",
"react-player": "^2.14.1",
"react-quill": "^2.0.0",
"react-router-dom": "^6.22.0",
"react-select": "^5.8.0",
"react-world-flags": "^1.6.0",
"reflect-metadata": "^0.2.2",
"sharp": "^0.33.0",
"swagger-ui-express": "^5.0.0",
"tslib": "^2.3.0",
"tsoa": "^5.1.1",
"typeorm": "^0.3.20",
"uuid": "^9.0.1",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"wkx": "^0.5.0"
}
}
This typescript file contains the datasource info:
import { DataSource } from "typeorm";
export const mtbConfigDataSource = new DataSource({
name: "MTBConfig",
type: "mysql",
host: "127.0.0.1",
port: 3310,
database: "mtb_config_clean",
username: "MTB_Super_Admin",
password: "P@ssword1",
synchronize: false,
logging: false,
entities: ["apps/mtb-api/src/dbconfig_entity/**/*.ts"],
migrations: ["apps/mtb-api/src/db_migrations/dbconfig_migration/**/*.ts}"],
legacySpatialSupport: false,
});