ToolJet/server/ormconfig.ts
Manish Kushare 6f43a043dc
Feature: Aggregate and group by functionality in TJDB (#10170)
* Added no codition section when aggregates are not available

* Added feature to add aggregate condition and display it accordingly

* Added feature to change the aggregateFx option

* Added feature to update column option in the aggregate

* Added feature to delete the aggregate

* Disabling the group by according to valid condition but without tooltip

* Added flow for deleting aggregate

* feat: migration and configuration changes to support aggregation in tooljet database

* added functionality for join table operations

* Dropdown styles

* Showing section for aggregate dropdown for joinTable operation

* Added gap in multiple aggregate conditions

* Added table_id in aggregate condition

* Added custom placeholder

Adjusted width of add condition of aggregate

* Refactored logic for disable group_by field

Added tooltip when group by is disabled

* Updated aggregateFx to aggFx and groupBy to group_by

* feat: group_by and aggregate option in list rows

* added table name for aggregate dropdown value in joinTable operation

* Get the group by options

* value of aggregate column dropdown in join table operation

* Added error and success message for aggregate deletion

* Spacing adjustments

* Clear the unwanted code

* Updated the stucture of aggregate

* Updated the structure of group_by

* Fix: Query builder breaking due to undefined values

* feat: logic used to aggregate on joins

* Removing async

* fix: app is crashing

* feat: statement timeout at database level and user session level configuration can be done for ToolJet database

* Added min and max width to dropdown in tooljetdb query manager

* Added description

* Adding width as 80 percentage when description is not avaialable

* New Postgrest change for render related to Aggregate (#10175)

* New Postgrest change for render related to Aggregate and group by functionality

* correction in PGRST_DB_ENABLE_AGGREGATE value

* Adding the env variable PGRST_DB_PRE_CONFIG

* Adding the new postgrest related env changes to CE specific files

* fix: updated env variable naming for aggregates

* Showing description at the bottom for aggregate fx

* Fixing typo error

* Showing tick mark on selected item in dropdown when isMulti is false

* Updated requested changes

* Showing some description when option is not focused or selected

* Updated the component name to AggregateFilter

* fix: updated env variable to enable aggregation in tooljet database

* refactor: new wrapper to create migration connection for tooljet database

* fix: custom error message for aggregation errors has been handled for list_rows operation

* fix: code review fixes

* fix: aggregate function validation typo is updated

* fix: empty validation for Select and Aggregate fields

* postgrest changes for cypress

* removed PGRST_DB_ENABLE_AGGREGATE

---------

Co-authored-by: Ganesh Kumar <ganesh8056234@gmail.com>
Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com>
Co-authored-by: Adish M <adish.madhu@gmail.com>
2024-07-01 14:38:31 +05:30

117 lines
2.8 KiB
TypeScript

import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { getEnvVars } from './scripts/database-config-utils';
function dbSslConfig(envVars) {
let config = {};
if (envVars?.DATABASE_URL)
config = {
url: envVars.DATABASE_URL,
ssl: { rejectUnauthorized: false },
};
if (envVars?.CA_CERT)
config = {
...config,
...{ ssl: { rejectUnauthorized: false, ca: envVars.CA_CERT } },
};
return config;
}
function tooljetDbSslConfig(envVars) {
let config = {};
if (envVars?.TOOLJET_DB_URL)
config = {
url: envVars.TOOLJET_DB_URL,
ssl: { rejectUnauthorized: false },
};
if (envVars?.CA_CERT)
config = {
...config,
...{ ssl: { rejectUnauthorized: false, ca: envVars.CA_CERT } },
};
return config;
}
function buildConnectionOptions(data): TypeOrmModuleOptions {
const connectionParams = {
database: data.PG_DB,
port: +data.PG_PORT || 5432,
username: data.PG_USER,
password: data.PG_PASS,
host: data.PG_HOST,
connectTimeoutMS: 5000,
extra: {
max: 25,
},
...dbSslConfig(data),
};
const entitiesDir =
data?.NODE_ENV === 'test' ? [__dirname + '/**/*.entity.ts'] : [__dirname + '/**/*.entity{.js,.ts}'];
return {
type: 'postgres',
...connectionParams,
entities: entitiesDir,
synchronize: false,
uuidExtension: 'pgcrypto',
migrationsRun: false,
migrationsTransactionMode: 'all',
logging: data.ORM_LOGGING || false,
migrations: [__dirname + '/migrations/**/*{.ts,.js}'],
keepConnectionAlive: true,
cli: {
migrationsDir: 'migrations',
},
};
}
function buildToolJetDbConnectionOptions(data): TypeOrmModuleOptions {
const connectionParams = {
database: data.TOOLJET_DB,
port: +data.TOOLJET_DB_PORT || 5432,
username: data.TOOLJET_DB_USER,
password: data.TOOLJET_DB_PASS,
host: data.TOOLJET_DB_HOST,
connectTimeoutMS: 5000,
logging: data.ORM_LOGGING || false,
extra: {
max: 25,
statement_timeout: data.TOOLJET_DB_STATEMENT_TIMEOUT || 60000,
},
...tooljetDbSslConfig(data),
};
return {
name: 'tooljetDb',
type: 'postgres',
...connectionParams,
synchronize: false,
uuidExtension: 'pgcrypto',
migrationsRun: false,
migrationsTransactionMode: 'all',
logging: data.ORM_LOGGING || false,
keepConnectionAlive: true,
};
}
function fetchConnectionOptions(type: string): TypeOrmModuleOptions {
const data = getEnvVars();
switch (type) {
case 'postgres':
return buildConnectionOptions(data);
case 'tooljetDb':
return buildToolJetDbConnectionOptions(data);
}
}
const ormconfig: TypeOrmModuleOptions = fetchConnectionOptions('postgres');
const tooljetDbOrmconfig: TypeOrmModuleOptions = fetchConnectionOptions('tooljetDb');
export { ormconfig, tooljetDbOrmconfig };
export default ormconfig;