Repository navigation
Keep one user row per person, as sections does - #40
Merged
Merged
Conversation
Replace the account table and the per-course user rows with one `users` row per person, copied from sections' User: email and Canvas ID unique, roles in each course as sets of course keys (staff, admin, student), and the Canvas courses and global admin flag that were on the account. Signing in claims a user moved from the per-course sites by email, and merges one under a changed email, as sections does. Heartbeats move to their own table, one per person per course, so being online in one course doesn't count in another. The connect handler now commits them; it didn't before, so nobody showed as online. The migration merges the old rows by email (ignoring case), the newest name and Online Setup links winning and a signed-in account's Canvas details over both, and re-points tickets, ticket events, group attendance and chat messages at the merged rows. Adapted from sections' 0002_single_user; it can't be undone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #40 +/- ##
==========================================
+ Coverage 78.56% 80.80% +2.23%
==========================================
Files 14 14
Lines 1418 1500 +82
Branches 198 209 +11
==========================================
+ Hits 1114 1212 +98
+ Misses 246 237 -9
+ Partials 58 51 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🚀 Staging Preview Deployed! |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With one row per person, joining or starting a group in one course took the person out of their group in another course, which could delete that group's ticket. Leaving now only looks at the current course's groups. The migration now refuses, before changing anything, references to user rows that don't exist (which it would have blanked, or stopped partway on), and one email shared by two bCourses accounts (where keeping either would lock the other out), listing what to fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds tests/test_users.py: roles in each course, global admins, looking people up (list_users, get_user), who's online in each course, old and racing heartbeats, closing groups everyone has left, and merging two rows' heartbeats and roles. The migration's tests now cover a row with no email, a blank name, tables without foreign keys, an empty database, an unknown table referencing users, and the downgrade refusing. The unknown-table check moves before anything changes, as SQLite can't roll back a half-done migration, and two branches that can't happen here go (old rows always have a course, and the account table always exists at this revision). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tickets A rolled-back run on staging's database (84,689 user rows, 544k tickets, 2.1M ticket events) took over 30 minutes before it was stopped: it rewrote every reference twice and inserted rows one statement at a time. Each person now keeps their oldest row's id, so only references to their other rows change, in one UPDATE ... FROM per column, and rows go in in batches. The same run now takes about 3 minutes, inside Cloud Run's 240-second startup window. The run also found two things staging (and likely prod) has: - 34 cs161 tickets whose user row doesn't exist (the foreign key was added NOT VALID). They get a placeholder person, "Unknown user <id>", under the missing id, so their history stays. - One staff row from 2020 with no email, which nothing refers to. Rows like it are skipped; one that something refers to still stops the migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
accounttable and the per-courseuserrows with oneusersrow per person, copied from sections'User(and its0002_single_usermigration).users(oh_queue/models.py): email and Canvas ID unique (Canvas ID empty for people moved from the per-course sites who haven't signed in since),is_global_admin,canvas_courses, and roles as sets of course keys (staff_offerings,admin_offerings,student_offerings). Inside a course,is_staffandis_adminanswer for that course, as in sections.set_role,is_member_of,canvas_roles_in,absorbandwith_emailare sections'.oh_queue/login.py): as in sections. A user is found by Canvas ID. A first sign-in claims a moved user with the same email. A changed email merges a moved user under the new email. An email that belongs to another bCourses account is refused. Opening a course syncs the person's role there from Canvas (sync_offering_role). Session ids are prefixeduser-, so oldaccount-cookies sign people out instead of matching the wrong row.call_url,doc_url) are now per person, not per course. The Online Setup page says so: a note above the form, read with each field, and "(all courses)" in both labels.connectset the heartbeat but never committed it, so the online counts only included staff helping a ticket. It commits now. Two tabs creating the first heartbeat at the same moment don't cause an error.list_userslists the course's members.get_usershows anyone in the course, or anyone who was helped or helped in it (global admins have no role in a course of their own).logged_inno longer readscurrent_user.course, which no longer exists. It now just requires a signed-in user; people outside the course are already turned away at sign-in.Migration (
5b9e2c7d1f30)userrows by email, ignoring case. The newest name and Online Setup links win, and a signed-in account's Canvas name and details win over both.UPDATE … FROMper column (ticket.user_id/helper_id,ticket_event,group_attendance,chat_message). Rows are inserted in batches.@oh-queue.invalidemail), so their history stays.user.accountanduser. It can't be undone (downgrade raises), as in sections.Rolled-back run on staging's data (84,689 user rows, 544k tickets, 2.1M ticket events): it finished in 174s, with 31,789 people, nothing left dangling, and all foreign keys on
users. Then it rolled back; staging is unchanged. Staging's Cloud Run startup probe allows 240s, and the migration runs before the server listens, so it fits but without much margin. That run also found what the placeholders and the email-less skip handle: 34 cs161 tickets (2020–22) belonging to missing user 14132 (ticket.user_id's foreign key isNOT VALID), and one 2020 staff row with no email. Prod likely has both.Also tested on SQLite (
tests/test_migrations.py) and on a local Postgres with copy-style tables.Not copied from sections
These belong in separate PRs if we want them:
canvas_synced_atTest plan
pytest(167 passed), covering every changed line and branch inoh_queue/and the migration, includingtests/test_users.py(roles, lookups, presence per course, group cleanup, merging) and the migration's refusals and edge casespytest tests/e2e tests/a11y(96 passed)flake8🤖 Generated with Claude Code