Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- V4: repair question options stored as a JSON object instead of a JSON array.
--
-- Question.options is mapped as List<String> and the grader compares the chosen option's text with
-- correct_answer. Older versions of seed_demo_data.sql inserted options as {"A": "10", "B": "20", ...},
-- which Jackson cannot read as a list: opening those exams in the editor or starting them failed with 500.
--
-- The application itself always writes arrays, so only rows from the old seed are touched. Keys are
-- option letters (A..E) or "Benar"/"Salah", so ordering by key keeps the original option order.
-- Running it on a database without such rows changes nothing.

UPDATE questions
SET options = COALESCE(
(SELECT jsonb_agg(entry.value ORDER BY entry.key) FROM jsonb_each(questions.options) AS entry),
'[]'::jsonb)
WHERE jsonb_typeof(options) = 'object';
8 changes: 4 additions & 4 deletions backend/src/main/resources/db/migration/seed_demo_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ BEGIN
-- Questions
INSERT INTO questions (examination_id, question_text, question_type, options, correct_answer, points)
VALUES
(v_exam1, 'Jika matriks A berordo 2x2 memiliki determinan 5, maka nilai dari determinan 2A adalah...', 'multiple_choice', '{"A": "10", "B": "20", "C": "25", "D": "40", "E": "50"}'::jsonb, '20', 20),
(v_exam1, 'Dua garis sejajar memiliki gradien yang sama besar.', 'true_false', '{"Benar": "Benar", "Salah": "Salah"}'::jsonb, 'Benar', 20),
(v_exam1, 'Jika matriks A berordo 2x2 memiliki determinan 5, maka nilai dari determinan 2A adalah...', 'multiple_choice', '["10", "20", "25", "40", "50"]'::jsonb, '20', 20),
(v_exam1, 'Dua garis sejajar memiliki gradien yang sama besar.', 'true_false', '["Benar", "Salah"]'::jsonb, 'Benar', 20),
(v_exam1, 'Jelaskan konsep invers matriks dan sebutkan syarat sebuah matriks memiliki invers!', 'essay', NULL, 'Matriks memiliki invers jika determinan != 0 (non-singular).', 60),

(v_exam2, 'Anotasi Spring Boot yang digunakan untuk menandai kelas sebagai REST Controller adalah...', 'multiple_choice', '{"A": "@Controller", "B": "@RestController", "C": "@Service", "D": "@Component", "E": "@Endpoint"}'::jsonb, '@RestController', 30),
(v_exam2, 'React hook apa yang digunakan untuk mengelola efek samping seperti data fetching?', 'multiple_choice', '{"A": "useState", "B": "useEffect", "C": "useMemo", "D": "useContext", "E": "useRef"}'::jsonb, 'useEffect', 30),
(v_exam2, 'Anotasi Spring Boot yang digunakan untuk menandai kelas sebagai REST Controller adalah...', 'multiple_choice', '["@Controller", "@RestController", "@Service", "@Component", "@Endpoint"]'::jsonb, '@RestController', 30),
(v_exam2, 'React hook apa yang digunakan untuk mengelola efek samping seperti data fetching?', 'multiple_choice', '["useState", "useEffect", "useMemo", "useContext", "useRef"]'::jsonb, 'useEffect', 30),
(v_exam2, 'Jelaskan perbedaan synchronous dan asynchronous dalam konteks pemrosesan Web API!', 'essay', NULL, 'Synchronous blocking, asynchronous non-blocking.', 40);

-- Exam Attempt
Expand Down
Loading