From e8649188e0c022f90d2716eebe42979790f3e2fc Mon Sep 17 00:00:00 2001 From: John Abramo Date: Wed, 19 Oct 2022 17:46:14 -0400 Subject: [PATCH 1/2] submission problem score allow null --- src/migration/1665020208581-addSubmissionProblemScores.ts | 4 ++-- src/model/submissionProblemScores.model.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/migration/1665020208581-addSubmissionProblemScores.ts b/src/migration/1665020208581-addSubmissionProblemScores.ts index 2e3f92d4..643276ae 100644 --- a/src/migration/1665020208581-addSubmissionProblemScores.ts +++ b/src/migration/1665020208581-addSubmissionProblemScores.ts @@ -22,8 +22,8 @@ export class addSubmissionProblemScores1665020208581 implements MigrationInterfa "deleted_at" TIMESTAMP, "submission_id" integer NOT NULL, "assignment_problem_id" integer NOT NULL, - "score" double precision NOT NULL, - "feedback" text NOT NULL, + "score" double precision, + "feedback" text, "released_at" TIMESTAMP, CONSTRAINT "submission_problem_scores_primary_key_constraint" PRIMARY KEY ("id") )`) diff --git a/src/model/submissionProblemScores.model.ts b/src/model/submissionProblemScores.model.ts index fecd2b5e..eaf97f35 100644 --- a/src/model/submissionProblemScores.model.ts +++ b/src/model/submissionProblemScores.model.ts @@ -36,11 +36,11 @@ export default class SubmissionProblemScore { @ManyToOne(() => AssignmentProblemModel) assignmentProblemId: number - @Column({ name: 'score', type: 'float' }) - score: number + @Column({ name: 'score', type: 'float', nullable: true }) + score: number | null - @Column({ name: 'feedback', type: 'text' }) - feedback: string + @Column({ name: 'feedback', type: 'text', nullable: true }) + feedback: string | null @Column({ name: 'released_at', nullable: true }) releasedAt?: Date From 5a52d183d9379e1d885373454bc1c1f8ea2755e2 Mon Sep 17 00:00:00 2001 From: John Abramo Date: Wed, 19 Oct 2022 20:02:19 -0400 Subject: [PATCH 2/2] add SubmissionScore Model --- .../1666218639563-addSubmissionScores.ts | 73 +++++++++++++++++++ src/model/index.ts | 2 + src/model/submissionScores.model.ts | 41 +++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/migration/1666218639563-addSubmissionScores.ts create mode 100644 src/model/submissionScores.model.ts diff --git a/src/migration/1666218639563-addSubmissionScores.ts b/src/migration/1666218639563-addSubmissionScores.ts new file mode 100644 index 00000000..ed70c4bf --- /dev/null +++ b/src/migration/1666218639563-addSubmissionScores.ts @@ -0,0 +1,73 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class addSubmissionScores1666218639563 implements MigrationInterface { + name = 'addSubmissionScores1666218639563' + + // prettier-ignore + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "assignments" DROP CONSTRAINT "assignments_to_courses_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "assignment_problems" DROP CONSTRAINT "assignment_problems_to_assignment_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_course_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_assignment_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_submitted_by_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_original_submission_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" DROP CONSTRAINT "submission_problem_scores_to_submission_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" DROP CONSTRAINT "submission_problem_scores_to_assignment_problem_id_foreign_key_"`) + await queryRunner.query(`ALTER TABLE "user_courses" DROP CONSTRAINT "user_courses_to_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "user_courses" DROP CONSTRAINT "user_courses_to_course_id_foreign_key_constraint"`) + + await queryRunner.query(`CREATE TABLE "submission_scores" ( + "id" SERIAL NOT NULL, + "created_at" TIMESTAMP NOT NULL DEFAULT now(), + "updated_at" TIMESTAMP NOT NULL DEFAULT now(), + "deleted_at" TIMESTAMP, + "submission_id" integer NOT NULL, + "score" double precision, + "feedback" text, + "released_at" TIMESTAMP, + CONSTRAINT "submission_scores_primary_key_constraint" PRIMARY KEY ("id") + )`) + + await queryRunner.query(`ALTER TABLE "assignments" ADD CONSTRAINT "assignments_to_courses_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "assignment_problems" ADD CONSTRAINT "assignment_problems_to_assignment_id_foreign_key_constraint" FOREIGN KEY ("assignment_id") REFERENCES "assignments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_course_id_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_assignment_id_foreign_key_constraint" FOREIGN KEY ("assignment_id") REFERENCES "assignments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_user_id_foreign_key_constraint" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_submitted_by_user_id_foreign_key_constraint" FOREIGN KEY ("submitted_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_original_submission_id_foreign_key_constraint" FOREIGN KEY ("original_submission_id") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" ADD CONSTRAINT "submission_problem_scores_to_submission_id_foreign_key_constraint" FOREIGN KEY ("submission_id") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" ADD CONSTRAINT "submission_problem_scores_to_assignment_problem_id_foreign_key_constraint" FOREIGN KEY ("assignment_problem_id") REFERENCES "assignment_problems"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submission_scores" ADD CONSTRAINT "submission_scores_to_submission_id_foreign_key_constraint" FOREIGN KEY ("submission_id") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "user_courses" ADD CONSTRAINT "user_courses_to_user_id_foreign_key_constraint" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "user_courses" ADD CONSTRAINT "user_courses_to_course_id_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + } + + // prettier-ignore + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user_courses" DROP CONSTRAINT "user_courses_to_course_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "user_courses" DROP CONSTRAINT "user_courses_to_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submission_scores" DROP CONSTRAINT "submission_scores_to_submission_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" DROP CONSTRAINT "submission_problem_scores_to_assignment_problem_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" DROP CONSTRAINT "submission_problem_scores_to_submission_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_original_submission_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_submitted_by_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_user_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_assignment_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "submissions" DROP CONSTRAINT "submissions_to_course_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "assignment_problems" DROP CONSTRAINT "assignment_problems_to_assignment_id_foreign_key_constraint"`) + await queryRunner.query(`ALTER TABLE "assignments" DROP CONSTRAINT "assignments_to_courses_foreign_key_constraint"`) + await queryRunner.query(`DROP TABLE "submission_scores"`) + await queryRunner.query(`ALTER TABLE "user_courses" ADD CONSTRAINT "user_courses_to_course_id_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "user_courses" ADD CONSTRAINT "user_courses_to_user_id_foreign_key_constraint" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" ADD CONSTRAINT "submission_problem_scores_to_assignment_problem_id_foreign_key_" FOREIGN KEY ("assignment_problem_id") REFERENCES "assignment_problems"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submission_problem_scores" ADD CONSTRAINT "submission_problem_scores_to_submission_id_foreign_key_constraint" FOREIGN KEY ("submission_id") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_original_submission_id_foreign_key_constraint" FOREIGN KEY ("original_submission_id") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_submitted_by_user_id_foreign_key_constraint" FOREIGN KEY ("submitted_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_user_id_foreign_key_constraint" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_assignment_id_foreign_key_constraint" FOREIGN KEY ("assignment_id") REFERENCES "assignments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "submissions" ADD CONSTRAINT "submissions_to_course_id_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "assignment_problems" ADD CONSTRAINT "assignment_problems_to_assignment_id_foreign_key_constraint" FOREIGN KEY ("assignment_id") REFERENCES "assignments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await queryRunner.query(`ALTER TABLE "assignments" ADD CONSTRAINT "assignments_to_courses_foreign_key_constraint" FOREIGN KEY ("course_id") REFERENCES "courses"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + } +} diff --git a/src/model/index.ts b/src/model/index.ts index 6a9d783e..5208a541 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -4,6 +4,7 @@ import SubmissionModel from './submissions.model' import UserModel from './users.model' import UserCourseModel from './userCourses.model' import SubmissionProblemScoreModel from './submissionProblemScores.model' +import SubmissionScoreModel from './submissionScores.model' type Models = | AssignmentModel @@ -12,5 +13,6 @@ type Models = | UserCourseModel | UserModel | SubmissionProblemScoreModel + | SubmissionScoreModel export default Models diff --git a/src/model/submissionScores.model.ts b/src/model/submissionScores.model.ts new file mode 100644 index 00000000..bb9cca74 --- /dev/null +++ b/src/model/submissionScores.model.ts @@ -0,0 +1,41 @@ +import { + JoinColumn, + ManyToOne, + Entity, + Column, + PrimaryGeneratedColumn, + CreateDateColumn, + UpdateDateColumn, + DeleteDateColumn, +} from 'typeorm' + +import SubmissionModel from './submissions.model' + +@Entity('submission_scores') +export default class SubmissionScore { + @PrimaryGeneratedColumn() + id: number + + @CreateDateColumn({ name: 'created_at' }) + createdAt: Date + + @UpdateDateColumn({ name: 'updated_at' }) + updatedAt: Date + + @DeleteDateColumn({ name: 'deleted_at' }) + deletedAt?: Date + + @Column({ name: 'submission_id' }) + @JoinColumn({ name: 'submission_id' }) + @ManyToOne(() => SubmissionModel) + submissionId: number + + @Column({ name: 'score', type: 'float', nullable: true }) + score: number | null + + @Column({ name: 'feedback', type: 'text', nullable: true }) + feedback: string | null + + @Column({ name: 'released_at', nullable: true }) + releasedAt?: Date +}