Skip to content

Commit b44a131

Browse files
evereqclaude
andcommitted
chore(deps): complete TypeORM 0.3 -> 1.0 migration
Builds all ~60 libs green locally. Changes: - Migration files: cast switch discriminants to DatabaseTypeEnum (TypeORM 1.0 dropped 'sqlite' from the driver-type union; type-only, no runtime change). - relations/select array->object via the official @typeorm/codemod (127 files in core). - patches/typeorm+1.0.0.patch (patch-package): restore string[] relations/select + the join option in the TYPES — TypeORM 1.0 removed them from types but still honors them at runtime (FindOptionsUtils still does Array.isArray(relations) / options.join). Avoids rewriting 100+ dynamic-relations call sites. Wired into postinstall.manual. - packages/config: switch driver configs to the public DataSourceOptions union, drop removed connectorPackage, pin better-sqlite type, add invalidWhereValuesBehavior:{null:ignore,undefined:ignore} to restore 0.3 null-where behavior. - .onConflict(...do nothing) -> .orIgnore() (wakatime); drop deprecated .join spread in crud.service; revert codemod-mangled broadcast findOneById call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5237005 commit b44a131

316 files changed

Lines changed: 1003 additions & 838 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.

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/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/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(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export abstract class CrudService<T extends BaseEntity> implements ICrudService<
199199
*
200200
* @deprecated
201201
*/
202-
...(options && options.join ? { join: options.join } : {}),
203202
...(options && options.select ? { select: options.select } : {}),
204203
...(options && options.relations ? { relations: options.relations } : {}),
205204
...(options && options.where ? { where: options.where } : {}),

packages/core/src/lib/core/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function unixTimestampToDate(timestamps, format = 'YYYY-MM-DD HH:mm:ss')
6868
*/
6969
export function convertToDatetime(datetime): Date | string | null {
7070
if (moment(new Date(datetime)).isValid()) {
71-
switch (getConfig().dbConnectionOptions.type) {
71+
switch (getConfig().dbConnectionOptions.type as DatabaseTypeEnum) {
7272
case DatabaseTypeEnum.sqlite:
7373
case DatabaseTypeEnum.betterSqlite3:
7474
return moment(new Date(datetime)).format('YYYY-MM-DD HH:mm:ss');
@@ -122,7 +122,7 @@ export function getDateRange(
122122
throw 'End date must be greater than start date.';
123123
}
124124

125-
switch (getConfig().dbConnectionOptions.type) {
125+
switch (getConfig().dbConnectionOptions.type as DatabaseTypeEnum) {
126126
case DatabaseTypeEnum.sqlite:
127127
case DatabaseTypeEnum.betterSqlite3:
128128
start = start.format('YYYY-MM-DD HH:mm:ss');
@@ -216,7 +216,7 @@ export function getDateRangeFormat(startDate: moment.Moment, endDate: moment.Mom
216216
throw 'End date must be greater than start date.';
217217
}
218218

219-
switch (getConfig().dbConnectionOptions.type) {
219+
switch (getConfig().dbConnectionOptions.type as DatabaseTypeEnum) {
220220
case DatabaseTypeEnum.sqlite:
221221
case DatabaseTypeEnum.betterSqlite3:
222222
return {

packages/core/src/lib/database/connection-entity-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class ConnectionEntityManager {
2121
* @returns The raw connection from the EntityManager.
2222
*/
2323
get rawConnection(): DataSource {
24-
return this.entityManager.connection;
24+
return this.entityManager.dataSource;
2525
}
2626

2727
/**

packages/core/src/lib/database/migration-executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class ${camelCase(name, true)}${timestamp} implements MigrationInterface
293293
public async up(queryRunner: QueryRunner): Promise<void> {
294294
console.log(chalk.yellow(this.name + ' start running!'));
295295
296-
switch (queryRunner.connection.options.type) {
296+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
297297
case DatabaseTypeEnum.sqlite:
298298
case DatabaseTypeEnum.betterSqlite3:
299299
await this.sqliteUpQueryRunner(queryRunner);
@@ -317,7 +317,7 @@ export class ${camelCase(name, true)}${timestamp} implements MigrationInterface
317317
public async down(queryRunner: QueryRunner): Promise<void> {
318318
console.log(chalk.yellow(this.name + ' reverting changes!'));
319319
320-
switch (queryRunner.connection.options.type) {
320+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
321321
case DatabaseTypeEnum.sqlite:
322322
case DatabaseTypeEnum.betterSqlite3:
323323
await this.sqliteDownQueryRunner(queryRunner);

packages/core/src/lib/database/migrations/1638541848595-SwitchToMigration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class SwitchToMigration1638541848595 implements MigrationInterface {
1313
public async up(queryRunner: QueryRunner): Promise<void> {
1414
console.log(chalk.yellow(this.name + ' start running!'));
1515

16-
switch (queryRunner.connection.options.type) {
16+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
1717
case DatabaseTypeEnum.sqlite:
1818
case DatabaseTypeEnum.betterSqlite3:
1919
await this.sqliteUpQueryRunner(queryRunner);
@@ -34,7 +34,7 @@ export class SwitchToMigration1638541848595 implements MigrationInterface {
3434
* @param queryRunner
3535
*/
3636
public async down(queryRunner: QueryRunner): Promise<void> {
37-
switch (queryRunner.connection.options.type) {
37+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
3838
case DatabaseTypeEnum.sqlite:
3939
case DatabaseTypeEnum.betterSqlite3:
4040
await this.sqliteDownQueryRunner(queryRunner);

packages/core/src/lib/database/migrations/1638793919144-KnowledgeBasePlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class KnowledgeBasePlugin1638793919144 implements MigrationInterface {
1313
public async up(queryRunner: QueryRunner): Promise<void> {
1414
console.log(chalk.yellow(this.name + ' start running!'));
1515

16-
switch (queryRunner.connection.options.type) {
16+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
1717
case DatabaseTypeEnum.sqlite:
1818
case DatabaseTypeEnum.betterSqlite3:
1919
await this.sqliteUpQueryRunner(queryRunner);
@@ -34,7 +34,7 @@ export class KnowledgeBasePlugin1638793919144 implements MigrationInterface {
3434
* @param queryRunner
3535
*/
3636
public async down(queryRunner: QueryRunner): Promise<void> {
37-
switch (queryRunner.connection.options.type) {
37+
switch (queryRunner.connection.options.type as DatabaseTypeEnum) {
3838
case DatabaseTypeEnum.sqlite:
3939
case DatabaseTypeEnum.betterSqlite3:
4040
await this.sqliteDownQueryRunner(queryRunner);

0 commit comments

Comments
 (0)