forge
Explore
Log in

Don't you dare go Hollow

Move cap/field_update/page toolkits from domain to new db layer

Browse files at this commit

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