Skip to content

Commit

Permalink
Hotfix: TJDB connection on feature disabled flag (#9579)
Browse files Browse the repository at this point in the history
* fix TJDB deps for feature flag

* support async loading of db connection

* conditionally init TJDB connection on boot

* bump to v2.39.1
  • Loading branch information
akshaysasidrn committed May 1, 2024
1 parent eef2a49 commit bc9990d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.39.0
2.39.1
2 changes: 1 addition & 1 deletion frontend/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.39.0
2.39.1
2 changes: 1 addition & 1 deletion server/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.39.0
2.39.1
2 changes: 1 addition & 1 deletion server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const imports = [
ImportExportResourcesModule,
CopilotModule,
OrganizationConstantModule,
TooljetDbModule,
];

if (process.env.SERVE_CLIENT !== 'false' && process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -165,7 +166,6 @@ if (process.env.COMMENT_FEATURE_ENABLE !== 'false') {
}

if (process.env.ENABLE_TOOLJET_DB === 'true') {
imports.unshift(TooljetDbModule);
imports.unshift(TypeOrmModule.forRoot(tooljetDbOrmconfig));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Plugin } from 'src/entities/plugin.entity';
import { PluginsHelper } from 'src/helpers/plugins.helper';
import { CredentialsService } from '@services/credentials.service';
import { DataSource } from 'src/entities/data_source.entity';
import { tooljetDbOrmconfig } from '../../../ormconfig';
import { PluginsModule } from '../plugins/plugins.module';
import { EncryptionService } from '@services/encryption.service';
import { Credential } from '../../../src/entities/credential.entity';
Expand All @@ -29,10 +28,6 @@ const imports = [
TooljetDbModule,
];

if (process.env.ENABLE_TOOLJET_DB === 'true') {
imports.unshift(TypeOrmModule.forRoot(tooljetDbOrmconfig));
}

@Module({
imports,
controllers: [ImportExportResourcesController],
Expand Down
15 changes: 11 additions & 4 deletions server/src/modules/tooljet_db/tooljet_db.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Credential } from '../../../src/entities/credential.entity';
import { TooljetDbController } from '@controllers/tooljet_db.controller';
Expand All @@ -7,12 +7,19 @@ import { TooljetDbService } from '@services/tooljet_db.service';
import { PostgrestProxyService } from '@services/postgrest_proxy.service';
import { TooljetDbBulkUploadService } from '@services/tooljet_db_bulk_upload.service';
import { TooljetDbOperationsService } from '@services/tooljet_db_operations.service';
import { tooljetDbOrmconfig } from 'ormconfig';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [TypeOrmModule.forFeature([Credential]), TypeOrmModule.forRoot(tooljetDbOrmconfig), CaslModule],
imports: [TypeOrmModule.forFeature([Credential]), CaslModule],
controllers: [TooljetDbController],
providers: [TooljetDbService, TooljetDbBulkUploadService, TooljetDbOperationsService, PostgrestProxyService],
exports: [TooljetDbOperationsService],
})
export class TooljetDbModule {}
export class TooljetDbModule implements OnModuleInit {
constructor(private configService: ConfigService) {}

onModuleInit() {
const enableTooljetDb = this.configService.get('ENABLE_TOOLJET_DB') === 'true';
console.log(`ToolJet Database enabled: ${enableTooljetDb}`);
}
}
2 changes: 2 additions & 0 deletions server/src/services/tooljet_db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ SelectQueryBuilder.prototype.fullOuterJoin = function (entityOrProperty, alias,
export class TooljetDbService {
constructor(
private readonly manager: EntityManager,
// TODO: remove optional decorator when
// ENABLE_TOOLJET_DB flag is deprecated
@Optional()
@InjectEntityManager('tooljetDb')
private readonly tooljetDbManager: EntityManager
Expand Down
5 changes: 4 additions & 1 deletion server/src/services/tooljet_db_bulk_upload.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { BadRequestException, Injectable, NotFoundException, Optional } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { InternalTable } from 'src/entities/internal_table.entity';
import * as csv from 'fast-csv';
Expand All @@ -14,6 +14,9 @@ const MAX_ROW_COUNT = 1000;
export class TooljetDbBulkUploadService {
constructor(
private readonly manager: EntityManager,
// TODO: remove optional decorator when
// ENABLE_TOOLJET_DB flag is deprecated
@Optional()
@InjectEntityManager('tooljetDb')
private readonly tooljetDbManager: EntityManager,
private readonly tooljetDbService: TooljetDbService
Expand Down

0 comments on commit bc9990d

Please sign in to comment.