diff --git a/backend/packages/Upgrade/src/api/models/IndividualEnrollment.ts b/backend/packages/Upgrade/src/api/models/IndividualEnrollment.ts index 038d89d122..7c376a6b90 100644 --- a/backend/packages/Upgrade/src/api/models/IndividualEnrollment.ts +++ b/backend/packages/Upgrade/src/api/models/IndividualEnrollment.ts @@ -31,6 +31,7 @@ export class IndividualEnrollment extends BaseModel { @Column({ type: 'enum', enum: ENROLLMENT_CODE, nullable: true }) public enrollmentCode: ENROLLMENT_CODE; + @Index() @ManyToOne(() => ExperimentCondition, { onDelete: 'CASCADE' }) public condition: ExperimentCondition; } diff --git a/backend/packages/Upgrade/src/api/models/IndividualExclusion.ts b/backend/packages/Upgrade/src/api/models/IndividualExclusion.ts index 4611bb46ed..fa39ad97c6 100644 --- a/backend/packages/Upgrade/src/api/models/IndividualExclusion.ts +++ b/backend/packages/Upgrade/src/api/models/IndividualExclusion.ts @@ -1,6 +1,6 @@ import { EXCLUSION_CODE } from 'upgrade_types'; import { IsNotEmpty } from 'class-validator'; -import { Entity, PrimaryColumn, ManyToOne, Column } from 'typeorm'; +import { Entity, PrimaryColumn, ManyToOne, Column, Index } from 'typeorm'; import { BaseModel } from './base/BaseModel'; import { Experiment } from './Experiment'; import { ExperimentUser } from './ExperimentUser'; @@ -10,6 +10,7 @@ export class IndividualExclusion extends BaseModel { @PrimaryColumn() public id: string; + @Index() @ManyToOne(() => Experiment, { onDelete: 'CASCADE' }) public experiment: Experiment; @@ -20,6 +21,7 @@ export class IndividualExclusion extends BaseModel { @Column({ type: 'enum', enum: EXCLUSION_CODE, nullable: true }) public exclusionCode: EXCLUSION_CODE; + @Index() @ManyToOne(() => ExperimentUser, { onDelete: 'CASCADE' }) public user: ExperimentUser; } diff --git a/backend/packages/Upgrade/src/database/migrations/1716191003726-addingIndex.ts b/backend/packages/Upgrade/src/database/migrations/1716191003726-addingIndex.ts new file mode 100644 index 0000000000..ea44ef43b9 --- /dev/null +++ b/backend/packages/Upgrade/src/database/migrations/1716191003726-addingIndex.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class addingIndex1716191003726 implements MigrationInterface { + name = 'addingIndex1716191003726'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE INDEX "IDX_4f4d2f2ec491226d4692ed400f" ON "individual_enrollment" ("conditionId") ` + ); + await queryRunner.query( + `CREATE INDEX "IDX_43238be19de9500c290393b907" ON "individual_exclusion" ("experimentId") ` + ); + await queryRunner.query(`CREATE INDEX "IDX_de26ba8251f4ebf8b9c8ccf623" ON "individual_exclusion" ("userId") `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."IDX_de26ba8251f4ebf8b9c8ccf623"`); + await queryRunner.query(`DROP INDEX "public"."IDX_43238be19de9500c290393b907"`); + await queryRunner.query(`DROP INDEX "public"."IDX_4f4d2f2ec491226d4692ed400f"`); + } +}