Skip to main content

Migrating from v3 to v4

Draft

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.js only 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​

  1. Pull the latest Judgels repository, and link the existing env directory as env in deployment/v4-ubuntu-24.04/ansible. The hosts.ini file does not need any changes.

  2. In env/vars.yml, set the Judgels version, and replace app_mode with the training and rating flags. If app_mode was TLX:

    -app_version: '3.0.0'
    -app_mode: TLX
    +app_version: '4.0.0'
    +training_enabled: true
    +rating_enabled: true

    If app_mode was unset or JUDGELS, just remove it; both flags default to false.

    IMPORTANT: v4 no longer reads app_mode. If we only bump app_version on a TLX deployment, training and ratings will be turned off after the upgrade.

  3. Keep the userRegistration_*, userResetPassword_* and googleAnalytics_trackingId variables 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​

  1. 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 when training_enabled is true.
  2. If Google Analytics was configured, verify that its tracking ID is shown in the Google Analytics section of the same page.
  3. Go to System → Roles, and verify that the admins are the same as before.
  4. Log out. Verify that the Register and "Forgot your password?" links are shown only when their feature is turned on.
  5. If registration is turned on, register a new user, and verify that the activation email arrives.
  6. If Google sign-in was configured, verify that the Google sign-in button is shown on the login page.
  7. Verify that the Courses, Problems and Submissions menus are shown only when training_enabled is true, and the Ranking menu only when rating_enabled is true.

At this point, Judgels v4 should be fully operational.

E. Cleaning up​

After v4 has started once:

  1. (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
  2. (Optional) Once we are sure we will not roll back to v3, we can remove the old jophiel_user_role table. 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:

FlagTurns on
training_enabledCourses, the problem and submission lists, the training admin pages and role, the submission history on profiles, and user registration and password reset
rating_enabledThe 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_enabled is true, the registration settings are copied: enabled, reCAPTCHA (from userRegistration_useRecaptcha), and the activation email template.
  • If userResetPassword_enabled is true, 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 mailer is configured;
  • reCAPTCHA is turned on, but no recaptcha is 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 to judgels-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_trackingId to 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:

v3v4
Account adminSYSTEM_ADMIN
Problem adminPROBLEM_ADMIN
Contest adminCONTEST_ADMIN
Training adminTRAINING_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.

v3v4Notes
POST /api/v2/user-account/registerPOST /api/v4/account/registerNow rejects a taken username or email with AccountRegistrationUsernameAlreadyExists or AccountRegistrationEmailAlreadyExists.
POST /api/v2/user-account/register-googlePOST /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-passwordPOST /api/v4/account/reset-password
GET /api/v2/users/registration/web/configGET /api/v2/user-web/configRemoved. 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-getPOST /api/v2/users/exportSame request and response.
POST /api/v2/users/batch-upsertPOST /api/v2/users/importSame request and response.
POST /api/v2/contests/{contestJid}/contestants/batch-upsertPOST /api/v2/contests/{contestJid}/contestants/addResponse field insertedContestantProfilesMap is now addedContestantProfilesMap.
POST /api/v2/contests/{contestJid}/contestants/batch-deletePOST /api/v2/contests/{contestJid}/contestants/removeResponse field deletedContestantProfilesMap is now removedContestantProfilesMap.
POST /api/v2/contests/{contestJid}/managers/batch-upsertPOST /api/v2/contests/{contestJid}/managers/addResponse field insertedManagerProfilesMap is now addedManagerProfilesMap.
POST /api/v2/contests/{contestJid}/managers/batch-deletePOST /api/v2/contests/{contestJid}/managers/removeResponse field deletedManagerProfilesMap is now removedManagerProfilesMap.
POST /api/v2/contests/{contestJid}/supervisors/batch-upsertPOST /api/v2/contests/{contestJid}/supervisors/addResponse field upsertedSupervisorProfilesMap is now addedSupervisorProfilesMap.
POST /api/v2/contests/{contestJid}/supervisors/batch-deletePOST /api/v2/contests/{contestJid}/supervisors/removeResponse field deletedSupervisorProfilesMap is now removedSupervisorProfilesMap.
PUT /api/v2/user-rolesPUT /api/v2/user-roles/{userJid} and POST /api/v2/user-roles/addSee User role API.
GET /api/v2/user-search/username-exists/{username}GET /api/v2/profiles/username/{username}/basicRemoved. The basic profile returns 404 for an unknown username.
POST /api/v2/user-search/username-to-jidGET /api/v2/profiles/username/{username}/basicRemoved. The basic profile now includes userJid; look up one username at a time.
GET /api/v2/user-search/email-exists/{email}NoneRemoved, 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/problemsGET /api/v4/training/problems
GET /api/v2/problems/tagsGET /api/v4/training/problems/tags
GET /api/v2/stats/usersGET /api/v4/training/stats/users
GET /api/v2/stats/users/topGET /api/v4/training/stats/users/top
GET, POST /api/v2/submissions/programmingGET, 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/regradePOST /api/v4/training/submissions/programming/regrade
POST /api/v2/submissions/programming/{submissionJid}/regradePOST /api/v4/training/submissions/programming/{submissionJid}/regrade
GET, POST /api/v2/submissions/bundleGET, POST /api/v4/training/submissions/bundle
GET /api/v2/submissions/bundle/answersGET /api/v4/training/submissions/bundle/answers
GET /api/v2/submissions/bundle/summaryGET /api/v4/training/submissions/bundle/summary
POST /api/v2/submissions/bundle/regradePOST /api/v4/training/submissions/bundle/regrade
POST /api/v2/submissions/bundle/{submissionJid}/regradePOST /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 fieldv4 role
account: SUPERADMINSUPERADMIN
account: ADMINSYSTEM_ADMIN
problem: ADMINPROBLEM_ADMIN
contest: ADMINCONTEST_ADMIN
training: ADMINTRAINING_ADMIN
  • GET /api/v2/user-roles: each item's role object is now roles, a set of roles. It returns only the roles the caller may manage.
  • GET /api/v2/user-roles is now paginated: data is a page (page, totalCount, pageNumber, pageSize) of 20 users, most recently granted first, selected with the page query param. The new role query 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 new term query 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. Use PUT /api/v2/user-roles/{userJid} with a set of roles to replace one user's roles, or POST /api/v2/user-roles/add with {"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: role is now roles, a set of roles.

Changed responses​

  • GET /api/v2/user-web/config has new fields: appFooter, googleAuthClientId, recaptchaSiteKey, ratingEnabled, trainingEnabled, trainingAccountRegistrationEnabled, trainingAccountPasswordResetEnabled and trainingGoogleAnalyticsTrackingId.
  • GET /api/v2/settings has new fields: trainingAccountRegistration, trainingAccountPasswordReset, trainingGoogleAnalytics, mailerConfigured and recaptchaConfigured. PUT /api/v2/settings accepts the first three. app has a new field, footer: HTML shown in the footer after "Powered by Judgels".
  • GET /api/v2/profiles/{userJid}/basic now includes userJid.
  • PUT /api/v2/contests/{contestJid}/modules/config no longer requires scoreboard; 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.