-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Experiment Archive State (#987)
* working archive feature frontend changes * ignoring storing logs for archived experiments * add few more missing readonly properties for archive state * missed readonly for archive state * Create API and database for archive * resolved failing test cases for archive state * import change * not allowing archived state change from enrolling state * merge analysis and archieve api * added remaining file * fix peer review comments for archive state * Solve review comments --------- Co-authored-by: RidhamShah <[email protected]> Co-authored-by: danoswaltCL <[email protected]>
- Loading branch information
1 parent
ffede04
commit 58f1e63
Showing
22 changed files
with
373 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Entity, PrimaryColumn, Column, OneToOne, JoinColumn } from 'typeorm'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { BaseModel } from './base/BaseModel'; | ||
import { Query } from './Query'; | ||
|
||
@Entity() | ||
export class ArchivedStats extends BaseModel { | ||
@PrimaryColumn('uuid') | ||
public id: string; | ||
|
||
@IsNotEmpty() | ||
@Column('jsonb') | ||
public result: object; | ||
|
||
@OneToOne(() => Query, (query) => query.archivedStats, { onDelete: 'CASCADE' }) | ||
@JoinColumn() | ||
public query: Query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
backend/packages/Upgrade/src/api/repositories/ArchivedStatsRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { EntityRepository, Repository } from 'typeorm'; | ||
import { ArchivedStats } from '../models/ArchivedStats'; | ||
import repositoryError from './utils/repositoryError'; | ||
|
||
@EntityRepository(ArchivedStats) | ||
export class ArchivedStatsRepository extends Repository<ArchivedStats> { | ||
public async saveRawJson( | ||
rawDataArray: Array<Omit<ArchivedStats, 'createdAt' | 'updatedAt' | 'versionNumber'>> | ||
): Promise<ArchivedStats> { | ||
const result = await this.createQueryBuilder('ArchivedStats') | ||
.insert() | ||
.into(ArchivedStats) | ||
.values(rawDataArray) | ||
.onConflict(`DO NOTHING`) | ||
.returning('*') | ||
.execute() | ||
.catch((errorMsg: any) => { | ||
const errorMsgString = repositoryError(this.constructor.name, 'saveRawJson', { rawDataArray }, errorMsg); | ||
throw errorMsgString; | ||
}); | ||
|
||
return result.raw; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
backend/packages/Upgrade/src/database/migrations/1692936809279-archivedState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class archivedState1692936809279 implements MigrationInterface { | ||
name = 'archivedState1692936809279'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "archived_stats" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "versionNumber" integer NOT NULL, "id" uuid NOT NULL, "result" jsonb NOT NULL, "queryId" uuid, CONSTRAINT "REL_df18fe5ea7298a1dc7bfb33b06" UNIQUE ("queryId"), CONSTRAINT "PK_afc8a335c8d9d48cefaf1aa2c09" PRIMARY KEY ("id"))` | ||
); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."state_time_log_fromstate_enum" RENAME TO "state_time_log_fromstate_enum_old"` | ||
); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."state_time_log_fromstate_enum" AS ENUM('inactive', 'preview', 'scheduled', 'enrolling', 'enrollmentComplete', 'cancelled', 'archived')` | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."state_time_log" ALTER COLUMN "fromState" TYPE "public"."state_time_log_fromstate_enum" USING "fromState"::"text"::"public"."state_time_log_fromstate_enum"` | ||
); | ||
await queryRunner.query(`DROP TYPE "public"."state_time_log_fromstate_enum_old"`); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."state_time_log_tostate_enum" RENAME TO "state_time_log_tostate_enum_old"` | ||
); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."state_time_log_tostate_enum" AS ENUM('inactive', 'preview', 'scheduled', 'enrolling', 'enrollmentComplete', 'cancelled', 'archived')` | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."state_time_log" ALTER COLUMN "toState" TYPE "public"."state_time_log_tostate_enum" USING "toState"::"text"::"public"."state_time_log_tostate_enum"` | ||
); | ||
await queryRunner.query(`DROP TYPE "public"."state_time_log_tostate_enum_old"`); | ||
await queryRunner.query(`ALTER TYPE "public"."experiment_state_enum" RENAME TO "experiment_state_enum_old"`); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."experiment_state_enum" AS ENUM('inactive', 'preview', 'scheduled', 'enrolling', 'enrollmentComplete', 'cancelled', 'archived')` | ||
); | ||
await queryRunner.query(`ALTER TABLE "public"."experiment" ALTER COLUMN "state" DROP DEFAULT`); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."experiment" ALTER COLUMN "state" TYPE "public"."experiment_state_enum" USING "state"::"text"::"public"."experiment_state_enum"` | ||
); | ||
await queryRunner.query(`ALTER TABLE "public"."experiment" ALTER COLUMN "state" SET DEFAULT 'inactive'`); | ||
await queryRunner.query(`DROP TYPE "public"."experiment_state_enum_old"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "archived_stats" ADD CONSTRAINT "FK_df18fe5ea7298a1dc7bfb33b06f" FOREIGN KEY ("queryId") REFERENCES "query"("id") ON DELETE CASCADE ON UPDATE NO ACTION` | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "archived_stats" DROP CONSTRAINT "FK_df18fe5ea7298a1dc7bfb33b06f"`); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."experiment_state_enum_old" AS ENUM('cancelled', 'enrolling', 'enrollmentComplete', 'inactive', 'preview', 'scheduled')` | ||
); | ||
await queryRunner.query(`ALTER TABLE "public"."experiment" ALTER COLUMN "state" DROP DEFAULT`); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."experiment" ALTER COLUMN "state" TYPE "public"."experiment_state_enum_old" USING "state"::"text"::"public"."experiment_state_enum_old"` | ||
); | ||
await queryRunner.query(`ALTER TABLE "public"."experiment" ALTER COLUMN "state" SET DEFAULT 'inactive'`); | ||
await queryRunner.query(`DROP TYPE "public"."experiment_state_enum"`); | ||
await queryRunner.query(`ALTER TYPE "public"."experiment_state_enum_old" RENAME TO "experiment_state_enum"`); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."state_time_log_tostate_enum_old" AS ENUM('cancelled', 'enrolling', 'enrollmentComplete', 'inactive', 'preview', 'scheduled')` | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."state_time_log" ALTER COLUMN "toState" TYPE "public"."state_time_log_tostate_enum_old" USING "toState"::"text"::"public"."state_time_log_tostate_enum_old"` | ||
); | ||
await queryRunner.query(`DROP TYPE "public"."state_time_log_tostate_enum"`); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."state_time_log_tostate_enum_old" RENAME TO "state_time_log_tostate_enum"` | ||
); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."state_time_log_fromstate_enum_old" AS ENUM('cancelled', 'enrolling', 'enrollmentComplete', 'inactive', 'preview', 'scheduled')` | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "public"."state_time_log" ALTER COLUMN "fromState" TYPE "public"."state_time_log_fromstate_enum_old" USING "fromState"::"text"::"public"."state_time_log_fromstate_enum_old"` | ||
); | ||
await queryRunner.query(`DROP TYPE "public"."state_time_log_fromstate_enum"`); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."state_time_log_fromstate_enum_old" RENAME TO "state_time_log_fromstate_enum"` | ||
); | ||
await queryRunner.query(`DROP TABLE "archived_stats"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.