Fix view performances (#14209)
This commit is contained in:
@@ -1,18 +1,30 @@
|
||||
import { type TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource, type DataSourceOptions } from 'typeorm';
|
||||
import { DataSource, type DataSourceOptions, type LogLevel } from 'typeorm';
|
||||
config({
|
||||
path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
|
||||
override: true,
|
||||
});
|
||||
|
||||
const getLoggingConfig = (): LogLevel[] => {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return ['query', 'error'];
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ['error'];
|
||||
};
|
||||
|
||||
const isJest = process.argv.some((arg) => arg.includes('jest'));
|
||||
|
||||
export const typeORMCoreModuleOptions: TypeOrmModuleOptions = {
|
||||
url: process.env.PG_DATABASE_URL,
|
||||
type: 'postgres',
|
||||
logging: ['error'],
|
||||
logging: getLoggingConfig(),
|
||||
schema: 'core',
|
||||
entities:
|
||||
process.env.IS_BILLING_ENABLED === 'true'
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import { type MigrationInterface, type QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddViewIndexes1756732238898 implements MigrationInterface {
|
||||
name = 'AddViewIndexes1756732238898';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_VIEW_FILTER_VIEW_ID" ON "core"."viewFilter" ("viewId") WHERE "deletedAt" IS NULL`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_VIEW_FILTER_GROUP_VIEW_ID" ON "core"."viewFilterGroup" ("viewId") WHERE "deletedAt" IS NULL`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_VIEW_GROUP_VIEW_ID" ON "core"."viewGroup" ("viewId") WHERE "deletedAt" IS NULL`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_VIEW_SORT_VIEW_ID" ON "core"."viewSort" ("viewId") WHERE "deletedAt" IS NULL`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_VIEW_FIELD_VIEW_ID" ON "core"."viewField" ("viewId") WHERE "deletedAt" IS NULL`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "core"."IDX_VIEW_FIELD_VIEW_ID"`);
|
||||
await queryRunner.query(`DROP INDEX "core"."IDX_VIEW_SORT_VIEW_ID"`);
|
||||
await queryRunner.query(`DROP INDEX "core"."IDX_VIEW_GROUP_VIEW_ID"`);
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "core"."IDX_VIEW_FILTER_GROUP_VIEW_ID"`,
|
||||
);
|
||||
await queryRunner.query(`DROP INDEX "core"."IDX_VIEW_FILTER_VIEW_ID"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user