Skip to content

Versioning and History#1346

Open
geraldnyeo wants to merge 39 commits intosource-academy:masterfrom
geraldnyeo:versions-feature
Open

Versioning and History#1346
geraldnyeo wants to merge 39 commits intosource-academy:masterfrom
geraldnyeo:versions-feature

Conversation

@geraldnyeo
Copy link
Copy Markdown
Contributor

@geraldnyeo geraldnyeo commented Mar 18, 2026

This PR implements the backend support for the "Versioning and History feature". It adds a "versions" table which tracks history for entries in the "answers" table, and implements the required version schema, controller, and routes.

This change is non-breaking and should be merged before source-academy/frontend#3659.

Database Changes

This PR adds a "versions" table with the following columns:

  • id
  • name
  • version: the content of the answer is stored here
  • answer_id
  • restored
  • restored_from
  • inserted_at
  • updated_at

Each entry in the table represents a version of an answer (from the answer table). There can be multiple versions for one answer.

The migration for this table has been added here: \priv\repo\migrations\20260219073155_create_versions.exs. To update the database to the latest version, run:

mix ecto.migrate

Database Design Decisions
Currently, each answer is indexed by a unique submission id + question id combination, which most methods and routes use. Multiple versions of the same answer would have the same submission id + question id combination, and storing them in the current answers table would introduce a lot of breaking changes, so we decided to store them in a separate versions table.

We also decided to store both the answer content in both the answer and versions table. Each version entry references an entry in the answers table (which cannot be null). Replacing the "answer" field in the answers table with some reference to the versions table (which also cannot be null) makes it difficult to create new answers, and requires an extra join every time an answer is searched for.

Routes

  • GET /v2/courses/:course_id/assessments/question/:questionid/version/history
  • POST /v2/courses/:course_id/assessments/question/:questionid/version/save
  • PUT /v2/courses/:course_id/assessments/question/:questionid/version/:versionid/name

Additional Notes

  • The schema.png in the README has not been updated to reflect these changes.

Related Issues / PRs

@geraldnyeo geraldnyeo added the Enhancement New feature or request label Mar 18, 2026
@RichDom2185
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces backend support for versioning and history of answers, which is a significant feature. The implementation adds a new versions table, along with the necessary schema, controller, and routes. The changes are generally well-structured, but there are several critical issues related to error handling and control flow that could lead to crashes. Specifically, several functions don't handle potential {:error, ...} tuples from find_team, leading to MatchError exceptions. There are also opportunities to reduce code duplication and improve adherence to Elixir conventions. I've provided specific comments and suggestions to address these points.

Updated migration to use up and down instead of change

Changed name of 'version' field in versions table to 'content'
@martin-henz martin-henz added the blocking something else needs this to be merged label Mar 26, 2026
@geraldnyeo geraldnyeo marked this pull request as ready for review April 6, 2026 09:40
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 6, 2026

Coverage Status

coverage: 88.577% (-0.3%) from 88.926% — geraldnyeo:versions-feature into source-academy:master

missing repo.insert after earlier rebase
This reverts commit cb11670.
Identifying source of test errors.
This reverts commit fde5d58.
Identifying source of test errors.
This reverts commit 91da5d2.
Identifying source of testing errors.
This reverts commit ba88128.
Identifying source of test errors.
This reverts commit c8942a8.
Identifying source of test errors.
repo insert previously removed during formatting
repo insert previously removed during formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocking something else needs this to be merged Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants