Skip to content

Commit 35dc9a8

Browse files
authored
fix: DB migration (#37)
1 parent 1d6bf7b commit 35dc9a8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/migration/1732106699497-InitMigration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export class InitMigration1732106699497 implements MigrationInterface {
55

66
public async up(queryRunner: QueryRunner): Promise<void> {
77
await queryRunner.query(`CREATE TYPE "public"."evaluation_evaluationstatus_enum" AS ENUM('approved', 'rejected')`);
8+
await queryRunner.query(`CREATE TYPE "public"."evaluation_evaluatortype_enum" AS ENUM('human', 'llm_gpt3')`);
9+
await queryRunner.query(`CREATE TYPE "public"."evaluation_answer_answer_enum" AS ENUM('yes', 'no', 'uncertain')`);
810
await queryRunner.query(`CREATE TABLE "evaluation" ("id" SERIAL NOT NULL, "evaluator" character varying(42) NOT NULL, "evaluatorType" "public"."evaluation_evaluatortype_enum" NOT NULL, "summary" character varying NOT NULL, "evaluatorScore" integer NOT NULL, "evaluationStatus" "public"."evaluation_evaluationstatus_enum" NOT NULL, "metadataCid" character varying NOT NULL, "applicationId" integer NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "lastUpdatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_566857ce7db15aa0fb1930b4cdf" UNIQUE ("evaluator", "applicationId"), CONSTRAINT "PK_b72edd439b9db736f55b584fa54" PRIMARY KEY ("id"))`);
911
await queryRunner.query(`CREATE TABLE "evaluation_answer" ("id" SERIAL NOT NULL, "answer" "public"."evaluation_answer_answer_enum" NOT NULL, "evaluationId" integer NOT NULL, "evaluationQuestionId" integer NOT NULL, CONSTRAINT "UQ_5d5571491f885c88023b5f56366" UNIQUE ("evaluationId", "evaluationQuestionId"), CONSTRAINT "PK_26adcf2e8e65214d2558b8f6910" PRIMARY KEY ("id"))`);
1012
await queryRunner.query(`CREATE TABLE "evaluation_question" ("id" SERIAL NOT NULL, "questionIndex" integer NOT NULL, "question" character varying NOT NULL, "poolId" integer NOT NULL, CONSTRAINT "UQ_bd9653bd57844a98c0863a0a5b8" UNIQUE ("poolId", "questionIndex"), CONSTRAINT "PK_6ecc0e6614b9c4bc65c6de2c021" PRIMARY KEY ("id"))`);
@@ -33,6 +35,8 @@ export class InitMigration1732106699497 implements MigrationInterface {
3335
await queryRunner.query(`DROP TABLE "evaluation_answer"`);
3436
await queryRunner.query(`DROP TABLE "evaluation"`);
3537
await queryRunner.query(`DROP TYPE "public"."evaluation_evaluationstatus_enum"`);
38+
await queryRunner.query(`DROP TYPE "public"."evaluation_evaluatortype_enum"`);
39+
await queryRunner.query(`DROP TYPE "public"."evaluation_answer_answer_enum"`);
3640
}
3741

3842
}

src/migration/1738025911271-Add-Indexes.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
import { type MigrationInterface, type QueryRunner } from "typeorm";
22

3-
export class AddPerformanceIndexes1234567890123 implements MigrationInterface {
3+
export class AddIndexes1738025911271 implements MigrationInterface {
4+
name = 'AddIndexes1738025911271'
5+
46
public async up(queryRunner: QueryRunner): Promise<void> {
57
// Indexes for Pool lookups
68
await queryRunner.query(`
79
CREATE INDEX IF NOT EXISTS idx_pool_chain_allo_pool
8-
ON pool(chain_id, allo_pool_id);
10+
ON "pool"("chainId", "alloPoolId");
911
`);
1012

1113
// Indexes for Application lookups
1214
await queryRunner.query(`
1315
CREATE INDEX IF NOT EXISTS idx_application_pool_chain
14-
ON application(pool_id, chain_id);
16+
ON "application"("poolId", "chainId");
1517
1618
CREATE INDEX IF NOT EXISTS idx_application_allo_id
17-
ON application(allo_application_id);
19+
ON "application"("alloApplicationId");
1820
`);
1921

2022
// Indexes for Evaluation lookups
2123
await queryRunner.query(`
2224
CREATE INDEX IF NOT EXISTS idx_evaluation_application
23-
ON evaluation(application_id);
25+
ON "evaluation"("applicationId");
2426
2527
CREATE INDEX IF NOT EXISTS idx_evaluation_evaluator
26-
ON evaluation(evaluator, evaluator_type);
28+
ON "evaluation"("evaluator", "evaluatorType");
2729
2830
CREATE INDEX IF NOT EXISTS idx_evaluation_status
29-
ON evaluation(evaluation_status);
31+
ON "evaluation"("evaluationStatus");
3032
`);
3133

3234
// Indexes for EvaluationQuestion lookups
3335
await queryRunner.query(`
3436
CREATE INDEX IF NOT EXISTS idx_eval_question_pool
35-
ON evaluation_question(pool_id, question_index);
37+
ON "evaluation_question"("poolId", "questionIndex");
3638
`);
3739
}
3840

0 commit comments

Comments
 (0)