Skip to content

Commit

Permalink
Merge pull request #1553 from CarnegieLearningWeb/fix/addingIndex
Browse files Browse the repository at this point in the history
Add index to include/exclude models
  • Loading branch information
ppratikcr7 authored Jun 3, 2024
2 parents 641240e + 153f61d commit 2c285e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +10,7 @@ export class IndividualExclusion extends BaseModel {
@PrimaryColumn()
public id: string;

@Index()
@ManyToOne(() => Experiment, { onDelete: 'CASCADE' })
public experiment: Experiment;

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class addingIndex1716191003726 implements MigrationInterface {
name = 'addingIndex1716191003726';

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.query(`DROP INDEX "public"."IDX_de26ba8251f4ebf8b9c8ccf623"`);
await queryRunner.query(`DROP INDEX "public"."IDX_43238be19de9500c290393b907"`);
await queryRunner.query(`DROP INDEX "public"."IDX_4f4d2f2ec491226d4692ed400f"`);
}
}

0 comments on commit 2c285e5

Please sign in to comment.