Commits
2026-09-16
✨ feat: the class×course instance is the academic anchor (K-12 remodel)Ahmet Kaan Gümüş · ae84034
✨ feat: the class×course instance is the academic anchor (K-12 remodel)
`course` was a school-wide singleton: enrollment, exams, sessions,
roll-call and homework all keyed on it, so two class sections teaching the same
course shared one roster, one exam set and one timetable. This moves the
academic anchor to `class_course` — the per-class instance — and rebuilds
the academic model around Turkish K-12.
Schema (migrations/school/20260916000001_k12_remodel.sql): `class_course`
becomes an instance (ders_saati, counts_toward_karne, enrollment_count,
class_course_teacher); enrollment re-keys to (class_course, app_user);
exam carries class_course + term (+ exam_audience for shared exams);
course_session / session_attendance / homework re-key; `class_member` is a
soft-leave history table (uuid PK, joined_at/left_at, partial unique index
on the live stint); `academic_year` sits above `term`; `class_group` links
a year, not a term; new `course_membership` (clubs/study), `karne_snapshot`;
settings gain branches/excuse_kinds/absence limits/timezone; profile gains
branch. Drops/recreates the identity-changing tables (pre-customer; the
migration resets every counter on a kept table that pointed at a dropped
one).
Layers: domain/db/service/web rewritten to the instance seam, with
`ensure_instance_teacher` gating instance writes (D10), the report card computed per
instance and weighted by ders_saati, an absence report, `/instances`
and `/academic-years` nests, and `/classes/{id}/instances`. Capacity and
the seat-claim 409 are gone; detach sweeps the whole instance subtree and
unlinks its blob keys.
Gates: cargo check --all-targets, SQLX_OFFLINE check (cache regenerated),
doc_sync, spec_bounds, limits_completeness, clippy -D warnings all green;
cargo nextest run 1370/1370.2026-09-12
🗃️ feat!: port courses, subjects, terms, enrollments, sessions, attendance to sqlx/PostgresAhmet Kaan Gümüş · f734c6aBrowse files
🗃️ feat: pub fn uuid(&self) accessor on all 34 Uuid id newtypesAhmet Kaan Gümüş · b3ab76fBrowse files
🗃️ fix: appointment.slot nullable ON DELETE SET NULL (dangling-ref booking contract)Ahmet Kaan Gümüş · d9b4e8eBrowse files
2026-09-11
🧹 chore: split course_session into domain/db/service layersAhmet Kaan Gümüş · 0ddaa5d
🧹 chore: split course_session into domain/db/service layers domain/course_session.rs keeps the pure surface: CourseSessionId (its ULID mint stays per the monotonic_id precedent), SessionTopic, the entity with pub(crate) fields, getters, and the topic-bound validation test. db/course_session.rs takes the query executors whole: create (the cap::touch_and_create claim that bumps the course row in the same transaction), read, list_for_course, the field-scoped update, and the cascading delete transaction; the orphan-race persistence test rides along. service/course_session.rs takes resolve_session_teacher out of the web layer — the scheduling role floor (a student cannot teach a lesson) — plus the thin doors the web layer now calls instead of the removed inherent methods. No locks: course_session never held one; the range guard rides inside the UPDATE's WHERE. web/sessions.rs and web/courses.rs re-point every CourseSession call and the shared resolve_session_teacher import to service::course_session; call sites in domain/session_attendance.rs (incl. tests) and doc links in domain/event.rs go to db::course_session. tests/ import fixes only.
2026-08-05
🔗 fix: stop a course's children outliving the courseAhmet Kaan Gümüş · 0251364
🔗 fix: stop a course's children outliving the course
Exam, CourseSession and Subject creates were bare db.create calls that
wrote no key the delete cascade writes, so a create racing
DELETE /courses/{id} committed alongside it. The orphans were not merely
stray: every exam route funnels through course_of, which answered 500
forever, so the row was undeletable while still listed to manager+.
Sessions and subjects 404'd the same way.
All three now ride cap::touch_and_create against the course row.
Course::delete also skipped the two bank_question cleanups its per-entity
siblings perform, leaving source_exam and subject pointing at deleted
records — contradicting the documented "null once that subject was
deleted".
Real-server measurement: 4/4 rounds orphaned before, 0/4 after.2026-08-02
fix: 🔩 close the leaks a five-domain hunt turned upAhmet Kaan Gümüş · a3fe8cf
fix: 🔩 close the leaks a five-domain hunt turned up Five hunters swept exams, homework/attendance, identity, money/scheduling and messaging/courses; a three-lens verifier panel then refuted three of the first fixes, and those corrections are folded in here. Leaks and races closed: - exam self-review gated on *any* mark, so a seq-1 grade opened the answer key forever — a student mid-retake read `correct` and `is_correct` off the sheet they were still writing. All four review reads now 409 while the caller's latest sitting is in progress. - roll call could land after its session was deleted, and the orphan was unremovable (its delete route 404s on the vanished session) while the attendance report went on counting it. The write now proves its parent exists in the same transaction, the way ExamResult::grade does. - a teacher could counter-propose and then approve their own proposal, committing the requester to a time only the teacher ever named; and even after that, re-proposing between the requester's read and their accept moved the meeting under them. Approve refuses while a proposal stands, and accept now pins the window it is answering. - two concurrent chatbot posts on one thread cross-attributed their answers — both replied to the second prompt, the first was never answered. The prompt id rides the request instead of being re-derived from write order. - a whiteboard participant demoted to `parent` kept drawing, and kept *reading* the live canvas for up to 15s. Every frame is authorized before delivery now, and a demotion sweeps the account off rosters. - a demotion to `parent` stranded event signups no one could free. Promotions are left alone (staff free their own seats) and closed lists are never rewritten. - the rate-limit bucket map was unbounded past 10k live keys and then scanned O(n) under the global mutex on every request. Eviction is bounded and never frees an exhausted bucket — the first attempt did, which traded a memory bug for an auth-bypass, so it is pinned by a test that floods at the victim's own spend. - session and event cascades ran as loose queries; a concurrent write slipped between them and orphaned rows, and for notes a blob nothing could ever reclaim. All three are one transaction now. - sixteen id generators still used Ulid::new(), whose random low bits scramble same-millisecond rows under the "newest first" the docs promise; five listings had no tie-break at all, so offset paging could skip or duplicate a row. Also: $session is a protected SurrealDB 3 variable — binding it fails the whole query as a bare 500, which is what hid the attendance fix. Accepted, documented, not fixed: one bank template instantiated into two exams copies `correct` into both, and the review gate is per-exam.
2026-07-27
fix: 🪢 guard writes in the database, not the processAhmet Kaan Gümüş · 6c87eca
fix: 🪢 guard writes in the database, not the process
Two replicas are live; every process-local lock silently stopped
meaning anything. Move the invariants into the writes themselves:
- count caps (enroll/register/files/threads) become a counter column
claimed by UPDATE .. WHERE n < cap (domain/cap.rs), backfilled once,
decremented in the same transaction as every child delete
- exam freeze, re-draft and grade gates ride inside the write's own
transaction (IF .. THROW); SESSION/WORK_ENTRY/EVENT locks die, range
checks fold into the UPDATE's WHERE (FieldUpdate::ordered)
- appointment decisions CAS on status+proposed window+decided_by;
bank/exam updates CAS on their editable columns
- rate limiter syncs local windows to a shared minute row every 2s,
fail-open when the database is down
- paged GETs run LIMIT/START in the database (domain/page.rs); sites
that post-filter in Rust stay web-sliced and say so
- exams.rs (3629 lines) splits into web/exams/{mod,attempts,questions,
images,review}; image uploads single-source in web/image.rs; the
bare-seq key rule lives once in domain/key.rs; migration SQL moves
to migration_sql.rs
Every new guard is mutation-proven (removing it fails a named test).
Migration adds counter columns + rate_limit table; backfill is
one-time, guarded by = NONE, and verified against the live volume.
Traps recorded: SurrealQL 'x ?? 0 > 0' parses as 'x ?? (0 > 0)'; the
embedded mem engine drops one of two concurrent writes yet answers Ok.2026-07-26
chore: 📦 give every constant one homeAhmet Kaan Gümüş · 78b25b5
chore: 📦 give every constant one home Constants were scattered across 18 modules: table names and migration SQL in database.rs, limits in config.rs and rate_limit.rs, magic strings sitting next to the only code that read them. Nobody could answer "what are all the hard values in this service?" without a grep. They all live in constant.rs now — validation bounds, the 37 SurrealDB table names, the PRE_REPAIR/MIGRATION/BACKFILL schema SQL, and the enum value tables that used to hide as associated consts (Role::ALL -> ROLES, Folder::SENDER -> SENDER_FOLDERS, and friends). Values are byte-identical; this changes no behavior. constant.rs now imports crate::domain for the enum types, an intra-crate cycle that compiles fine. Statics stayed where they were. A Mutex or a ULID generator is runtime state, not a constant, and moving them would only blur that line. Two guards keep the consolidation honest. limits_completeness.rs already failed on any pub const in constant.rs that is neither published through /limits nor excluded with a reason; the *_TABLE names are excused by shape rather than by 37 lines of boilerplate, but the excuse now requires the absence of a MAX_/MIN_/DEFAULT_ prefix so a real bound cannot hide behind the naming convention. And the move quietly dropped three rules off the end of the text-fold table, which every existing test still passed — so the circumflexed vowels are pinned, and search_fold_sql must emit one string::replace per rule or the needle and the column drift apart.
2026-07-25
fix: 🧩 finish the partial-PATCH sweep — 4 more handlers lost writesAhmet Kaan Gümüş · d773e7e
fix: 🧩 finish the partial-PATCH sweep — 4 more handlers lost writes 32bca26 routed six resources through `FieldUpdate` so a PATCH writes only the fields it was given. It stopped at six of ten. The remaining four still read the row unguarded and then wrote a field-scoped `SET` bound to that stale snapshot, so two concurrent PATCHes of different fields reverted each other, 200 OK, silently: - subjects and the two user routes (`apply_profile`/`apply_preferences`, four endpoints) move to `FieldUpdate`. No lock needed — neither has a cross-field check, so request-scoped values alone close it - course sessions get `SESSION_LOCK`, taken *before* the row read whenever `starts_at`/`ends_at` arrives, with the range merged and revalidated against the stored other end. The lock is not optional: converting to `FieldUpdate` without it re-introduces 9e25e0c, verified by disabling it and watching a one-ended PATCH store `starts_at > ends_at` with both requests answering 200 - bank questions instead take `BANK_LOCK.write()` before `owned_question`. This one is a genuine read-modify-write — the kind/choices/correct trio must merge from the stored row because choice ids carry the option pictures — so an exclusive lease over read+merge+write is the fix, the same shape as the exam PATCH. Per-field writes cannot express it - `subject.rs` also mints ids via `monotonic_id::next_ulid()` now, since subjects list `ORDER BY id ASC`; `bank_questions.rs` rustdoc stops calling a choice id a position Also verified safe and left alone: the exam and exam-question PATCHes already hold `EXAM_LOCK.write()` across read and write, settings uses a CAS retry, and messages/chatbot/questions/appointments write single fields. Each new suite races 20 rounds and reads the row back; every one fails if the stale refill is restored.
🎨 style: cargo fmt the tree before the audit fixesAhmet Kaan Gümüş · b4a5a00
🎨 style: cargo fmt the tree before the audit fixes Pure reformatting, no behaviour change: rustfmt wrapping plus its alphabetical `use`-list reordering across the files that had drifted. Kept separate so the correctness commits that follow carry only logic.
fix: 🔒 drain the whole-row save backlogAhmet Kaan Gümüş · 19ba18a
fix: 🔒 drain the whole-row save backlog - a whole-row .content(self) reverts any write that landed between the struct's read and its save; the gate flagged 14 sites and this empties it - course.rs was the only genuinely raceable one, in both directions: teachers[] is written by assign, unassign and the demotion sweep while Course::update rewrites the text columns, so staffing a course reverted a concurrent rename and a rename dropped a concurrent assignment. Both reproduced as failing tests first - assign/unassign now use array::distinct(array::append(...)) and teachers -= $usr rather than rewriting the array from a stale read - session, event, note, term, homework and work-entry updates are each their row's only writer and rewrite every mutable field, so no failing interleaving exists today; converted defensively anyway, following Subject::update, and not test-proven - the five create/upsert sites are annotated instead: each builds its struct in place from the request and never reads it back
2026-07-12
✨ feat(attendance): course sessions, roll call, work log, reportsAhmet Kaan Gümüş · 5b6aac1
✨ feat(attendance): course sessions, roll call, work log, reports
- course_session: a course's lesson (teacher, topic, required starts_at,
optional ends_at); managed under course rights like exams; explicit
teacher_id must hold teacher+; lists ordered by starts_at (timetable)
- session_attendance roll call: one row per session+user by composite id,
course denormalized so reports need no join; students never self-mark —
the session's teacher or a course manager marks enrolled students, and
the teacher's own presence row is manager+ only (no self-declared
presence); session/course deletes cascade roll-call rows
- work_entry staff timesheet (teacher+): check-in/out stamped by the
server clock only, so a client clock or crafted request can't forge
presence; one open stint per user held atomically — INSERT IGNORE on
the deterministic open_{user} id, check-out takes it via DELETE RETURN
BEFORE and re-files under a ULID; manager+ reads any log, corrects
closed stints (ordered instants), deletes entries
- attendance reports at /attendance/me and /attendance/{user} (teacher+),
mirroring the marks report: event tallies + session tallies +
per-course breakdown; rate = (present+late)/(present+absent+late) —
late attends, excused counts against no one; unenrolling hides marks
but never absences (attendance is a historical record)
- RequireManager extractor; check_time_range shared by events/sessions