forge
Explore
Log in

Don't you dare go Hollow

🏫 lay the class-layer schema and bounds

Browse files at this commit

0a82a9b6e7cdbf71f6d4750cbb58f352a38c6ee2Ahmet Kaan GümüşParent: cd6bccf
  • feat
    • 🏫 lay the class-layer schema and bounds
Show full message
feat: 🏫 lay the class-layer schema and bounds
src/constant.rsmodified+17 -0
@@ -86,6 +86,12 @@ pub const MAX_EXAM_DESCRIPTION_LEN: usize = 2_000;
86 pub const MAX_COURSE_TITLE_LEN: usize = 200;86 pub const MAX_COURSE_TITLE_LEN: usize = 200;
87 pub const MAX_COURSE_DESCRIPTION_LEN: usize = 2_000;87 pub const MAX_COURSE_DESCRIPTION_LEN: usize = 2_000;
88 88
89+/// A class (şube) is named like a course, but its optional `grade` is a free-text
90+/// label the school picks ("9", "10-A", "anaokulu") — a line of display text, so
91+/// it is bounded like the other short labels, not like a description.
92+pub const MAX_CLASS_NAME_LEN: usize = 200;
93+pub const MAX_CLASS_GRADE_LEN: usize = 20;
94+
89 pub const MAX_SUBJECT_NAME_LEN: usize = 200;95 pub const MAX_SUBJECT_NAME_LEN: usize = 200;
90 pub const MAX_SUBJECT_DESCRIPTION_LEN: usize = 2_000;96 pub const MAX_SUBJECT_DESCRIPTION_LEN: usize = 2_000;
91 97
@@ -698,6 +704,9 @@ pub const BANK_QUESTION_TABLE: &str = "bank_question";
698 pub const BANK_QUESTION_IMAGE_TABLE: &str = "bank_question_image";704 pub const BANK_QUESTION_IMAGE_TABLE: &str = "bank_question_image";
699 pub const COURSE_TABLE: &str = "course";705 pub const COURSE_TABLE: &str = "course";
700 pub const ENROLLMENT_TABLE: &str = "enrollment";706 pub const ENROLLMENT_TABLE: &str = "enrollment";
707+pub const CLASS_GROUP_TABLE: &str = "class_group";
708+pub const CLASS_MEMBER_TABLE: &str = "class_member";
709+pub const CLASS_COURSE_TABLE: &str = "class_course";
701 pub const PARENT_LINK_TABLE: &str = "parent_link";710 pub const PARENT_LINK_TABLE: &str = "parent_link";
702 pub const COURSE_SESSION_TABLE: &str = "course_session";711 pub const COURSE_SESSION_TABLE: &str = "course_session";
703 pub const SESSION_ATTENDANCE_TABLE: &str = "session_attendance";712 pub const SESSION_ATTENDANCE_TABLE: &str = "session_attendance";
@@ -750,6 +759,14 @@ pub const REGISTRATION_COUNT_FIELD: &str = "registration_count";
750 /// is claimed before a course's link is written, so the two decisions contend759 /// is claimed before a course's link is written, so the two decisions contend
751 /// on the term row instead of on a cross-table `SELECT` no transaction orders.760 /// on the term row instead of on a cross-table `SELECT` no transaction orders.
752 pub const COURSE_COUNT_FIELD: &str = "course_count";761 pub const COURSE_COUNT_FIELD: &str = "course_count";
762+/// The two refcounts on a class row: how many students it holds and how many
763+/// courses it is attached to. A class may only be dropped at zero on both.
764+pub const CLASS_MEMBER_COUNT_FIELD: &str = "class_member_count";
765+pub const CLASS_COURSE_COUNT_FIELD: &str = "class_course_count";
766+/// Classes linking a term, the second half of the term delete guard. Deliberately
767+/// *not* `COURSE_COUNT_FIELD`: boot recounts that one from the course rows alone,
768+/// so a class claiming into it would be wiped on the next migration.
769+pub const TERM_CLASS_COUNT_FIELD: &str = "class_count";
753 /// A refcount too, and the whole of the fee-plan edit *and* delete guard: how770 /// A refcount too, and the whole of the fee-plan edit *and* delete guard: how
754 /// many students are on this plan. A plan may only be edited or deleted at771 /// many students are on this plan. A plan may only be edited or deleted at
755 /// zero, and the count is claimed in the same transaction as the assignment772 /// zero, and the count is claimed in the same transaction as the assignment
src/migration_sql.rsmodified+34 -0
@@ -239,6 +239,9 @@ pub const MIGRATION: &str = "
239 -- write-skew between concurrent request tasks (see `crate::domain::cap`).239 -- write-skew between concurrent request tasks (see `crate::domain::cap`).
240 -- Absent reads as zero, so no Rust struct needs it.240 -- Absent reads as zero, so no Rust struct needs it.
241 DEFINE FIELD IF NOT EXISTS course_count ON term TYPE option<int>;241 DEFINE FIELD IF NOT EXISTS course_count ON term TYPE option<int>;
242+ -- Classes linking this term, the other half of the same guard. A column of
243+ -- its own because `course_count` is seeded from the course rows alone.
244+ DEFINE FIELD IF NOT EXISTS class_count ON term TYPE option<int>;
242 245
243 DEFINE TABLE IF NOT EXISTS course SCHEMAFULL;246 DEFINE TABLE IF NOT EXISTS course SCHEMAFULL;
244 DEFINE FIELD IF NOT EXISTS creator ON course TYPE record<user>;247 DEFINE FIELD IF NOT EXISTS creator ON course TYPE record<user>;
@@ -262,10 +265,41 @@ pub const MIGRATION: &str = "
262 DEFINE FIELD IF NOT EXISTS homework_count ON subject TYPE option<int>;265 DEFINE FIELD IF NOT EXISTS homework_count ON subject TYPE option<int>;
263 DEFINE INDEX IF NOT EXISTS subject_course ON subject FIELDS course;266 DEFINE INDEX IF NOT EXISTS subject_course ON subject FIELDS course;
264 267
268+ -- A class (şube) is a named set of students that bulk-manages real
269+ -- `enrollment` rows: `class_member` is one student in it, `class_course` one
270+ -- course it is attached to. Both counters gate the class delete.
271+ DEFINE TABLE IF NOT EXISTS class_group SCHEMAFULL;
272+ DEFINE FIELD IF NOT EXISTS name ON class_group TYPE string;
273+ DEFINE FIELD IF NOT EXISTS grade ON class_group TYPE option<string>;
274+ DEFINE FIELD IF NOT EXISTS term ON class_group TYPE option<record<term>>;
275+ DEFINE FIELD IF NOT EXISTS creator ON class_group TYPE record<user>;
276+ DEFINE FIELD IF NOT EXISTS class_member_count ON class_group TYPE option<int>;
277+ DEFINE FIELD IF NOT EXISTS class_course_count ON class_group TYPE option<int>;
278+
279+ DEFINE TABLE IF NOT EXISTS class_member SCHEMAFULL;
280+ DEFINE FIELD IF NOT EXISTS class ON class_member TYPE record<class_group>;
281+ DEFINE FIELD IF NOT EXISTS user ON class_member TYPE record<user>;
282+ DEFINE FIELD IF NOT EXISTS added_by ON class_member TYPE record<user>;
283+ DEFINE INDEX IF NOT EXISTS class_member_class_user ON class_member FIELDS class, user UNIQUE;
284+ DEFINE INDEX IF NOT EXISTS class_member_class ON class_member FIELDS class;
285+ DEFINE INDEX IF NOT EXISTS class_member_user ON class_member FIELDS user;
286+
287+ DEFINE TABLE IF NOT EXISTS class_course SCHEMAFULL;
288+ DEFINE FIELD IF NOT EXISTS class ON class_course TYPE record<class_group>;
289+ DEFINE FIELD IF NOT EXISTS course ON class_course TYPE record<course>;
290+ DEFINE FIELD IF NOT EXISTS attached_by ON class_course TYPE record<user>;
291+ DEFINE INDEX IF NOT EXISTS class_course_class_course ON class_course FIELDS class, course UNIQUE;
292+ DEFINE INDEX IF NOT EXISTS class_course_class ON class_course FIELDS class;
293+ DEFINE INDEX IF NOT EXISTS class_course_course ON class_course FIELDS course;
294+
265 DEFINE TABLE IF NOT EXISTS enrollment SCHEMAFULL;295 DEFINE TABLE IF NOT EXISTS enrollment SCHEMAFULL;
266 DEFINE FIELD IF NOT EXISTS course ON enrollment TYPE record<course>;296 DEFINE FIELD IF NOT EXISTS course ON enrollment TYPE record<course>;
267 DEFINE FIELD IF NOT EXISTS user ON enrollment TYPE record<user>;297 DEFINE FIELD IF NOT EXISTS user ON enrollment TYPE record<user>;
268 DEFINE FIELD IF NOT EXISTS enrolled_by ON enrollment TYPE record<user>;298 DEFINE FIELD IF NOT EXISTS enrolled_by ON enrollment TYPE record<user>;
299+ -- The class that pumped this row, absent when a human placed the student
300+ -- directly. Absence is the meaning, so there is nothing to backfill: a class
301+ -- sweep may only take back the rows it wrote.
302+ DEFINE FIELD IF NOT EXISTS source ON enrollment TYPE option<record<class_group>>;
269 DEFINE INDEX IF NOT EXISTS enrollment_course_user ON enrollment FIELDS course, user UNIQUE;303 DEFINE INDEX IF NOT EXISTS enrollment_course_user ON enrollment FIELDS course, user UNIQUE;
270 DEFINE INDEX IF NOT EXISTS enrollment_user ON enrollment FIELDS user;304 DEFINE INDEX IF NOT EXISTS enrollment_user ON enrollment FIELDS user;
271 305
src/web/limits.rsmodified+7 -1
@@ -106,7 +106,8 @@ struct EventLimits {
106 max_description_len: usize,106 max_description_len: usize,
107 }107 }
108 108
109-/// Courses, their curriculum subjects, and lesson sessions.109+/// Courses, their curriculum subjects, lesson sessions, and the classes that
110+/// bulk-enroll into them.
110 #[derive(Serialize, ToSchema)]111 #[derive(Serialize, ToSchema)]
111 struct CourseLimits {112 struct CourseLimits {
112 max_title_len: usize,113 max_title_len: usize,
@@ -118,6 +119,9 @@ struct CourseLimits {
118 max_subject_description_len: usize,119 max_subject_description_len: usize,
119 max_session_topic_len: usize,120 max_session_topic_len: usize,
120 max_term_name_len: usize,121 max_term_name_len: usize,
122+ max_class_name_len: usize,
123+ /// A class's optional free-text grade label ("9", "10-A").
124+ max_class_grade_len: usize,
121 }125 }
122 126
123 /// Exams, their questions, answers, and marks.127 /// Exams, their questions, answers, and marks.
@@ -420,6 +424,8 @@ impl LimitsResponse {
420 max_subject_description_len: MAX_SUBJECT_DESCRIPTION_LEN,424 max_subject_description_len: MAX_SUBJECT_DESCRIPTION_LEN,
421 max_session_topic_len: MAX_SESSION_TOPIC_LEN,425 max_session_topic_len: MAX_SESSION_TOPIC_LEN,
422 max_term_name_len: MAX_TERM_NAME_LEN,426 max_term_name_len: MAX_TERM_NAME_LEN,
427+ max_class_name_len: MAX_CLASS_NAME_LEN,
428+ max_class_grade_len: MAX_CLASS_GRADE_LEN,
423 },429 },
424 exam: ExamLimits {430 exam: ExamLimits {
425 max_title_len: MAX_EXAM_TITLE_LEN,431 max_title_len: MAX_EXAM_TITLE_LEN,