Skip to content

Fix Seed: store demo question options as JSON arrays and repair existing rows - #30

Merged
mfarim merged 1 commit into
mainfrom
fix/seed-question-options
Nov 27, 2026
Merged

mfarim merged 1 commit into
mainfrom
fix/seed-question-options

Conversation

@mfarim

@mfarim mfarim commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Problem

seed_demo_data.sql inserted question options as a JSON object ({"A": "10", "B": "20", ...}). Question.options is mapped as List<String>, so Jackson cannot read those rows.

On any database seeded with the demo data, including the public demo, the demo exams were unusable:

  • opening exam 1 or 2 in the question editor returned 500 (GET /api/v1/exams/{id}/questions)
  • starting either exam returned 500 (POST /api/v1/exams/{id}/start)

Changes

  • seed_demo_data.sql: the four affected questions now use JSON arrays, the same format the question editor writes. True/false questions use ["Benar", "Salah"].
  • V4__fix_question_options_format.sql: converts existing object-shaped options into arrays, ordered by key. Keys are A..E or Benar/Salah, so the original option order is kept.
    • Only rows where jsonb_typeof(options) = 'object' are touched. The application always writes arrays, so questions created by teachers are not affected.
    • On a clean database it changes nothing.

Testing

Isolated Docker stack:

Scenario Editor Start exam Grading
main + old seed (before) 500 500 –
Old seeded DB + V4 migration 200 200 correct options graded correct (30 + 30)
Fresh DB + new seed 200 200 correct options graded correct (30 + 30)

Grading also stays correct with shuffle_options enabled. The answer is matched by option text, not position.

Deploy note

Back up the database first. V4 runs automatically when the backend starts.

…ting rows

seed_demo_data.sql inserted question options as a JSON object ({"A": "10", ...}),
but Question.options is mapped as List<String>, so opening or starting the demo
exams failed with 500.

- Seed the four affected questions with JSON arrays, the format the editor writes.
- Add V4 migration that converts existing object-shaped options into arrays
  (ordered by key, so the original option order is kept). Rows already stored as
  arrays are not touched.
@mfarim mfarim self-assigned this Nov 27, 2026
@mfarim
mfarim merged commit aca7832 into main Nov 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant