Repository navigation
Open
Labels
ready to buildDecided; can be built without further decisions (triage 2026-10-30)
Description
Reported on the PEERS deployment; the same bug exists on Census (shared shift-types code). Filing so the fix can be ported. Fixed on the peers-main branch in commits ab8fa94 and 68c1c90 — note it is not a clean cherry-pick onto main because it sits on top of peers-only shift features (cancel-shift notify, time_text columns), so it needs a manual port.
Symptom
Creating/editing a Shift Type, an admin can add one time (date + start/end + position/slots) but a second time "saves" with no error, then is gone after clicking Update and reopening.
Root causes (three, compounding)
op_shift_times.shift_instancehad a GLOBALUNIQUEkey, but the "Add time" dialog (ShiftTypesTimeDialogAdd.tsx) only checks a new Instance label against the current shift type's times. So a label another type already uses (e.g. one shift's "Monday Morning") passes the UI but violates the DB key.- The insert errors were swallowed.
handleTimeListAdd(api/shifts/types/index.ts) and the PATCH add/remove/position paths (api/shifts/types/[typeId]/index.ts) used un-awaitedforEach(async …), so the duplicate-key error never surfaced — the route returned 2xx and the row silently disappeared. (fetcherTriggeralso resolves the JSON body on non-2xx, so the client can't see a 4xx either.) - New-time position wrongly marked removed. Even with a unique label, the PATCH handler snapshotted existing
op_shift_time_positionrows after inserting the new time, so the freshly-inserted position (server id not in the request) was seen as orphaned and setremove_time_position=1. The form GET filters out any time whose position is removed → the time hides on reload.
Fix applied (peers-main)
- Per-type uniqueness: migrate
op_shift_timesfromUNIQUE(shift_instance)→UNIQUE(shift_name_id, shift_instance). Labels must be unique within a shift type but can repeat across types (matches the UI's within-type check). Migration:database/migrations/2026-07-02-shift-instance-per-type.sql. Safe on existing data (all instances already globally unique); no code looks up a row byshift_instancealone. - Server pre-check
findInstanceConflict()run before any writes → returns a clean 409 with a clear message naming the offending label (no partial writes). - Snapshot
dbTimePositionListBEFORE inserting new times, so a fresh position is never treated as orphaned. - Await the add/remove writes (
Promise.all) so errors propagate; insert each new time individually (old code re-inserted the wholetimeListAddonce per item). - Client: both shift-type submit handlers now treat a
statusCode >= 400body as an error so the message surfaces.
Still open (lower priority, not addressed)
- The remaining un-awaited
forEach(async …)in the PATCH time-position update/remove paths. generateId()returns before its async collision recheck resolves (recheck is effectively dead code).
Metadata
Metadata
Assignees
Labels
ready to buildDecided; can be built without further decisions (triage 2026-10-30)
Activity
mbhewitt commentedon Jul 2, 2026
Correction: the migration file is
migrations/006_shift_instance_per_type.sql(top-levelmigrations/dir, following the repo's 001–005 convention) — not thedatabase/migrations/path mentioned above.mbhewitt commentedon Nov 27, 2026
Folded in #477 (Shift instance uniqueness bug — borrow Peers' solution). Why: same shift-instance uniqueness bug (
scheduler_schema.sql:313). Link #533 too, but do not fold it (front-end cause, same editor). The migration named in #466 (006_shift_instance_per_type.sql) does not existIts description, for reference:
Approved by Mew on #851 (issue sweep, 2026-11-27).
Edit a shift from its page; reschedule notice (#901)
mbhewitt commentedon Nov 29, 2026
Shipped in PR #901 (prod 2027.G.00901.C, 2026-11-29). Migration 037 applied. Leaving this open for Mew to close.