forked from UBAutograding/devU-api
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 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,73 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm' | ||
|
||
export class addSubmissionScores1666218639563 implements MigrationInterface { | ||
name = 'addSubmissionScores1666218639563' | ||
|
||
// prettier-ignore | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
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<void> { | ||
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`) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |