Migrating from v3 to v4
v4 is not released yet. This guide is a draft and will grow as v4 changes land.
A. Summary
We can upgrade from v3 to v4 in place, reusing the same VMs and database. The only change we need to make by hand is in env/vars.yml: app_mode is replaced by two flags, training_enabled and rating_enabled.
Everything else is migrated automatically on the first start:
- User registration, password reset and Google Analytics are moved from the config files to the database, and are managed in the Admin tab from now on.
- User roles are moved to a new table, and every problem author becomes a problem writer.
- The client gets its config from the server, so
judgels-client.jsonly contains the API URL.
There are also some breaking API changes; see Appendix: API changes.
B. Backing up existing config
Back up env/vars.yml, as we will change it in the next section. Optionally, back up the database too, in case we need to roll back to v3.
C. Deploying Judgels v4
Pull the latest Judgels repository, and link the existing env directory as
envindeployment/v4-ubuntu-24.04/ansible. Thehosts.inifile does not need any changes.In
env/vars.yml, set the Judgels version, and replaceapp_modewith the training and rating flags. Ifapp_modewasTLX:-app_version: '3.0.0'
-app_mode: TLX
+app_version: '4.0.0'
+training_enabled: true
+rating_enabled: trueIf
app_modewas unset orJUDGELS, just remove it; both flags default tofalse.IMPORTANT: v4 no longer reads
app_mode. If we only bumpapp_versionon aTLXdeployment, training and ratings will be turned off after the upgrade.Keep the
userRegistration_*,userResetPassword_*andgoogleAnalytics_trackingIdvariables for now. v4 will copy them to the database on its first start.
Then, run the deploy playbook:
ansible-playbook -e @env/vars.yml playbooks/deploy.yml
This will deploy the server, client, and graders together, and migrate the database automatically. We don't need to rerun the provision playbook.
D. Verifying
- Log in as
superadmin, and go to the Admin tab, then System → Settings → Training. Verify that the Account registration and Account password reset sections match the old config. The Training tab is shown only whentraining_enabledistrue. - If Google Analytics was configured, verify that its tracking ID is shown in the Google Analytics section of the same page.
- Go to System → Roles, and verify that the admins are the same as before.
- Log out. Verify that the Register and "Forgot your password?" links are shown only when their feature is turned on.
- If registration is turned on, register a new user, and verify that the activation email arrives.
- If Google sign-in was configured, verify that the Google sign-in button is shown on the login page.
- Verify that the Courses, Problems and Submissions menus are shown only when
training_enabledistrue, and the Ranking menu only whenrating_enabledistrue.
At this point, Judgels v4 should be fully operational.
E. Cleaning up
After v4 has started once:
- (Optional) We can remove the following variables from
env/vars.yml, which are no longer used. They will be removed in the release after v4.0.userRegistration_*userResetPassword_*googleAnalytics_trackingId
- (Optional) Once we are sure we will not roll back to v3, we can remove the old
jophiel_user_roletable. See User roles.
F. What changed
Training and rating flags
v3 had two modes: JUDGELS and TLX. Training and ratings were only available in TLX mode. v4 has no modes; instead, each feature has its own flag:
| Flag | Turns on |
|---|---|
training_enabled | Courses, the problem and submission lists, the training admin pages and role, the submission history on profiles, and user registration and password reset |
rating_enabled | The Ranking page, the top ratings on the home page, the Ratings admin page, and rating contests |
Both flags default to false. They are only read by the server, which passes them to the client.
User registration and password reset
User registration and password reset are now part of training, and only work when training_enabled is true. A contest-only deployment has no self-service accounts: admins create the users, and the Register, "Forgot your password?" and My account pages are hidden.
They are now turned on and configured in the Admin tab, under System → Settings → Training, instead of in judgels-server.yml. The mailer and recaptcha config stay in judgels-server.yml, because they contain secrets.
On its first start, v4 copies the old config to the database, so we don't need to re-enter anything:
- If
userRegistration_enabledistrue, the registration settings are copied: enabled, reCAPTCHA (fromuserRegistration_useRecaptcha), and the activation email template. - If
userResetPassword_enabledistrue, the password reset settings are copied: enabled, and the request and reset email templates. - A feature that is turned off in the config is not copied, and stays off.
- Settings that already exist in the database are never overwritten, so later restarts will not undo changes made in the Admin tab.
The Admin tab will reject saving these settings when:
- registration or password reset is turned on, but no
maileris configured; - reCAPTCHA is turned on, but no
recaptchais configured; - the activation email body or the password reset request email body does not contain
{{emailCode}}; - training is turned off.
Google sign-in and Google Analytics
judgels-client.js now only contains the API URL. The client gets everything else from the server:
- Google sign-in: the client ID is still read from
auth_google_clientId, but is now only written tojudgels-server.yml. - Google Analytics: the tracking ID is now set in the Admin tab, under System → Settings → Training, and is only used when training is on. On its first start, v4 copies
googleAnalytics_trackingIdto the database, unless a tracking ID has already been saved there.
User roles
A user can now have a set of roles, instead of one role per area. The existing roles are migrated as follows:
| v3 | v4 |
|---|---|
| Account admin | SYSTEM_ADMIN |
| Problem admin | PROBLEM_ADMIN |
| Contest admin | CONTEST_ADMIN |
| Training admin | TRAINING_ADMIN |
| - | PROBLEM_WRITER, given to every problem author, except superadmin |
The superadmin user's role was not stored in v3; v4 adds its SUPERADMIN role on every start.
In v3, any user could write problems. In v4, the new problem admin pages require the PROBLEM_WRITER role, so the migration gives it to everyone who created a problem. Other users, including partners who never created a problem, need to be given the role by an admin in the Admin tab, under System → Roles, before they can write problems.
In the database, the roles are moved from the old jophiel_user_role table, which has one row per user and one column per area, to a new judgels_user_role table, which has one row per role of a user. The old table is kept, but is no longer used by v4.
IMPORTANT: if we roll back to v3, it will use the old table again, and role changes made in v4 will be lost.
Appendix: API changes
The client that ships with v4 already uses the new API. All paths are under the server API domain, e.g. https://api.judgels.example.com.
Moved or renamed endpoints
The old paths below are removed, unless noted otherwise.
| v3 | v4 | Notes |
|---|---|---|
POST /api/v2/user-account/register | POST /api/v4/account/register | Now rejects a taken username or email with AccountRegistrationUsernameAlreadyExists or AccountRegistrationEmailAlreadyExists. |
POST /api/v2/user-account/register-google | POST /api/v4/account/register-google | |
POST /api/v2/user-account/activate/{emailCode} | POST /api/v4/account/activate/{emailCode} | |
POST /api/v2/user-account/resend-activation-email/{email} | POST /api/v4/account/resend-activation-email/{email} | |
POST /api/v2/user-account/request-reset-password/{email} | POST /api/v4/account/request-reset-password/{email} | |
POST /api/v2/user-account/reset-password | POST /api/v4/account/reset-password | |
GET /api/v2/users/registration/web/config | GET /api/v2/user-web/config | Removed. Its useRecaptcha and recaptcha.siteKey are replaced by recaptchaSiteKey in the user web config, which is set only when registration and its reCAPTCHA are on. |
POST /api/v2/users/batch-get | POST /api/v2/users/export | Same request and response. |
POST /api/v2/users/batch-upsert | POST /api/v2/users/import | Same request and response. |
POST /api/v2/contests/{contestJid}/contestants/batch-upsert | POST /api/v2/contests/{contestJid}/contestants/add | Response field insertedContestantProfilesMap is now addedContestantProfilesMap. |
POST /api/v2/contests/{contestJid}/contestants/batch-delete | POST /api/v2/contests/{contestJid}/contestants/remove | Response field deletedContestantProfilesMap is now removedContestantProfilesMap. |
POST /api/v2/contests/{contestJid}/managers/batch-upsert | POST /api/v2/contests/{contestJid}/managers/add | Response field insertedManagerProfilesMap is now addedManagerProfilesMap. |
POST /api/v2/contests/{contestJid}/managers/batch-delete | POST /api/v2/contests/{contestJid}/managers/remove | Response field deletedManagerProfilesMap is now removedManagerProfilesMap. |
POST /api/v2/contests/{contestJid}/supervisors/batch-upsert | POST /api/v2/contests/{contestJid}/supervisors/add | Response field upsertedSupervisorProfilesMap is now addedSupervisorProfilesMap. |
POST /api/v2/contests/{contestJid}/supervisors/batch-delete | POST /api/v2/contests/{contestJid}/supervisors/remove | Response field deletedSupervisorProfilesMap is now removedSupervisorProfilesMap. |
PUT /api/v2/user-roles | PUT /api/v2/user-roles/{userJid} and POST /api/v2/user-roles/add | See User role API. |
GET /api/v2/user-search/username-exists/{username} | GET /api/v2/profiles/username/{username}/basic | Removed. The basic profile returns 404 for an unknown username. |
POST /api/v2/user-search/username-to-jid | GET /api/v2/profiles/username/{username}/basic | Removed. The basic profile now includes userJid; look up one username at a time. |
GET /api/v2/user-search/email-exists/{email} | None | Removed, because it let anyone find out which emails have accounts. Registration checks taken emails itself. |
Training-wide endpoints
The training-wide endpoints moved under /api/v4/training. The old /api/v2 paths are still served, with the same requests and responses, but are deprecated, and will be removed in the release after v4.0.
| v3 (deprecated) | v4 |
|---|---|
GET /api/v2/problems | GET /api/v4/training/problems |
GET /api/v2/problems/tags | GET /api/v4/training/problems/tags |
GET /api/v2/stats/users | GET /api/v4/training/stats/users |
GET /api/v2/stats/users/top | GET /api/v4/training/stats/users/top |
GET, POST /api/v2/submissions/programming | GET, POST /api/v4/training/submissions/programming |
GET /api/v2/submissions/programming/{submissionJid} | GET /api/v4/training/submissions/programming/{submissionJid} |
GET /api/v2/submissions/programming/id/{submissionId} | GET /api/v4/training/submissions/programming/id/{submissionId} |
POST /api/v2/submissions/programming/regrade | POST /api/v4/training/submissions/programming/regrade |
POST /api/v2/submissions/programming/{submissionJid}/regrade | POST /api/v4/training/submissions/programming/{submissionJid}/regrade |
GET, POST /api/v2/submissions/bundle | GET, POST /api/v4/training/submissions/bundle |
GET /api/v2/submissions/bundle/answers | GET /api/v4/training/submissions/bundle/answers |
GET /api/v2/submissions/bundle/summary | GET /api/v4/training/submissions/bundle/summary |
POST /api/v2/submissions/bundle/regrade | POST /api/v4/training/submissions/bundle/regrade |
POST /api/v2/submissions/bundle/{submissionJid}/regrade | POST /api/v4/training/submissions/bundle/{submissionJid}/regrade |
User role API
A user now holds a set of roles instead of one role object with a field per area. The roles are SUPERADMIN, SYSTEM_ADMIN, PROBLEM_ADMIN, PROBLEM_WRITER, CONTEST_ADMIN and TRAINING_ADMIN.
| v3 role field | v4 role |
|---|---|
account: SUPERADMIN | SUPERADMIN |
account: ADMIN | SYSTEM_ADMIN |
problem: ADMIN | PROBLEM_ADMIN |
contest: ADMIN | CONTEST_ADMIN |
training: ADMIN | TRAINING_ADMIN |
GET /api/v2/user-roles: each item'sroleobject is nowroles, a set of roles. It returns only the roles the caller may manage.GET /api/v2/user-rolesis now paginated:datais a page (page,totalCount,pageNumber,pageSize) of 20 users, most recently granted first, selected with thepagequery param. The newrolequery param, which can be repeated, lists only the users holding any of the given roles; without it, the users holding any role the caller may manage are listed. The superadmin is never listed. The newtermquery param lists only the users whose username contains it.PUT /api/v2/user-roles, which took a map of username to role object, is removed. UsePUT /api/v2/user-roles/{userJid}with a set of roles to replace one user's roles, orPOST /api/v2/user-roles/addwith{"usernames": [...], "roles": [...]}to add roles to many users. The superadmin's roles cannot be changed; adding roles to it succeeds without changing anything, as it already holds every role.GET /api/v2/user-web/config:roleis nowroles, a set of roles.
Changed responses
GET /api/v2/user-web/confighas new fields:appFooter,googleAuthClientId,recaptchaSiteKey,ratingEnabled,trainingEnabled,trainingAccountRegistrationEnabled,trainingAccountPasswordResetEnabledandtrainingGoogleAnalyticsTrackingId.GET /api/v2/settingshas new fields:trainingAccountRegistration,trainingAccountPasswordReset,trainingGoogleAnalytics,mailerConfiguredandrecaptchaConfigured.PUT /api/v2/settingsaccepts the first three.apphas a new field,footer: HTML shown in the footer after "Powered by Judgels".GET /api/v2/profiles/{userJid}/basicnow includesuserJid.PUT /api/v2/contests/{contestJid}/modules/configno longer requiresscoreboard; a missing module config is left as it is.
Endpoints that depend on the training and rating flags
In v3, most of these were served only in TLX mode. In v4, they return 404 unless their flag is on:
training_enabled: the account registration and password reset endpoints, the training-wide endpoints above,/api/v2/{curriculums,courses,chapters,archives,problemsets}/...,/api/v2/lessons/{lessonJid}/render/...and/api/v4/lessons/....rating_enabled:/api/v2/user-rating/...(served in every mode in v3) and/api/v2/contest-rating/....
New endpoints
v4 adds the endpoints behind the new problem and lesson admin pages: /api/v4/problems/..., /api/v4/lessons/..., and problem test submissions at /api/v4/problems/{problemJid}/submissions/{programming,bundle}/.... They replace the old admin web interface for these pages, and need no migration.