Skip to content

Commit

Permalink
updated Stratification migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
RidhamShah committed Oct 5, 2023
1 parent 9120553 commit b5f9b1d
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class stratificationFactorFeature1695966648161 implements MigrationInterface {
name = 'stratificationFactorFeature1695966648161';
export class stratificationFactorFeature1696498128121 implements MigrationInterface {
name = 'stratificationFactorFeature1696498128121';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "stratification_factor" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "versionNumber" integer NOT NULL, "id" uuid NOT NULL, "stratificationFactorName" character varying NOT NULL, CONSTRAINT "PK_0b8b85d842f1ca83b1008b240eb" PRIMARY KEY ("id"))`
`CREATE TABLE "stratification_factor" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "versionNumber" integer NOT NULL, "stratificationFactorName" character varying NOT NULL, CONSTRAINT "PK_9ebfa233a2cbd8a560ca15f3f54" PRIMARY KEY ("stratificationFactorName"))`
);
await queryRunner.query(
`CREATE TABLE "user_stratification_factor" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "versionNumber" integer NOT NULL, "stratificationFactorValue" character varying NOT NULL, "userId" character varying NOT NULL, "stratificationFactorId" uuid NOT NULL, CONSTRAINT "PK_23fb3e3418618a53c5d9cbfeb30" PRIMARY KEY ("userId", "stratificationFactorId"))`
`CREATE TABLE "user_stratification_factor" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "versionNumber" integer NOT NULL, "stratificationFactorValue" character varying NOT NULL, "userId" character varying NOT NULL, "factorName" character varying NOT NULL, CONSTRAINT "PK_17c5f1a852052b6800e15febbd6" PRIMARY KEY ("userId", "factorName"))`
);
await queryRunner.query(
`CREATE TYPE "public"."experiment_assignmentalgorithm_enum" AS ENUM('random', 'stratified random sampling')`
);
await queryRunner.query(
`ALTER TABLE "public"."experiment" ADD "assignmentAlgorithm" "public"."experiment_assignmentalgorithm_enum" NOT NULL`
`ALTER TABLE "public"."experiment" ADD "assignmentAlgorithm" "public"."experiment_assignmentalgorithm_enum" NOT NULL DEFAULT 'random'`
);
await queryRunner.query(
`ALTER TABLE "public"."experiment" ADD "stratificationFactorStratificationFactorName" character varying`
);
await queryRunner.query(`ALTER TABLE "public"."experiment" ADD "stratificationFactorId" uuid`);
await queryRunner.query(
`ALTER TABLE "user_stratification_factor" ADD CONSTRAINT "FK_a314482a152dd63f49898feb468" FOREIGN KEY ("userId") REFERENCES "experiment_user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "user_stratification_factor" ADD CONSTRAINT "FK_3eeb586965b5d4fe0238fb89194" FOREIGN KEY ("stratificationFactorId") REFERENCES "stratification_factor"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
`ALTER TABLE "user_stratification_factor" ADD CONSTRAINT "FK_287fb490668d66047a1f8d96c1e" FOREIGN KEY ("factorName") REFERENCES "stratification_factor"("stratificationFactorName") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "public"."experiment" ADD CONSTRAINT "FK_9ac712ea8ff6ffe88dd02417aa9" FOREIGN KEY ("stratificationFactorId") REFERENCES "stratification_factor"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
`ALTER TABLE "public"."experiment" ADD CONSTRAINT "FK_335189d91114f3a71ff18be6243" FOREIGN KEY ("stratificationFactorStratificationFactorName") REFERENCES "stratification_factor"("stratificationFactorName") ON DELETE CASCADE ON UPDATE NO ACTION`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "public"."experiment" DROP CONSTRAINT "FK_9ac712ea8ff6ffe88dd02417aa9"`);
await queryRunner.query(`ALTER TABLE "public"."experiment" DROP CONSTRAINT "FK_335189d91114f3a71ff18be6243"`);
await queryRunner.query(
`ALTER TABLE "user_stratification_factor" DROP CONSTRAINT "FK_3eeb586965b5d4fe0238fb89194"`
`ALTER TABLE "user_stratification_factor" DROP CONSTRAINT "FK_287fb490668d66047a1f8d96c1e"`
);
await queryRunner.query(
`ALTER TABLE "user_stratification_factor" DROP CONSTRAINT "FK_a314482a152dd63f49898feb468"`
);
await queryRunner.query(`ALTER TABLE "public"."experiment" DROP COLUMN "stratificationFactorId"`);
await queryRunner.query(
`ALTER TABLE "public"."experiment" DROP COLUMN "stratificationFactorStratificationFactorName"`
);
await queryRunner.query(`ALTER TABLE "public"."experiment" DROP COLUMN "assignmentAlgorithm"`);
await queryRunner.query(`DROP TYPE "public"."experiment_assignmentalgorithm_enum"`);
await queryRunner.query(`DROP TABLE "user_stratification_factor"`);
Expand Down

0 comments on commit b5f9b1d

Please sign in to comment.