From 1b166dbe1f882852f5827c633342225450498253 Mon Sep 17 00:00:00 2001 From: bayusamudra5502 <bayusamudra.55.02.com@gmail.com> Date: Sat, 1 Apr 2023 13:12:27 +0700 Subject: [PATCH] fix: updating material and quiz schema --- .../20230401130532-update-material.sql | 8 ++++ .../20230401130806-update-quiz.sql | 47 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 migrations/development/20230401130532-update-material.sql create mode 100644 migrations/development/20230401130806-update-quiz.sql diff --git a/migrations/development/20230401130532-update-material.sql b/migrations/development/20230401130532-update-material.sql new file mode 100644 index 0000000..b739bd7 --- /dev/null +++ b/migrations/development/20230401130532-update-material.sql @@ -0,0 +1,8 @@ + +-- +migrate Up +ALTER TABLE material + ADD COLUMN week INT; + +-- +migrate Down +ALTER TABLE material + DROP COLUMN week; \ No newline at end of file diff --git a/migrations/development/20230401130806-update-quiz.sql b/migrations/development/20230401130806-update-quiz.sql new file mode 100644 index 0000000..a2e0126 --- /dev/null +++ b/migrations/development/20230401130806-update-quiz.sql @@ -0,0 +1,47 @@ + +-- +migrate Up +DROP TABLE quiz_take_choice_answer; +DROP TABLE quiz_choice_option; +DROP TABLE quiz_problem; + +ALTER TABLE quiz + ADD COLUMN quiz_path TEXT; + +-- +migrate Down + +ALTER TABLE quiz + DROP COLUMN quiz_path; + +CREATE TABLE public."quiz_problem" ( + id UUID DEFAULT uuid_generate_v4(), + statement TEXT NOT NULL, + "type" PROBLEM_TYPE NOT NULL, + quiz_id UUID NOT NULL, + PRIMARY KEY(id), + FOREIGN KEY(quiz_id) + REFERENCES public."quiz"(id) +); + +CREATE TABLE public."quiz_choice_option" ( + id UUID DEFAULT uuid_generate_v4(), + quiz_problem_id UUID NOT NULL, + statement TEXT NOT NULL, + is_answer BOOLEAN DEFAULT false, + PRIMARY KEY(id, quiz_problem_id), + FOREIGN KEY (quiz_problem_id) + REFERENCES public."quiz_problem"(id) + ON DELETE CASCADE +); + + +CREATE TABLE public."quiz_take_choice_answer" ( + quiz_take_id UUID NOT NULL, + answer_choice_id UUID NOT NULL, + quiz_problem_id UUID NOT NULL, + PRIMARY KEY (quiz_take_id, quiz_problem_id), + FOREIGN KEY (quiz_take_id) + REFERENCES public."quiz_take"(id) + ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (answer_choice_id, quiz_problem_id) + REFERENCES public."quiz_choice_option"(id, quiz_problem_id) +); -- GitLab