Move cap/field_update/page toolkits from domain to new db layer
Browse files at this commit3763468e17cdf06e401e93e53ecabb6c5d623ceaParent: 8b8a45d- chore
- move cap/field_update/page toolkits from domain to new db layer
62 changed files +112 -108
- README.md +1 -1
- src/constant.rs +3 -3
- src/database.rs +1 -1
- src/domain/cap.rs → src/db/cap.rs +1 -1
- src/domain/field_update.rs → src/db/field_update.rs +2 -2
- src/db/mod.rs +5 -0
- src/domain/page.rs → src/db/page.rs +0 -0
- src/domain/appointment.rs +3 -3
- src/domain/appointment_slot.rs +3 -3
- src/domain/attendance.rs +1 -1
- src/domain/board.rs +2 -2
- src/domain/board_stroke.rs +2 -2
- src/domain/chatbot_message.rs +1 -1
- src/domain/chatbot_thread.rs +2 -2
- src/domain/class_blueprint.rs +1 -1
- src/domain/class_course.rs +1 -1
- src/domain/class_group.rs +5 -5
- src/domain/class_member.rs +2 -2
- src/domain/class_pump.rs +2 -2
- src/domain/course.rs +3 -3
- src/domain/course_note.rs +3 -3
- src/domain/course_note_file.rs +2 -2
- src/domain/course_session.rs +3 -3
- src/domain/dietary_profile.rs +1 -1
- src/domain/enrollment.rs +2 -2
- src/domain/event.rs +1 -1
- src/domain/exam.rs +1 -1
- src/domain/exam_attempt.rs +3 -2
- src/domain/exam_question.rs +3 -3
- src/domain/exam_result.rs +2 -2
- src/domain/fee_plan.rs +2 -2
- src/domain/fee_plan_assignment.rs +2 -2
- src/domain/homework.rs +2 -2
- src/domain/homework_file.rs +1 -1
- src/domain/homework_result.rs +1 -1
- src/domain/meal_attendance.rs +1 -1
- src/domain/meal_booking.rs +2 -2
- src/domain/meal_ledger.rs +1 -1
- src/domain/menu.rs +4 -4
- src/domain/menu_dish.rs +1 -1
- src/domain/message.rs +1 -1
- src/domain/mod.rs +0 -3
- src/domain/note.rs +2 -2
- src/domain/note_file.rs +2 -2
- src/domain/payment_ledger.rs +1 -1
- src/domain/pomodoro.rs +1 -1
- src/domain/rag_output.rs +1 -1
- src/domain/registration.rs +1 -1
- src/domain/session_attendance.rs +1 -1
- src/domain/settings.rs +1 -1
- src/domain/solution.rs +1 -1
- src/domain/subject.rs +3 -3
- src/domain/term.rs +2 -2
- src/domain/user.rs +4 -4
- src/domain/work_entry.rs +2 -2
- src/lib.rs +1 -0
- src/migration_sql.rs +3 -3
- src/tenant.rs +1 -1
- src/web/exams/mod.rs +1 -1
- src/web/homework.rs +1 -1
- src/web/mod.rs +2 -2
- src/web/settings.rs +1 -1
README.mdmodified+1 -1
| @@ -4565,7 +4565,7 @@ losing races at one process. Every invariant is therefore guarded where the | ||
| 4565 | 4565 | database itself decides the winner. Three tiers: |
| 4566 | 4566 | |
| 4567 | 4567 | 1. **Single-row conditional writes** — compare-and-set (`save_if_unchanged`), |
| 4568 | - `UPDATE … WHERE`, stored counters (`domain::cap`). A single-record write is | |
| 4568 | + `UPDATE … WHERE`, stored counters (`db::cap`). A single-record write is | |
| 4569 | 4569 | atomic, so of N concurrent tasks exactly the allowed number get a non-empty |
| 4570 | 4570 | result: the database decides the winner, the loser retries |
| 4571 | 4571 | (`CAS_UPDATE_RETRIES`) or gets a 409. |
src/constant.rsmodified+3 -3
| @@ -921,13 +921,13 @@ pub const BOARD_STROKE_TABLE: &str = "board_stroke"; | ||
| 921 | 921 | pub const BADGE_AWARD_TABLE: &str = "badge_award"; |
| 922 | 922 | /// One row per *name* the school's settings offer, keyed by the name itself: |
| 923 | 923 | /// how many rows still reference it, and whether it has been retired out of the |
| 924 | -/// list (see the reference counters in [`crate::domain::cap`]). | |
| 924 | +/// list (see the reference counters in [`crate::db::cap`]). | |
| 925 | 925 | pub const KIND_REF_TABLE: &str = "kind_ref"; |
| 926 | 926 | pub const SLOT_REF_TABLE: &str = "slot_ref"; |
| 927 | 927 | |
| 928 | 928 | // --- stored cap counters ------------------------------------------------- |
| 929 | 929 | |
| 930 | -/// The counter columns behind the count caps (see [`crate::domain::cap`]). | |
| 930 | +/// The counter columns behind the count caps (see [`crate::db::cap`]). | |
| 931 | 931 | /// Each one lives on the *parent* row, because a single-record conditional |
| 932 | 932 | /// `UPDATE` is the only guard a concurrent writer cannot outrun (a lock is |
| 933 | 933 | /// released around the round trip). Spelled here rather than at the call site |
| @@ -970,7 +970,7 @@ pub const CHATBOT_THREAD_COUNT_FIELD: &str = "chatbot_thread_count"; | ||
| 970 | 970 | /// The column a *grant* claim moves and puts back, so its transaction writes |
| 971 | 971 | /// the holder's own `user` record — the one key |
| 972 | 972 | /// [`crate::domain::user::User::set_role`] writes (see |
| 973 | -/// [`crate::domain::cap::role_claim`]). Any `option<int>` on the row would do: | |
| 973 | +/// [`crate::db::cap::role_claim`]). Any `option<int>` on the row would do: | |
| 974 | 974 | /// the claim nets zero and never reads it, so this is an alias rather than a |
| 975 | 975 | /// column of its own — a new one would mean a migration on a SCHEMAFULL table |
| 976 | 976 | /// for a value nothing ever observes. |
src/database.rsmodified+1 -1
| @@ -283,7 +283,7 @@ pub async fn init_mem_tenants() -> Result<Tenants, AppError> { | ||
| 283 | 283 | /// that is dropped and re-made on every call. For the tests whose subject is |
| 284 | 284 | /// the store's own conflict detection, which [`init_mem`]'s embedded engine |
| 285 | 285 | /// does not have: it drops one of two concurrent writes to a record and answers |
| 286 | -/// `Ok` to both (see [`crate::domain::cap`]), which *forges* the very | |
| 286 | +/// `Ok` to both (see [`crate::db::cap`]), which *forges* the very | |
| 287 | 287 | /// integrity failure those tests exist to catch — measured 2026-07-30 at 2 |
| 288 | 288 | /// failed runs in 36 on `memory`, against 0 in 10 000 rounds here. |
| 289 | 289 | /// |
src/domain/cap.rs → src/db/cap.rsrenamed+1 -1
| @@ -58,7 +58,7 @@ use crate::error::AppError; | ||
| 58 | 58 | static CLAIM_LOCK: Mutex<()> = Mutex::const_new(()); |
| 59 | 59 | |
| 60 | 60 | /// [`CLAIM_LOCK`], for a counter write that rides someone else's transaction |
| 61 | -/// instead of [`write`]'s — [`crate::domain::field_update::FieldUpdate`]'s term | |
| 61 | +/// instead of [`write`]'s — [`crate::db::field_update::FieldUpdate`]'s term | |
| 62 | 62 | /// move claims and releases inside the very `UPDATE`'s transaction, and still |
| 63 | 63 | /// owes the process one counter write at a time. |
| 64 | 64 | /// |
src/domain/field_update.rs → src/db/field_update.rsrenamed+2 -2
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | use surrealdb::types::{RecordId, SurrealValue, Value}; |
| 26 | 26 | |
| 27 | 27 | use crate::database::{Database, transaction_with_retry, write_with_retry}; |
| 28 | -use crate::domain::cap; | |
| 28 | +use crate::db::cap; | |
| 29 | 29 | use crate::error::AppError; |
| 30 | 30 | |
| 31 | 31 | /// The `THROW` markers [`FieldUpdate::refcount`]'s transaction aborts with: the |
| @@ -131,7 +131,7 @@ impl FieldUpdate { | ||
| 131 | 131 | /// count is what a delete guard reads, so the stranded one makes its parent |
| 132 | 132 | /// undeletable forever. `refused` is the answer when the claimed row is gone |
| 133 | 133 | /// (the conditional write doubles as the existence check, as in |
| 134 | - /// [`crate::domain::cap`]); the transaction then aborts, so the release and | |
| 134 | + /// [`crate::db::cap`]); the transaction then aborts, so the release and | |
| 135 | 135 | /// the row write never happened either. |
| 136 | 136 | /// |
| 137 | 137 | /// Only ever called alongside a `.set()` of the very column that carries the |
src/db/mod.rsadded+5 -0
| @@ -0,0 +1,5 @@ | ||
| 1 | +//! The only layer that executes queries. | |
| 2 | + | |
| 3 | +pub mod cap; | |
| 4 | +pub mod field_update; | |
| 5 | +pub mod page; |
src/domain/page.rs → src/db/page.rsrenamed+0 -0
src/domain/appointment.rsmodified+3 -3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | //! Two *cross-record* invariants live here, guarded very differently: |
| 6 | 6 | //! |
| 7 | 7 | //! - **One live booking per slot** — the `occupied` counter on the slot row, a |
| 8 | -//! [`cap`](crate::domain::cap) of one. Booking claims it *with* the booking | |
| 8 | +//! [`cap`](crate::db::cap) of one. Booking claims it *with* the booking | |
| 9 | 9 | //! row ([`claim_and_create`](cap::claim_and_create)); |
| 10 | 10 | //! rejecting or cancelling gives it back in the *same transaction* as the |
| 11 | 11 | //! status flip, so the slot frees itself with nothing to sweep. Both are |
| @@ -41,8 +41,8 @@ use crate::constant::{ | ||
| 41 | 41 | }; |
| 42 | 42 | use crate::database::{Database, lost_the_race}; |
| 43 | 43 | use crate::domain::appointment_slot::{AppointmentSlot, AppointmentSlotId}; |
| 44 | -use crate::domain::cap; | |
| 45 | -use crate::domain::page::PagedList; | |
| 44 | +use crate::db::cap; | |
| 45 | +use crate::db::page::PagedList; | |
| 46 | 46 | use crate::domain::timestamp::Timestamp; |
| 47 | 47 | use crate::domain::user::UserId; |
| 48 | 48 | use crate::error::{AppError, ValidationError}; |
src/domain/appointment_slot.rsmodified+3 -3
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | //! A teacher's published availability: "I am free here, book me". A slot is |
| 2 | 2 | //! nearly pure calendar: the one piece of booking state it carries is the |
| 3 | -//! `occupied` counter (a [`cap`](crate::domain::cap) of one), taken when a | |
| 3 | +//! `occupied` counter (a [`cap`](crate::db::cap) of one), taken when a | |
| 4 | 4 | //! booking is made and given back in the same transaction as the reject or |
| 5 | 5 | //! cancel that settles it — so the slot frees itself again, and unlike a UNIQUE |
| 6 | 6 | //! index it does not keep a dead booking's seat. Stored rather than counted |
| @@ -19,7 +19,7 @@ use crate::constant::{ | ||
| 19 | 19 | }; |
| 20 | 20 | use crate::database::{Database, transaction_with_retry}; |
| 21 | 21 | use crate::domain::appointment::{APPOINTMENT_LOCK, Appointment}; |
| 22 | -use crate::domain::cap; | |
| 22 | +use crate::db::cap; | |
| 23 | 23 | use crate::domain::monotonic_id::next_ulid; |
| 24 | 24 | use crate::domain::role::Role; |
| 25 | 25 | use crate::domain::timestamp::Timestamp; |
| @@ -579,7 +579,7 @@ impl AppointmentSlot { | ||
| 579 | 579 | mod tests { |
| 580 | 580 | use super::*; |
| 581 | 581 | use crate::constant::{MILLIS_PER_DAY, SLOT_OCCUPIED_FIELD}; |
| 582 | - use crate::domain::cap; | |
| 582 | + use crate::db::cap; | |
| 583 | 583 | |
| 584 | 584 | fn at(millis: i64) -> Timestamp { |
| 585 | 585 | Timestamp::from_millis(millis) |
src/domain/attendance.rsmodified+1 -1
| @@ -3,7 +3,7 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 3 | 3 | use crate::constant::{ATTENDANCE_TABLE, REGISTRATION_COUNT_FIELD}; |
| 4 | 4 | use crate::database::{Database, transaction_with_retry}; |
| 5 | 5 | use crate::domain::event::EventId; |
| 6 | -use crate::domain::page::PagedList; | |
| 6 | +use crate::db::page::PagedList; | |
| 7 | 7 | use crate::domain::user::UserId; |
| 8 | 8 | use crate::error::{AppError, ValidationError}; |
| 9 | 9 |
src/domain/board.rsmodified+2 -2
| @@ -20,9 +20,9 @@ use crate::constant::{ | ||
| 20 | 20 | USER_BOARD_COUNT_FIELD, |
| 21 | 21 | }; |
| 22 | 22 | use crate::database::{Database, transaction_with_retry}; |
| 23 | -use crate::domain::cap; | |
| 23 | +use crate::db::cap; | |
| 24 | 24 | use crate::domain::monotonic_id::next_ulid; |
| 25 | -use crate::domain::page::PagedList; | |
| 25 | +use crate::db::page::PagedList; | |
| 26 | 26 | use crate::domain::timestamp::Timestamp; |
| 27 | 27 | use crate::domain::user::UserId; |
| 28 | 28 | use crate::error::{AppError, ValidationError}; |
src/domain/board_stroke.rsmodified+2 -2
| @@ -26,9 +26,9 @@ use crate::constant::{ | ||
| 26 | 26 | }; |
| 27 | 27 | use crate::database::{Database, transaction_with_retry}; |
| 28 | 28 | use crate::domain::board::{Board, BoardId}; |
| 29 | -use crate::domain::cap; | |
| 29 | +use crate::db::cap; | |
| 30 | 30 | use crate::domain::monotonic_id::next_ulid; |
| 31 | -use crate::domain::page::PagedList; | |
| 31 | +use crate::db::page::PagedList; | |
| 32 | 32 | use crate::domain::timestamp::Timestamp; |
| 33 | 33 | use crate::domain::user::UserId; |
| 34 | 34 | use crate::error::AppError; |
src/domain/chatbot_message.rsmodified+1 -1
| @@ -19,7 +19,7 @@ use crate::constant::{ | ||
| 19 | 19 | }; |
| 20 | 20 | use crate::database::Database; |
| 21 | 21 | use crate::domain::chatbot_thread::{ChatbotThreadId, touch_and_write}; |
| 22 | -use crate::domain::page::PagedList; | |
| 22 | +use crate::db::page::PagedList; | |
| 23 | 23 | use crate::domain::timestamp::Timestamp; |
| 24 | 24 | use crate::domain::user::UserId; |
| 25 | 25 | use crate::error::{AppError, ValidationError}; |
src/domain/chatbot_thread.rsmodified+2 -2
| @@ -10,9 +10,9 @@ use crate::constant::{ | ||
| 10 | 10 | MAX_CHATBOT_THREAD_TITLE_LEN, SETTINGS_KEY, SETTINGS_TABLE, |
| 11 | 11 | }; |
| 12 | 12 | use crate::database::{Database, transaction_with_retry}; |
| 13 | -use crate::domain::cap; | |
| 13 | +use crate::db::cap; | |
| 14 | 14 | use crate::domain::monotonic_id::next_ulid; |
| 15 | -use crate::domain::page::PagedList; | |
| 15 | +use crate::db::page::PagedList; | |
| 16 | 16 | use crate::domain::timestamp::Timestamp; |
| 17 | 17 | use crate::domain::user::UserId; |
| 18 | 18 | use crate::error::{AppError, ValidationError}; |
src/domain/class_blueprint.rsmodified+1 -1
| @@ -42,7 +42,7 @@ use crate::domain::class_course::ClassCourse; | ||
| 42 | 42 | use crate::domain::class_group::{ClassGrade, ClassGroup, ClassGroupId}; |
| 43 | 43 | use crate::domain::class_pump::{Attached, Axis, detach}; |
| 44 | 44 | use crate::domain::course::CourseId; |
| 45 | -use crate::domain::page::PagedList; | |
| 45 | +use crate::db::page::PagedList; | |
| 46 | 46 | use crate::domain::user::UserId; |
| 47 | 47 | use crate::error::{AppError, ValidationError}; |
| 48 | 48 |
src/domain/class_course.rsmodified+1 -1
| @@ -12,7 +12,7 @@ use crate::domain::class_blueprint::ClassBlueprintId; | ||
| 12 | 12 | use crate::domain::class_group::ClassGroupId; |
| 13 | 13 | use crate::domain::class_pump::{Attached, Axis, attach, detach, link_id}; |
| 14 | 14 | use crate::domain::course::CourseId; |
| 15 | -use crate::domain::page::PagedList; | |
| 15 | +use crate::db::page::PagedList; | |
| 16 | 16 | use crate::domain::timestamp::Timestamp; |
| 17 | 17 | use crate::domain::user::UserId; |
| 18 | 18 | use crate::error::AppError; |
src/domain/class_group.rsmodified+5 -5
| @@ -17,10 +17,10 @@ use crate::constant::{ | ||
| 17 | 17 | MAX_CLASS_NAME_LEN, TERM_CLASS_COUNT_FIELD, |
| 18 | 18 | }; |
| 19 | 19 | use crate::database::{Database, transaction_with_retry}; |
| 20 | -use crate::domain::cap; | |
| 21 | -use crate::domain::field_update::FieldUpdate; | |
| 20 | +use crate::db::cap; | |
| 21 | +use crate::db::field_update::FieldUpdate; | |
| 22 | 22 | use crate::domain::monotonic_id::next_ulid; |
| 23 | -use crate::domain::page::PagedList; | |
| 23 | +use crate::db::page::PagedList; | |
| 24 | 24 | use crate::domain::term::{self, TermId}; |
| 25 | 25 | use crate::domain::user::UserId; |
| 26 | 26 | use crate::error::{AppError, ValidationError}; |
| @@ -87,7 +87,7 @@ impl ClassGrade { | ||
| 87 | 87 | |
| 88 | 88 | /// One class. `creator` is who made it; the two refcounts behind the delete |
| 89 | 89 | /// guard are database-side columns only, so no whole-row save can clobber one |
| 90 | -/// (see [`crate::domain::cap`]). | |
| 90 | +/// (see [`crate::db::cap`]). | |
| 91 | 91 | /// |
| 92 | 92 | /// `teacher` is the section's homeroom teacher (sınıf öğretmeni): optional, not |
| 93 | 93 | /// refcounted, and merely a label pointing at a teacher-or-higher account — the |
| @@ -415,7 +415,7 @@ mod tests { | ||
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /// The stored counter, re-read — never off a return value, which the |
| 418 | - /// in-memory engine forges wins on (see [`crate::domain::cap`]). | |
| 418 | + /// in-memory engine forges wins on (see [`crate::db::cap`]). | |
| 419 | 419 | async fn stored_count(sql: &str, db: &Database) -> i64 { |
| 420 | 420 | let mut result = db.query(sql).await.unwrap().check().unwrap(); |
| 421 | 421 | result |
src/domain/class_member.rsmodified+2 -2
| @@ -11,7 +11,7 @@ use crate::constant::{CLASS_MEMBER_TABLE, MAX_CLASS_COURSES, MAX_CLASS_MEMBERS}; | ||
| 11 | 11 | use crate::database::Database; |
| 12 | 12 | use crate::domain::class_group::ClassGroupId; |
| 13 | 13 | use crate::domain::class_pump::{Attached, Axis, attach, detach, link_id}; |
| 14 | -use crate::domain::page::PagedList; | |
| 14 | +use crate::db::page::PagedList; | |
| 15 | 15 | use crate::domain::timestamp::Timestamp; |
| 16 | 16 | use crate::domain::user::UserId; |
| 17 | 17 | use crate::error::{AppError, ValidationError}; |
| @@ -252,7 +252,7 @@ pub(crate) mod tests { | ||
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /// A counter, re-read out of the store — never off a return value, which |
| 255 | - /// the in-memory engine forges wins on (see [`crate::domain::cap`]). | |
| 255 | + /// the in-memory engine forges wins on (see [`crate::db::cap`]). | |
| 256 | 256 | pub(crate) async fn counter(field: &str, of: RecordId, db: &Database) -> i64 { |
| 257 | 257 | let mut result = db |
| 258 | 258 | .query(format!("SELECT VALUE {field} ?? 0 FROM $of")) |
src/domain/class_pump.rsmodified+2 -2
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | //! a direction flag would be one function containing two, so the seam stays |
| 19 | 19 | //! where the SQL puts it. |
| 20 | 20 | //! |
| 21 | -//! Everything here writes counters the way [`crate::domain::cap`] does — a | |
| 21 | +//! Everything here writes counters the way [`crate::db::cap`] does — a | |
| 22 | 22 | //! single-record conditional `UPDATE`, never a count-then-write — and every |
| 23 | 23 | //! `??` is parenthesized, because `n ?? 0 < $cap` parses as `n ?? (0 < $cap)` |
| 24 | 24 | //! and is truthy for every row. |
| @@ -30,7 +30,7 @@ use crate::constant::{ | ||
| 30 | 30 | ENROLLMENT_COUNT_FIELD, ENROLLMENT_TABLE, MAX_CLASS_COURSES, MAX_CLASS_MEMBERS, |
| 31 | 31 | }; |
| 32 | 32 | use crate::database::{Database, transaction_with_retry}; |
| 33 | -use crate::domain::cap; | |
| 33 | +use crate::db::cap; | |
| 34 | 34 | use crate::domain::class_group::{ClassGroup, ClassGroupId}; |
| 35 | 35 | use crate::error::AppError; |
| 36 | 36 |
src/domain/course.rsmodified+3 -3
| @@ -5,10 +5,10 @@ use crate::constant::{ | ||
| 5 | 5 | MAX_COURSE_DESCRIPTION_LEN, MAX_COURSE_TITLE_LEN, REF_COUNT_FIELD, |
| 6 | 6 | }; |
| 7 | 7 | use crate::database::{Database, transaction_with_retry}; |
| 8 | -use crate::domain::cap; | |
| 9 | -use crate::domain::field_update::FieldUpdate; | |
| 8 | +use crate::db::cap; | |
| 9 | +use crate::db::field_update::FieldUpdate; | |
| 10 | 10 | use crate::domain::monotonic_id::next_ulid; |
| 11 | -use crate::domain::page::PagedList; | |
| 11 | +use crate::db::page::PagedList; | |
| 12 | 12 | use crate::domain::term::{self, TermId}; |
| 13 | 13 | use crate::domain::user::UserId; |
| 14 | 14 | use crate::error::{AppError, ValidationError}; |
src/domain/course_note.rsmodified+3 -3
| @@ -4,12 +4,12 @@ use crate::constant::{ | ||
| 4 | 4 | COURSE_NOTE_TABLE, ENROLLMENT_COUNT_FIELD, MAX_NOTE_CONTENT_LEN, MAX_NOTE_TITLE_LEN, |
| 5 | 5 | }; |
| 6 | 6 | use crate::database::Database; |
| 7 | -use crate::domain::cap; | |
| 7 | +use crate::db::cap; | |
| 8 | 8 | use crate::domain::course::CourseId; |
| 9 | 9 | use crate::domain::course_note_file::CourseNoteFile; |
| 10 | -use crate::domain::field_update::FieldUpdate; | |
| 10 | +use crate::db::field_update::FieldUpdate; | |
| 11 | 11 | use crate::domain::monotonic_id::next_ulid; |
| 12 | -use crate::domain::page::PagedList; | |
| 12 | +use crate::db::page::PagedList; | |
| 13 | 13 | use crate::domain::user::UserId; |
| 14 | 14 | use crate::error::{AppError, ValidationError}; |
| 15 | 15 | use crate::validate::{validate_optional, validate_required}; |
src/domain/course_note_file.rsmodified+2 -2
| @@ -15,10 +15,10 @@ use crate::constant::{ | ||
| 15 | 15 | COURSE_NOTE_FILE_COUNT_FIELD, COURSE_NOTE_FILE_TABLE, MAX_COURSE_NOTE_FILES, |
| 16 | 16 | }; |
| 17 | 17 | use crate::database::Database; |
| 18 | -use crate::domain::cap; | |
| 18 | +use crate::db::cap; | |
| 19 | 19 | use crate::domain::course_note::CourseNoteId; |
| 20 | 20 | use crate::domain::monotonic_id::next_ulid; |
| 21 | -use crate::domain::page::PagedList; | |
| 21 | +use crate::db::page::PagedList; | |
| 22 | 22 | use crate::error::AppError; |
| 23 | 23 | |
| 24 | 24 | #[derive(Debug, Clone, PartialEq, Eq, SurrealValue)] |
src/domain/course_session.rsmodified+3 -3
| @@ -2,11 +2,11 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::constant::{COURSE_SESSION_TABLE, ENROLLMENT_COUNT_FIELD, MAX_SESSION_TOPIC_LEN}; |
| 4 | 4 | use crate::database::{Database, transaction_with_retry}; |
| 5 | -use crate::domain::cap; | |
| 5 | +use crate::db::cap; | |
| 6 | 6 | use crate::domain::course::CourseId; |
| 7 | -use crate::domain::field_update::FieldUpdate; | |
| 7 | +use crate::db::field_update::FieldUpdate; | |
| 8 | 8 | use crate::domain::monotonic_id::next_ulid; |
| 9 | -use crate::domain::page::PagedList; | |
| 9 | +use crate::db::page::PagedList; | |
| 10 | 10 | use crate::domain::timestamp::{Timestamp, range_error}; |
| 11 | 11 | use crate::domain::user::UserId; |
| 12 | 12 | use crate::error::{AppError, ValidationError}; |
src/domain/dietary_profile.rsmodified+1 -1
| @@ -14,7 +14,7 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 14 | 14 | |
| 15 | 15 | use crate::constant::{DIETARY_PROFILE_TABLE, MAX_DIETARY_NOTE_LEN, MAX_DIETARY_TAGS}; |
| 16 | 16 | use crate::database::Database; |
| 17 | -use crate::domain::field_update::FieldUpdate; | |
| 17 | +use crate::db::field_update::FieldUpdate; | |
| 18 | 18 | use crate::domain::timestamp::Timestamp; |
| 19 | 19 | use crate::domain::user::UserId; |
| 20 | 20 | use crate::error::{AppError, ValidationError}; |
src/domain/enrollment.rsmodified+2 -2
| @@ -2,10 +2,10 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::constant::{ENROLLMENT_COUNT_FIELD, ENROLLMENT_TABLE}; |
| 4 | 4 | use crate::database::{Database, transaction_with_retry}; |
| 5 | -use crate::domain::cap; | |
| 5 | +use crate::db::cap; | |
| 6 | 6 | use crate::domain::class_group::ClassGroupId; |
| 7 | 7 | use crate::domain::course::{Course, CourseId}; |
| 8 | -use crate::domain::page::PagedList; | |
| 8 | +use crate::db::page::PagedList; | |
| 9 | 9 | use crate::domain::role::Role; |
| 10 | 10 | use crate::domain::user::UserId; |
| 11 | 11 | use crate::error::{AppError, ValidationError}; |
src/domain/event.rsmodified+1 -1
| @@ -8,7 +8,7 @@ use crate::domain::class_group::ClassGroupId; | ||
| 8 | 8 | use crate::domain::class_member::{ClassMember, ClassMemberId}; |
| 9 | 9 | use crate::domain::course::CourseId; |
| 10 | 10 | use crate::domain::enrollment::Enrollment; |
| 11 | -use crate::domain::field_update::FieldUpdate; | |
| 11 | +use crate::db::field_update::FieldUpdate; | |
| 12 | 12 | use crate::domain::monotonic_id::next_ulid; |
| 13 | 13 | use crate::domain::registration::Registration; |
| 14 | 14 | use crate::domain::role::Role; |
src/domain/exam.rsmodified+1 -1
| @@ -5,7 +5,7 @@ use crate::constant::{ | ||
| 5 | 5 | UNLIMITED_EXAM_ATTEMPTS, |
| 6 | 6 | }; |
| 7 | 7 | use crate::database::{Database, transaction_with_retry}; |
| 8 | -use crate::domain::cap; | |
| 8 | +use crate::db::cap; | |
| 9 | 9 | use crate::domain::course::CourseId; |
| 10 | 10 | use crate::domain::monotonic_id::next_ulid; |
| 11 | 11 | use crate::domain::settings::ExamKindDef; |
src/domain/exam_attempt.rsmodified+3 -2
| @@ -6,7 +6,8 @@ use crate::domain::exam::Exam; | ||
| 6 | 6 | use crate::domain::exam::ExamId; |
| 7 | 7 | use crate::domain::timestamp::Timestamp; |
| 8 | 8 | use crate::domain::user::UserId; |
| 9 | -use crate::domain::{badge, cap, key}; | |
| 9 | +use crate::db::cap; | |
| 10 | +use crate::domain::{badge, key}; | |
| 10 | 11 | use crate::error::AppError; |
| 11 | 12 | |
| 12 | 13 | /// The `THROW` marker the freeze gate aborts with, and the one 409 both it and |
| @@ -426,7 +427,7 @@ impl ExamAttempt { | ||
| 426 | 427 | // |
| 427 | 428 | // corner-cut: the count and a concurrent `CREATE exam_attempt` are still not |
| 428 | 429 | // serialized against each other — SurrealDB does not conflict-check a |
| 429 | - // cross-record count (the write skew `domain::cap` exists for), so an | |
| 430 | + // cross-record count (the write skew `db::cap` exists for), so an | |
| 430 | 431 | // attempt landing in the same instant as an edit can still interleave |
| 431 | 432 | // either way. The mutex this replaces closed that inside one process only, |
| 432 | 433 | // and there are two, so nothing is lost. Closing it properly means the |
src/domain/exam_question.rsmodified+3 -3
| @@ -9,11 +9,11 @@ use crate::constant::{ | ||
| 9 | 9 | }; |
| 10 | 10 | use crate::database::Database; |
| 11 | 11 | use crate::domain::bank_question::BankQuestionId; |
| 12 | -use crate::domain::cap; | |
| 12 | +use crate::db::cap; | |
| 13 | 13 | use crate::domain::exam::ExamId; |
| 14 | 14 | use crate::domain::exam_attempt::ExamAttempt; |
| 15 | 15 | use crate::domain::monotonic_id::next_ulid; |
| 16 | -use crate::domain::page::PagedList; | |
| 16 | +use crate::db::page::PagedList; | |
| 17 | 17 | use crate::domain::subject::SubjectId; |
| 18 | 18 | use crate::error::{AppError, ValidationError}; |
| 19 | 19 | use crate::validate::{validate_question_kind, validate_question_points, validate_required}; |
| @@ -569,7 +569,7 @@ impl ExamQuestion { | ||
| 569 | 569 | // undeletable forever). |
| 570 | 570 | // |
| 571 | 571 | // The two are armed on *different* conditions, which is the whole of |
| 572 | - // the rule ([`crate::domain::field_update::FieldUpdate::refcount`] states | |
| 572 | + // the rule ([`crate::db::field_update::FieldUpdate::refcount`] states | |
| 573 | 573 | // it the same way): the counter statements only when the link actually |
| 574 | 574 | // changes, but the CAS whenever this write *carries* the link — and it |
| 575 | 575 | // always does, because the handler fills an omitted `subject_id` from |
src/domain/exam_result.rsmodified+2 -2
| @@ -7,7 +7,7 @@ use crate::constant::{ | ||
| 7 | 7 | KIND_REF_TABLE, MARKS_GIVEN_TOTAL_FIELD, REF_COUNT_FIELD, REF_RETIRED_FIELD, |
| 8 | 8 | }; |
| 9 | 9 | use crate::database::{Database, transaction_with_retry}; |
| 10 | -use crate::domain::cap; | |
| 10 | +use crate::db::cap; | |
| 11 | 11 | use crate::domain::course::CourseId; |
| 12 | 12 | use crate::domain::exam::ExamId; |
| 13 | 13 | use crate::domain::key; |
| @@ -23,7 +23,7 @@ pub(crate) fn draft_error() -> AppError { | ||
| 23 | 23 | |
| 24 | 24 | /// The reference counter for one exam kind — how many marks are written under |
| 25 | 25 | /// that name, and whether the school has retired it (see |
| 26 | -/// [`crate::domain::cap`]). Keyed by the name itself: the kind is snapshotted | |
| 26 | +/// [`crate::db::cap`]). Keyed by the name itself: the kind is snapshotted | |
| 27 | 27 | /// text on the exam, and this row is what makes "a kind nothing is graded under |
| 28 | 28 | /// may be removed" a decision the database takes, not a count a concurrent mark |
| 29 | 29 | /// can invalidate. |
src/domain/fee_plan.rsmodified+2 -2
| @@ -20,9 +20,9 @@ use crate::constant::{ | ||
| 20 | 20 | FEE_PLAN_TABLE, FEE_PLAN_UNASSIGNED_GUARD, MAX_FEE_PLAN_INSTALLMENTS, MAX_FEE_PLAN_NAME_LEN, |
| 21 | 21 | }; |
| 22 | 22 | use crate::database::{Database, write_with_retry}; |
| 23 | -use crate::domain::field_update::FieldUpdate; | |
| 23 | +use crate::db::field_update::FieldUpdate; | |
| 24 | 24 | use crate::domain::monotonic_id::next_ulid; |
| 25 | -use crate::domain::page::PagedList; | |
| 25 | +use crate::db::page::PagedList; | |
| 26 | 26 | use crate::domain::payment_ledger::LedgerAmount; |
| 27 | 27 | use crate::domain::timestamp::Timestamp; |
| 28 | 28 | use crate::domain::user::UserId; |
src/domain/fee_plan_assignment.rsmodified+2 -2
| @@ -19,9 +19,9 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 19 | 19 | |
| 20 | 20 | use crate::constant::{FEE_PLAN_ASSIGNMENT_COUNT_FIELD, FEE_PLAN_ASSIGNMENT_TABLE}; |
| 21 | 21 | use crate::database::Database; |
| 22 | -use crate::domain::cap::{self, Claimed}; | |
| 22 | +use crate::db::cap::{self, Claimed}; | |
| 23 | 23 | use crate::domain::fee_plan::{FeePlan, FeePlanId}; |
| 24 | -use crate::domain::page::PagedList; | |
| 24 | +use crate::db::page::PagedList; | |
| 25 | 25 | use crate::domain::payment_ledger::PaymentLedger; |
| 26 | 26 | use crate::domain::timestamp::Timestamp; |
| 27 | 27 | use crate::domain::user::UserId; |
src/domain/homework.rsmodified+2 -2
| @@ -17,9 +17,9 @@ use crate::constant::{ | ||
| 17 | 17 | SUBJECT_HOMEWORK_COUNT_FIELD, |
| 18 | 18 | }; |
| 19 | 19 | use crate::database::Database; |
| 20 | -use crate::domain::cap; | |
| 20 | +use crate::db::cap; | |
| 21 | 21 | use crate::domain::course::CourseId; |
| 22 | -use crate::domain::field_update::FieldUpdate; | |
| 22 | +use crate::db::field_update::FieldUpdate; | |
| 23 | 23 | use crate::domain::monotonic_id::next_ulid; |
| 24 | 24 | use crate::domain::subject::SubjectId; |
| 25 | 25 | use crate::domain::timestamp::Timestamp; |
src/domain/homework_file.rsmodified+1 -1
| @@ -16,7 +16,7 @@ use crate::constant::{ | ||
| 16 | 16 | SUBMISSION_OPEN_GUARD, |
| 17 | 17 | }; |
| 18 | 18 | use crate::database::{Database, transaction_with_retry}; |
| 19 | -use crate::domain::cap; | |
| 19 | +use crate::db::cap; | |
| 20 | 20 | use crate::domain::course::CourseId; |
| 21 | 21 | use crate::domain::homework::HomeworkId; |
| 22 | 22 | use crate::domain::homework_submission::{HomeworkSubmission, HomeworkSubmissionId}; |
src/domain/homework_result.rsmodified+1 -1
| @@ -188,7 +188,7 @@ impl HomeworkResult { | ||
| 188 | 188 | // no counter column and is SCHEMAFULL, so `due_at` is the one `int` it |
| 189 | 189 | // already has; do not invent a second spelling. |
| 190 | 190 | // |
| 191 | - // Not [`crate::domain::cap::touch_and_create`], which is the same shape | |
| 191 | + // Not [`crate::db::cap::touch_and_create`], which is the same shape | |
| 192 | 192 | // for a bare `CREATE`: a grade is an UPSERT (a regrade must overwrite), |
| 193 | 193 | // and the freeze stamp and the grader's counter have to ride the same |
| 194 | 194 | // transaction, which that helper has no room for. |
src/domain/meal_attendance.rsmodified+1 -1
| @@ -20,7 +20,7 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 20 | 20 | use crate::constant::{MEAL_ATTENDANCE_STATUSES, MEAL_ATTENDANCE_TABLE}; |
| 21 | 21 | use crate::database::Database; |
| 22 | 22 | use crate::domain::menu::{MenuDate, MenuId, bump_menu_and_write}; |
| 23 | -use crate::domain::page::PagedList; | |
| 23 | +use crate::db::page::PagedList; | |
| 24 | 24 | use crate::domain::timestamp::Timestamp; |
| 25 | 25 | use crate::domain::user::UserId; |
| 26 | 26 | use crate::error::{AppError, ValidationError}; |
src/domain/meal_booking.rsmodified+2 -2
| @@ -35,10 +35,10 @@ use crate::constant::{ | ||
| 35 | 35 | MENU_VERSION_FIELD, |
| 36 | 36 | }; |
| 37 | 37 | use crate::database::{Database, backoff, lost_the_race}; |
| 38 | -use crate::domain::cap::{self, Claimed}; | |
| 38 | +use crate::db::cap::{self, Claimed}; | |
| 39 | 39 | use crate::domain::meal_ledger::{LedgerAmount, MealLedger}; |
| 40 | 40 | use crate::domain::menu::{Menu, MenuDate, MenuId, MenuSlot}; |
| 41 | -use crate::domain::page::PagedList; | |
| 41 | +use crate::db::page::PagedList; | |
| 42 | 42 | use crate::domain::settings::{MealSlotDef, Settings}; |
| 43 | 43 | use crate::domain::timestamp::Timestamp; |
| 44 | 44 | use crate::domain::user::UserId; |
src/domain/meal_ledger.rsmodified+1 -1
| @@ -63,7 +63,7 @@ use crate::database::{Database, lost_the_race}; | ||
| 63 | 63 | use crate::domain::meal_booking::{MealBooking, MealBookingId}; |
| 64 | 64 | use crate::domain::menu::MenuId; |
| 65 | 65 | use crate::domain::menu_dish::MenuDish; |
| 66 | -use crate::domain::page::PagedList; | |
| 66 | +use crate::db::page::PagedList; | |
| 67 | 67 | // The client-chosen idempotence key both ledgers take — one grammar, one |
| 68 | 68 | // validator, one type, rather than a second newtype that could drift from it. |
| 69 | 69 | use crate::domain::payment_ledger::PaymentRequestKey; |
src/domain/menu.rsmodified+4 -4
| @@ -18,8 +18,8 @@ use crate::constant::{ | ||
| 18 | 18 | MENU_VERSION_FIELD, REF_COUNT_FIELD, SLOT_REF_TABLE, |
| 19 | 19 | }; |
| 20 | 20 | use crate::database::{Database, transaction_with_retry, write_with_retry}; |
| 21 | -use crate::domain::cap; | |
| 22 | -use crate::domain::page::PagedList; | |
| 21 | +use crate::db::cap; | |
| 22 | +use crate::db::page::PagedList; | |
| 23 | 23 | use crate::domain::settings::MealSlotDef; |
| 24 | 24 | use crate::domain::timestamp::Timestamp; |
| 25 | 25 | use crate::domain::user::UserId; |
| @@ -30,7 +30,7 @@ use crate::error::{AppError, ValidationError}; | ||
| 30 | 30 | /// conflict-check). Publishing no longer needs it — the day+slot *is* the |
| 31 | 31 | /// record id — and neither does a booking, a menu delete, or the settings |
| 32 | 32 | /// slot-removal guard: those went to conditional single-record writes |
| 33 | -/// ([`crate::domain::cap`]), which the store decides as this lock cannot. | |
| 33 | +/// ([`crate::db::cap`]), which the store decides as this lock cannot. | |
| 34 | 34 | // |
| 35 | 35 | // corner-cut: the dish cap therefore rests on this lock alone — a dish write |
| 36 | 36 | // added without taking it reopens the count-then-write hole silently. Closing |
| @@ -49,7 +49,7 @@ pub(crate) static MENU_LOCK: Mutex<()> = Mutex::const_new(()); | ||
| 49 | 49 | |
| 50 | 50 | /// The reference counter for one meal slot — how many menus are published under |
| 51 | 51 | /// that name, and whether the school has retired it (see |
| 52 | -/// [`crate::domain::cap`]). The mirror of | |
| 52 | +/// [`crate::db::cap`]). The mirror of | |
| 53 | 53 | /// [`kind_ref`](crate::domain::exam_result::kind_ref) for exam kinds: the slot |
| 54 | 54 | /// is snapshotted text on the menu, so this row is the only place the two |
| 55 | 55 | /// tables' relationship is a single record concurrent writes can contend on. |
src/domain/menu_dish.rsmodified+1 -1
| @@ -289,7 +289,7 @@ impl MenuDish { | ||
| 289 | 289 | /// it takes the three-way shape: absent = keep, `Some(None)` = clear. |
| 290 | 290 | /// |
| 291 | 291 | /// The `SET` is built here rather than by |
| 292 | - /// [`FieldUpdate`](crate::domain::field_update::FieldUpdate) because the | |
| 292 | + /// [`FieldUpdate`](crate::db::field_update::FieldUpdate) because the | |
| 293 | 293 | /// revision bump lands on *another* row and has to share this write's |
| 294 | 294 | /// transaction; the field-by-field scoping — an omitted field is never |
| 295 | 295 | /// written, so a concurrent PATCH of another one is not reverted — is the |
src/domain/message.rsmodified+1 -1
| @@ -14,7 +14,7 @@ use crate::constant::{ | ||
| 14 | 14 | }; |
| 15 | 15 | use crate::database::Database; |
| 16 | 16 | use crate::domain::monotonic_id::next_ulid; |
| 17 | -use crate::domain::page::PagedList; | |
| 17 | +use crate::db::page::PagedList; | |
| 18 | 18 | use crate::domain::timestamp::Timestamp; |
| 19 | 19 | use crate::domain::user::UserId; |
| 20 | 20 | use crate::error::{AppError, ValidationError}; |
src/domain/mod.rsmodified+0 -3
| @@ -12,7 +12,6 @@ pub mod bank_question_image; | ||
| 12 | 12 | pub mod board; |
| 13 | 13 | pub mod board_stroke; |
| 14 | 14 | pub mod builder; |
| 15 | -pub mod cap; | |
| 16 | 15 | pub mod chatbot_message; |
| 17 | 16 | pub mod chatbot_thread; |
| 18 | 17 | pub mod class_blueprint; |
| @@ -34,7 +33,6 @@ pub mod exam_question; | ||
| 34 | 33 | pub mod exam_result; |
| 35 | 34 | pub mod fee_plan; |
| 36 | 35 | pub mod fee_plan_assignment; |
| 37 | -pub mod field_update; | |
| 38 | 36 | pub mod homework; |
| 39 | 37 | pub mod homework_file; |
| 40 | 38 | pub mod homework_result; |
| @@ -49,7 +47,6 @@ pub mod message; | ||
| 49 | 47 | pub mod monotonic_id; |
| 50 | 48 | pub mod note; |
| 51 | 49 | pub mod note_file; |
| 52 | -pub mod page; | |
| 53 | 50 | pub mod parent_link; |
| 54 | 51 | pub mod payment_ledger; |
| 55 | 52 | pub mod pomodoro; |
src/domain/note.rsmodified+2 -2
| @@ -2,10 +2,10 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::constant::{MAX_NOTE_CONTENT_LEN, MAX_NOTE_TITLE_LEN, NOTE_TABLE}; |
| 4 | 4 | use crate::database::Database; |
| 5 | -use crate::domain::field_update::FieldUpdate; | |
| 5 | +use crate::db::field_update::FieldUpdate; | |
| 6 | 6 | use crate::domain::monotonic_id::next_ulid; |
| 7 | 7 | use crate::domain::note_file::NoteFile; |
| 8 | -use crate::domain::page::PagedList; | |
| 8 | +use crate::db::page::PagedList; | |
| 9 | 9 | use crate::domain::user::UserId; |
| 10 | 10 | use crate::error::{AppError, ValidationError}; |
| 11 | 11 | use crate::validate::{validate_optional, validate_required}; |
src/domain/note_file.rsmodified+2 -2
| @@ -12,10 +12,10 @@ use crate::constant::{ | ||
| 12 | 12 | NOTE_FILE_TABLE, |
| 13 | 13 | }; |
| 14 | 14 | use crate::database::Database; |
| 15 | -use crate::domain::cap; | |
| 15 | +use crate::db::cap; | |
| 16 | 16 | use crate::domain::monotonic_id::next_ulid; |
| 17 | 17 | use crate::domain::note::NoteId; |
| 18 | -use crate::domain::page::PagedList; | |
| 18 | +use crate::db::page::PagedList; | |
| 19 | 19 | use crate::error::{AppError, ValidationError}; |
| 20 | 20 | |
| 21 | 21 | #[derive(Debug, Clone, PartialEq, Eq, SurrealValue)] |
src/domain/payment_ledger.rsmodified+1 -1
| @@ -98,7 +98,7 @@ use crate::domain::fee_plan_assignment::{FeePlanAssignment, FeePlanAssignmentId} | ||
| 98 | 98 | // error message for both ledgers. |
| 99 | 99 | pub use crate::domain::meal_ledger::{LedgerAmount, LedgerMethod, LedgerNote}; |
| 100 | 100 | use crate::domain::monotonic_id::next_ulid; |
| 101 | -use crate::domain::page::PagedList; | |
| 101 | +use crate::db::page::PagedList; | |
| 102 | 102 | use crate::domain::timestamp::Timestamp; |
| 103 | 103 | use crate::domain::user::UserId; |
| 104 | 104 | use crate::error::{AppError, ValidationError}; |
src/domain/pomodoro.rsmodified+1 -1
| @@ -497,7 +497,7 @@ mod tests { | ||
| 497 | 497 | /// contention on one user row. |
| 498 | 498 | /// |
| 499 | 499 | /// Multi-threaded and off the embedded engine for the reason |
| 500 | - /// [`crate::domain::cap`] spells out: the in-memory engine does not | |
| 500 | + /// [`crate::db::cap`] spells out: the in-memory engine does not | |
| 501 | 501 | /// conflict-check two concurrent writes to one record, so it would answer |
| 502 | 502 | /// `Ok` to a write it dropped and *forge* the integrity failure this test |
| 503 | 503 | /// exists to catch. |
src/domain/rag_output.rsmodified+1 -1
| @@ -20,7 +20,7 @@ use crate::domain::course::CourseId; | ||
| 20 | 20 | use crate::domain::course_note::CourseNoteId; |
| 21 | 21 | use crate::domain::course_note_file::CourseNoteFileId; |
| 22 | 22 | use crate::domain::monotonic_id::next_ulid; |
| 23 | -use crate::domain::page::PagedList; | |
| 23 | +use crate::db::page::PagedList; | |
| 24 | 24 | use crate::domain::timestamp::Timestamp; |
| 25 | 25 | use crate::error::AppError; |
| 26 | 26 |
src/domain/registration.rsmodified+1 -1
| @@ -2,7 +2,7 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::constant::{REGISTRATION_COUNT_FIELD, REGISTRATION_TABLE}; |
| 4 | 4 | use crate::database::Database; |
| 5 | -use crate::domain::cap; | |
| 5 | +use crate::db::cap; | |
| 6 | 6 | use crate::domain::event::{Event, EventId}; |
| 7 | 7 | use crate::domain::role::Role; |
| 8 | 8 | use crate::domain::user::{User, UserId}; |
src/domain/session_attendance.rsmodified+1 -1
| @@ -8,7 +8,7 @@ use crate::database::{Database, transaction_with_retry}; | ||
| 8 | 8 | use crate::domain::attendance::AttendanceStatus; |
| 9 | 9 | use crate::domain::course::CourseId; |
| 10 | 10 | use crate::domain::course_session::{CourseSession, CourseSessionId}; |
| 11 | -use crate::domain::page::PagedList; | |
| 11 | +use crate::db::page::PagedList; | |
| 12 | 12 | use crate::domain::timestamp::Timestamp; |
| 13 | 13 | use crate::domain::user::UserId; |
| 14 | 14 | use crate::error::AppError; |
src/domain/settings.rsmodified+1 -1
| @@ -46,7 +46,7 @@ use crate::error::{AppError, ValidationError}; | ||
| 46 | 46 | /// So the pair is serialized instead. Every writer of the singleton goes |
| 47 | 47 | /// through `PATCH /settings`, and the deployment runs one process by contract |
| 48 | 48 | /// (stop-the-world upgrades), so process-wide is deployment-wide here — the |
| 49 | -/// same argument [`crate::domain::cap`]'s own lock makes for `retire_name`'s | |
| 49 | +/// same argument [`crate::db::cap`]'s own lock makes for `retire_name`'s | |
| 50 | 50 | /// two statements, one level up. The compare-and-set stays: it is what keeps a |
| 51 | 51 | /// crashed or rolled-back attempt from writing a list nobody merged. |
| 52 | 52 | /// |
src/domain/solution.rsmodified+1 -1
| @@ -15,7 +15,7 @@ use crate::constant::{MAX_SOLUTION_BODY_LEN, SOLUTION_TABLE}; | ||
| 15 | 15 | use crate::database::Database; |
| 16 | 16 | use crate::domain::monotonic_id::next_ulid; |
| 17 | 17 | use crate::domain::note_file::FileContentType; |
| 18 | -use crate::domain::page::PagedList; | |
| 18 | +use crate::db::page::PagedList; | |
| 19 | 19 | use crate::domain::pool_question::{PoolQuestionId, bump_question_and_write}; |
| 20 | 20 | use crate::domain::timestamp::Timestamp; |
| 21 | 21 | use crate::domain::user::UserId; |
src/domain/subject.rsmodified+3 -3
| @@ -4,11 +4,11 @@ use crate::constant::{ | ||
| 4 | 4 | ENROLLMENT_COUNT_FIELD, MAX_SUBJECT_DESCRIPTION_LEN, MAX_SUBJECT_NAME_LEN, SUBJECT_TABLE, |
| 5 | 5 | }; |
| 6 | 6 | use crate::database::{Database, transaction_with_retry}; |
| 7 | -use crate::domain::cap; | |
| 7 | +use crate::db::cap; | |
| 8 | 8 | use crate::domain::course::CourseId; |
| 9 | -use crate::domain::field_update::FieldUpdate; | |
| 9 | +use crate::db::field_update::FieldUpdate; | |
| 10 | 10 | use crate::domain::monotonic_id::next_ulid; |
| 11 | -use crate::domain::page::PagedList; | |
| 11 | +use crate::db::page::PagedList; | |
| 12 | 12 | use crate::error::{AppError, ValidationError}; |
| 13 | 13 | use crate::validate::{validate_optional, validate_required}; |
| 14 | 14 |
src/domain/term.rsmodified+2 -2
| @@ -10,9 +10,9 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 10 | 10 | |
| 11 | 11 | use crate::constant::{COURSE_COUNT_FIELD, MAX_TERM_NAME_LEN, TERM_CLASS_COUNT_FIELD, TERM_TABLE}; |
| 12 | 12 | use crate::database::{Database, write_with_retry}; |
| 13 | -use crate::domain::field_update::FieldUpdate; | |
| 13 | +use crate::db::field_update::FieldUpdate; | |
| 14 | 14 | use crate::domain::monotonic_id::next_ulid; |
| 15 | -use crate::domain::page::PagedList; | |
| 15 | +use crate::db::page::PagedList; | |
| 16 | 16 | use crate::domain::timestamp::{Timestamp, range_error}; |
| 17 | 17 | use crate::error::{AppError, ValidationError}; |
| 18 | 18 | use crate::validate::validate_required; |
src/domain/user.rsmodified+4 -4
| @@ -13,10 +13,10 @@ use crate::constant::{ | ||
| 13 | 13 | use crate::database::{Database, transaction_with_retry, write_with_retry}; |
| 14 | 14 | use crate::domain::appointment::AppointmentStatus; |
| 15 | 15 | use crate::domain::board::Board; |
| 16 | -use crate::domain::field_update::FieldUpdate; | |
| 16 | +use crate::db::field_update::FieldUpdate; | |
| 17 | 17 | use crate::domain::monotonic_id::next_ulid; |
| 18 | 18 | use crate::domain::note_file::FileContentType; |
| 19 | -use crate::domain::page::PagedList; | |
| 19 | +use crate::db::page::PagedList; | |
| 20 | 20 | use crate::domain::preferences::{Language, PaletteColor, Theme}; |
| 21 | 21 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; |
| 22 | 22 | use crate::domain::role::Role; |
| @@ -31,7 +31,7 @@ use crate::validate::{validate_password, validate_username}; | ||
| 31 | 31 | /// guard is a count-then-write: read whether another admin exists, then lower |
| 32 | 32 | /// this row. SurrealDB conflict-checks neither side of that pair — a |
| 33 | 33 | /// `BEGIN…COMMIT` does not serialize a cross-record count against a concurrent |
| 34 | -/// update (write-skew, see [`crate::domain::cap`]) and a statement that only | |
| 34 | +/// update (write-skew, see [`crate::db::cap`]) and a statement that only | |
| 35 | 35 | /// *reads* the rival's row never collides with it. So two admins demoting each |
| 36 | 36 | /// other both counted the other and both committed, leaving **zero** admins and |
| 37 | 37 | /// a school nobody can administer: `ensure_admin` refuses to promote an |
| @@ -41,7 +41,7 @@ use crate::validate::{validate_password, validate_username}; | ||
| 41 | 41 | /// Serializing the pair is what closes it, the same argument |
| 42 | 42 | /// [`crate::domain::settings::SETTINGS_LOCK`] makes one level up: the deployment |
| 43 | 43 | /// runs one process by contract (stop-the-world upgrades), so process-wide is |
| 44 | -/// deployment-wide. A per-row counter (the [`crate::domain::cap`] shape) does | |
| 44 | +/// deployment-wide. A per-row counter (the [`crate::db::cap`] shape) does | |
| 45 | 45 | /// not fit — the count being capped is over *every* user row, with no parent |
| 46 | 46 | /// record to hold it and no place to seed one without a backfill. |
| 47 | 47 | /// |
src/domain/work_entry.rsmodified+2 -2
| @@ -2,9 +2,9 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::constant::WORK_ENTRY_TABLE; |
| 4 | 4 | use crate::database::{Database, transaction_with_retry}; |
| 5 | -use crate::domain::field_update::FieldUpdate; | |
| 5 | +use crate::db::field_update::FieldUpdate; | |
| 6 | 6 | use crate::domain::monotonic_id::next_ulid; |
| 7 | -use crate::domain::page::PagedList; | |
| 7 | +use crate::db::page::PagedList; | |
| 8 | 8 | use crate::domain::timestamp::Timestamp; |
| 9 | 9 | use crate::domain::user::UserId; |
| 10 | 10 | use crate::error::{AppError, ValidationError}; |
src/lib.rsmodified+1 -0
| @@ -2,6 +2,7 @@ pub mod ai; | ||
| 2 | 2 | pub mod config; |
| 3 | 3 | pub mod constant; |
| 4 | 4 | pub mod database; |
| 5 | +pub mod db; | |
| 5 | 6 | pub mod domain; |
| 6 | 7 | pub mod error; |
| 7 | 8 | pub mod migration_sql; |
src/migration_sql.rsmodified+3 -3
| @@ -280,7 +280,7 @@ pub const MIGRATION: &str = " | ||
| 280 | 280 | DEFINE FIELD IF NOT EXISTS audience.class ON event TYPE option<record<class_group>>; |
| 281 | 281 | DEFINE FIELD IF NOT EXISTS audience.capacity ON event TYPE option<int>; |
| 282 | 282 | -- Seats taken on the signup list, the stored capacity guard that closes |
| 283 | - -- write-skew between concurrent request tasks (see `crate::domain::cap`). | |
| 283 | + -- write-skew between concurrent request tasks (see `crate::db::cap`). | |
| 284 | 284 | -- Absent reads as zero, so no Rust struct needs it. |
| 285 | 285 | DEFINE FIELD IF NOT EXISTS registration_count ON event TYPE option<int>; |
| 286 | 286 | REMOVE FIELD IF EXISTS audience.users ON TABLE event; |
| @@ -311,7 +311,7 @@ pub const MIGRATION: &str = " | ||
| 311 | 311 | -- is exactly what an absent stamp already means. |
| 312 | 312 | DEFINE FIELD IF NOT EXISTS archived_at ON term TYPE option<int>; |
| 313 | 313 | -- Courses still linking this term, the stored delete guard that closes |
| 314 | - -- write-skew between concurrent request tasks (see `crate::domain::cap`). | |
| 314 | + -- write-skew between concurrent request tasks (see `crate::db::cap`). | |
| 315 | 315 | -- Absent reads as zero, so no Rust struct needs it. |
| 316 | 316 | DEFINE FIELD IF NOT EXISTS course_count ON term TYPE option<int>; |
| 317 | 317 | -- Classes linking this term, the other half of the same guard. A column of |
| @@ -782,7 +782,7 @@ pub const MIGRATION: &str = " | ||
| 782 | 782 | DEFINE FIELD IF NOT EXISTS date ON menu TYPE string READONLY; |
| 783 | 783 | DEFINE FIELD IF NOT EXISTS slot ON menu TYPE string READONLY; |
| 784 | 784 | DEFINE FIELD IF NOT EXISTS capacity ON menu TYPE option<int>; |
| 785 | - -- `seats_booked` is the seat cap's counter (see `domain::cap`) and | |
| 785 | + -- `seats_booked` is the seat cap's counter (see `db::cap`) and | |
| 786 | 786 | -- `version` the menu's revision: a booking claims its seat only while the |
| 787 | 787 | -- menu still stands at the revision it read the price at, so a dish |
| 788 | 788 | -- re-priced mid-booking cannot be billed as the old price. Both absent |
src/tenant.rsmodified+1 -1
| @@ -30,7 +30,7 @@ use surrealdb::types::{RecordId, RecordIdKey, SurrealValue}; | ||
| 30 | 30 | use crate::config::Config; |
| 31 | 31 | use crate::constant::{MAX_SLUG_LEN, MIN_SLUG_LEN}; |
| 32 | 32 | use crate::database::{Database, lost_the_race, migrate, migrate_control}; |
| 33 | -use crate::domain::page::PagedList; | |
| 33 | +use crate::db::page::PagedList; | |
| 34 | 34 | use crate::domain::timestamp::Timestamp; |
| 35 | 35 | use crate::error::{AppError, ValidationError}; |
| 36 | 36 | use crate::module::ModuleSet; |
src/web/exams/mod.rsmodified+1 -1
| @@ -72,7 +72,7 @@ impl Scheduled for Exam { | ||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /// Serializes the exam subsystem's cross-record check-then-writes, which |
| 75 | -/// `BEGIN…COMMIT` cannot (write skew) — the reasoning in [`crate::domain::cap`]. | |
| 75 | +/// `BEGIN…COMMIT` cannot (write skew) — the reasoning in [`crate::db::cap`]. | |
| 76 | 76 | /// It orders requests, but only around what it wraps — every invariant that |
| 77 | 77 | /// could be moved into the database itself has been, so a gap between a read |
| 78 | 78 | /// and its write is decided by the store. What is left here needs a |
src/web/homework.rsmodified+1 -1
| @@ -78,7 +78,7 @@ use super::{ | ||
| 78 | 78 | /// delete used to take is on this list any more. |
| 79 | 79 | /// |
| 80 | 80 | /// Lock order, where both are taken: `HOMEWORK_LOCK` before the counter lock in |
| 81 | -/// [`crate::domain::cap`], never the reverse. | |
| 81 | +/// [`crate::db::cap`], never the reverse. | |
| 82 | 82 | // corner-cut: global RwLock, shard per-homework if write latency ever matters. |
| 83 | 83 | pub(crate) static HOMEWORK_LOCK: tokio::sync::RwLock<()> = tokio::sync::RwLock::const_new(()); |
| 84 | 84 |
src/web/mod.rsmodified+2 -2
| @@ -147,7 +147,7 @@ pub(crate) async fn undo_if_demoted(target: &UserId, db: &Database) -> Result<() | ||
| 147 | 147 | /// If both ends are present, `ends_at` must not precede `starts_at`. Shared by |
| 148 | 148 | /// everything that carries a time range (events, course sessions). The PATCH |
| 149 | 149 | /// paths re-check this at write time via |
| 150 | -/// [`crate::domain::field_update::FieldUpdate::ordered`], which answers with the | |
| 150 | +/// [`crate::db::field_update::FieldUpdate::ordered`], which answers with the | |
| 151 | 151 | /// same error — this is the pre-flight, that is the race closer. |
| 152 | 152 | pub(crate) fn check_time_range( |
| 153 | 153 | starts_at: Option<Timestamp>, |
| @@ -405,7 +405,7 @@ mod tests { | ||
| 405 | 405 | /// refuse; with the account still staff it must undo nothing at all. |
| 406 | 406 | /// |
| 407 | 407 | /// Asserted on stored state, never on a return value: the in-memory engine |
| 408 | - /// forges those (see [`crate::domain::cap`]). | |
| 408 | + /// forges those (see [`crate::db::cap`]). | |
| 409 | 409 | #[tokio::test] |
| 410 | 410 | async fn undo_if_demoted_repairs_both_assignments_or_neither() { |
| 411 | 411 | use crate::domain::class_group::{ClassGroup, ClassName}; |
src/web/settings.rsmodified+1 -1
| @@ -9,7 +9,7 @@ use surrealdb::types::RecordId; | ||
| 9 | 9 | |
| 10 | 10 | use crate::constant::CAS_UPDATE_RETRIES; |
| 11 | 11 | use crate::database::Database; |
| 12 | -use crate::domain::cap; | |
| 12 | +use crate::db::cap; | |
| 13 | 13 | use crate::domain::exam_result::kind_ref; |
| 14 | 14 | use crate::domain::menu::slot_ref; |
| 15 | 15 | use crate::domain::settings::{ExamKindDef, GradeBand, MealSlotDef, SETTINGS_LOCK, Settings}; |