Skip to content

Commit 937c8ba

Browse files
authored
Merge pull request #9716 from ever-co/chore/upgrade-typeorm-1.0
chore(deps): migrate TypeORM 0.3 -> 1.0
2 parents d55f032 + db68916 commit 937c8ba

337 files changed

Lines changed: 1046 additions & 878 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"sound-play": "1.1.0",
8585
"squirrelly": "^8.0.8",
8686
"twing": "^5.0.2",
87-
"typeorm": "^0.3.30",
87+
"typeorm": "^1.0.0",
8888
"undici": "^6.10.2",
8989
"custom-electron-titlebar": "^4.4.1"
9090
},

apps/server-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"rxjs": "^7.8.2",
8383
"squirrelly": "^8.0.8",
8484
"twing": "^5.0.2",
85-
"typeorm": "^0.3.30",
85+
"typeorm": "^1.0.0",
8686
"undici": "^6.10.2",
8787
"custom-electron-titlebar": "^4.4.1"
8888
},

apps/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"rxjs": "^7.8.2",
7878
"squirrelly": "^8.0.8",
7979
"twing": "^5.0.2",
80-
"typeorm": "^0.3.30",
80+
"typeorm": "^1.0.0",
8181
"undici": "^6.10.2",
8282
"custom-electron-titlebar": "^4.4.1"
8383
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"doc:build": "compodoc -p tsconfig.json -d dist/docs",
114114
"doc:serve": "compodoc -s -d dist/docs",
115115
"doc:build-serve": "compodoc -p tsconfig.json -d docs -s",
116-
"postinstall.manual": "yarn node ./.scripts/postinstall.js",
116+
"postinstall.manual": "patch-package && yarn node ./.scripts/postinstall.js",
117117
"postinstall.electron": "yarn electron-builder install-app-deps && yarn node tools/electron/postinstall",
118118
"postinstall.web": "yarn node ./decorate-angular-cli.js && yarn node tools/web/postinstall",
119119
"build:desktop": "cross-env NODE_ENV=production yarn run copy-files-i18n-desktop && yarn run postinstall.electron && yarn run config:prod && yarn run config:desktop:prod && yarn run pack:desktop && yarn run generate:icons:desktop --environment=prod && yarn run build:package:all:prod && yarn ng:prod run gauzy:desktop-ui --base-href ./ && yarn ng:prod run api:desktop-api && yarn ng:prod build desktop-api --configuration=production --output-path=dist/apps/desktop/desktop-api && yarn ng:prod build desktop --configuration=production --base-href ./ && yarn run prepare:desktop && yarn run copy-files-desktop && yarn run copy-assets-gauzy",
@@ -757,6 +757,7 @@
757757
"ng-packagr": "^21.0.0",
758758
"node-gyp": "^10.2.0",
759759
"npm-run-all": "^4.1.5",
760+
"patch-package": "^8.0.1",
760761
"nx": "^22.5.2",
761762
"pkg": "^5.3.0",
762763
"png-to-ico": "^2.1.8",

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"graphql": "^16.11.0",
3838
"nest-knexjs": "^0.0.30",
3939
"slugify": "^1.6.6",
40-
"typeorm": "^0.3.30",
40+
"typeorm": "^1.0.0",
4141
"tslib": "^2.6.2"
4242
},
4343
"devDependencies": {

packages/config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"mikro-orm-soft-delete": "^1.0.0-alpha.1",
4646
"nest-knexjs": "^0.0.30",
4747
"tslib": "^2.6.2",
48-
"typeorm": "^0.3.30"
48+
"typeorm": "^1.0.0"
4949
},
5050
"devDependencies": {
5151
"@types/jest": "30.0.0",

packages/config/src/lib/database.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { BetterSqliteDriver, Options as MikroOrmBetterSqliteOptions } from '@mik
66
import { PostgreSqlDriver, Options as MikroOrmPostgreSqlOptions } from '@mikro-orm/postgresql';
77
import { Options as MikroOrmMySqlOptions, MySqlDriver } from '@mikro-orm/mysql';
88
import { DataSourceOptions } from 'typeorm';
9-
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
10-
import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';
119
import { KnexModuleOptions } from 'nest-knexjs';
1210
import * as path from 'path';
1311
import * as chalk from 'chalk';
@@ -116,16 +114,17 @@ switch (dbType) {
116114
mikroOrmConnectionConfig = mikroOrmMySqlOptions;
117115

118116
// TypeORM DB Config (MySQL)
119-
const typeOrmMySqlOptions: MysqlConnectionOptions = {
117+
const typeOrmMySqlOptions: DataSourceOptions = {
120118
type: dbType,
119+
// TypeORM 1.0 throws on null/undefined in where by default; restore 0.3 'ignore' behavior.
120+
invalidWhereValuesBehavior: { null: 'ignore', undefined: 'ignore' },
121121
ssl: getTlsOptions(dbSslMode),
122122
host: process.env.DB_HOST || 'localhost',
123123
port: process.env.DB_PORT ? Number.parseInt(process.env.DB_PORT, 10) : 3306,
124124
database: process.env.DB_NAME || 'mysql',
125125
username: process.env.DB_USER || 'root',
126126
password: process.env.DB_PASS || 'root',
127127
// forcing typeorm to use (mysql2) if both (mysql/mysql2) packages found, it prioritize to load (mysql)
128-
connectorPackage: 'mysql2',
129128
logging: getLoggingOptions(process.env.DB_LOGGING), // by default set to error only
130129
logger: 'advanced-console',
131130
// log queries that take more than 10 sec as warnings
@@ -212,8 +211,10 @@ switch (dbType) {
212211
mikroOrmConnectionConfig = mikroOrmPostgresOptions;
213212

214213
// TypeORM DB Config (PostgreSQL)
215-
const typeOrmPostgresOptions: PostgresConnectionOptions = {
214+
const typeOrmPostgresOptions: DataSourceOptions = {
216215
type: dbType,
216+
// TypeORM 1.0 throws on null/undefined in where by default; restore 0.3 'ignore' behavior.
217+
invalidWhereValuesBehavior: { null: 'ignore', undefined: 'ignore' },
217218
ssl: getTlsOptions(dbSslMode),
218219
host: process.env.DB_HOST || 'localhost',
219220
port: process.env.DB_PORT ? Number.parseInt(process.env.DB_PORT, 10) : 5432,
@@ -310,7 +311,9 @@ switch (dbType) {
310311

311312
// TypeORM DB Config (Better-SQLite3)
312313
const typeOrmBetterSqliteConfig: DataSourceOptions = {
313-
type: dbType,
314+
type: DatabaseTypeEnum.betterSqlite3,
315+
// TypeORM 1.0 throws on null/undefined in where by default; restore 0.3 'ignore' behavior.
316+
invalidWhereValuesBehavior: { null: 'ignore', undefined: 'ignore' },
314317
database: sqlitePath,
315318
logging: 'all',
316319
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"sql.js": "^1.5.0",
180180
"streamifier": "^0.1.1",
181181
"swagger-ui-express": "^5.0.0",
182-
"typeorm": "^0.3.30",
182+
"typeorm": "^1.0.0",
183183
"underscore": "^1.13.8",
184184
"unleash-client": "^3.16.1",
185185
"unzipper": "^0.12.1",

packages/core/src/lib/auth/auth.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,9 @@ export class AuthService extends SocialAuthService {
16911691
case MultiORMEnum.TypeORM: {
16921692
const users = await this.typeOrmUserRepository.find({
16931693
where: { email },
1694-
select: ['id']
1694+
select: {
1695+
id: true
1696+
}
16951697
});
16961698
for (const user of users) {
16971699
await this.typeOrmUserRepository.update(user.id, { code: magicCode, codeExpireAt });
@@ -2248,7 +2250,8 @@ export class AuthService extends SocialAuthService {
22482250
break;
22492251
}
22502252
case MultiORMEnum.TypeORM: {
2251-
user = await this.typeOrmUserRepository.findOne({ where, relations });
2253+
// TODO(typeorm-v1): `relations` no longer accepts a string array. This value references a variable whose shape can't be determined statically — if it holds `string[]`, wrap it: `Object.fromEntries(<expr>?.map(r => [r, true]) ?? [])` (dot-paths need extra nesting handling). If it already holds the v1 object shape, no change needed.
2254+
user = await this.typeOrmUserRepository.findOne({ where, relations });
22522255
break;
22532256
}
22542257
default:
@@ -2274,7 +2277,8 @@ export class AuthService extends SocialAuthService {
22742277
break;
22752278
}
22762279
case MultiORMEnum.TypeORM: {
2277-
employee = await this.typeOrmEmployeeRepository.findOne({ where: employeeWhere, relations: employeeRelations });
2280+
// TODO(typeorm-v1): `relations` no longer accepts a string array. This value references a variable whose shape can't be determined statically — if it holds `string[]`, wrap it: `Object.fromEntries(<expr>?.map(r => [r, true]) ?? [])` (dot-paths need extra nesting handling). If it already holds the v1 object shape, no change needed.
2281+
employee = await this.typeOrmEmployeeRepository.findOne({ where: employeeWhere, relations: employeeRelations });
22782282
break;
22792283
}
22802284
default:
@@ -2385,7 +2389,8 @@ export class AuthService extends SocialAuthService {
23852389
break;
23862390
}
23872391
case MultiORMEnum.TypeORM: {
2388-
user = await this.typeOrmUserRepository.findOne({ where, relations });
2392+
// TODO(typeorm-v1): `relations` no longer accepts a string array. This value references a variable whose shape can't be determined statically — if it holds `string[]`, wrap it: `Object.fromEntries(<expr>?.map(r => [r, true]) ?? [])` (dot-paths need extra nesting handling). If it already holds the v1 object shape, no change needed.
2393+
user = await this.typeOrmUserRepository.findOne({ where, relations });
23892394
break;
23902395
}
23912396
default:

packages/core/src/lib/availability-slots/commands/handlers/get-conflict-availability-slots.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class GetConflictAvailabilitySlotsHandler implements ICommandHandler<GetC
3333
employeeId
3434
});
3535

36-
switch (this.configService.dbConnectionOptions.type) {
36+
switch (this.configService.dbConnectionOptions.type as DatabaseTypeEnum) {
3737
case DatabaseTypeEnum.sqlite:
3838
case DatabaseTypeEnum.betterSqlite3:
3939
query.andWhere(

0 commit comments

Comments
 (0)