Pre-prod schema: person join key, drop school password copy
Browse files at this commit804bd3c69c4f630b2a273218c464d3e3ef9ade67Parent: 612a884- feat
- pre-prod schema: person join key, drop school password copy
145 changed files +1758 -1915
- .sqlx/query-01137f478e8052ac393515c5a26cf1ef16e3209150b3d15d94d65c9b2ecb2824.json +0 -15
- .sqlx/query-0a8892a6a3eb57b0e02e4340abba3c6241102483de35c59e31fbb351bc677202.json +64 -0
- .sqlx/query-0bbcdb6f1b8b0c7d518b5e32c2b3aad7cbdab3e8e972c619c0cb05bfc2be7cac.json +28 -0
- .sqlx/query-40a7f3cec635eeb143336c87ea38028e937608109e9f2bd583084a5d8febf6a4.json → .sqlx/query-0f4855352631239aaf9aac48ad4510afd1081f61c523106c60c62ae3c7ad9944.json +6 -6
- .sqlx/query-2c7c0898e7f4d8131d5683d70e718ae35e1969cbe33e21781907c572bf2a66e3.json → .sqlx/query-110d348f669e2895d2537a67a3a5babd214d94d7d0c879a858311abc04da9560.json +4 -3
- .sqlx/query-ba87bfbbbf6cdca3ac0d1544c86306944919cf6f4026744eef245e8fbd5d982a.json → .sqlx/query-1426cb1fc87d2e06ea919254bac9cb3403d07318c2bb43388a8dca245a952fc8.json +4 -3
- .sqlx/query-14db52e674777efa73c824f94af93ab2d197bdbccf8d94beea4943d9a3b17f90.json +0 -221
- .sqlx/query-fc15e864cec24208e364d047c7c7fce91281a080da50c2c509cbb6470e7c212a.json → .sqlx/query-15e1d6d5b56bbdbc817402c8b92202dc705ca27d14da7016adb201145c2229b0.json +6 -6
- .sqlx/query-f9a7f1eba3e17f7aec59c1c21d9e0335d0f648a8f8c8b25f27445161b131712b.json → .sqlx/query-201a66d66d53b7e6aa7b882bf250bad3806f7d066c09c241a2c3cbc28d58a0e5.json +3 -39
- .sqlx/query-8c139417415e49694c492d70fcf612de89bc3ef5dc2611d7a4cde2bf0c01d430.json → .sqlx/query-21038488baf4bb7c99de9f75dcf11b6183596b77bb5f3eadca699acc37016367.json +4 -3
- .sqlx/query-eab35aebb71eda25b39cb97d4437f9fd1b3cc602ef0403cae3f0eef284ad5f98.json → .sqlx/query-23a1369a6a30b803cafaaa75e7203ace62afc4d3bbc55cdec686920ac0fdd570.json +2 -2
- .sqlx/query-24753c350019e38e0d71e5ec3677999f61acb40ca3530a6f187acbec4bafe95c.json +17 -0
- .sqlx/query-2d99e80f8fedbef5029e37e426f4c95766c83f19c4bc801d6f99baee11696569.json +0 -23
- .sqlx/query-0e07d306c0ad413d269e73f90826d694154ba0e78011b42e277556069db1e1c2.json → .sqlx/query-3b7d8a00a0bba2941ab58aa40a4f4c53d14796284b8a2eafb482d1fac06966c5.json +3 -38
- .sqlx/query-0f9e44ea5d44c057ea95a3dd7006e5e133f6df1a0f284e41bc64ba74b3bf348b.json → .sqlx/query-3d60209700585decbd009cd8d340e8a90d157e48fe791d84c45ed9c41ef8e745.json +2 -38
- .sqlx/query-3e61b9438e821420c2a19b4788c2a6697d4b0f89f6ea247b40adb7ef3bfadc9b.json +28 -0
- .sqlx/query-447b194a72b03ed8f6ea2be70808c09778fb771a4d6a497dfc572eeec640a914.json +28 -0
- .sqlx/query-6a9c3d65b96535b78994f3e86751b3d4d6aeea87621d61023f4bfa956e406690.json → .sqlx/query-4a0358abcaf4cb40aa163933b0693d0a07847c927cf227111eefddbbfcdd473d.json +3 -39
- .sqlx/query-4eb0c853e0f0dbfdab689b50ef7f49ad12806460e3181a728c9d213b86994759.json +17 -0
- .sqlx/query-5339f6bcf5b3634d8f56481af433ff85f4033d4bd9564e8c101e720ee5177b28.json +0 -14
- .sqlx/query-56efb3614b74f560c67b4eded8840fa69edaafd90370717086bf5ea33587ccc9.json +64 -0
- .sqlx/query-f51d8ec191322860edab5b5691eb75608b7a97611865c7c60835b671620d341d.json → .sqlx/query-58e602261d1ddb31b9b0d25cb87f46934b0c584727551c8f85d4744b543af99f.json +6 -6
- .sqlx/query-978ee2d572d4c605bc6efc79619a592706dab1a321d6a6afc02705624be5a9d2.json → .sqlx/query-5c49c6a3de866f7db70e13ce592b877972ba1729c8db31202abe0ece0337114b.json +2 -2
- .sqlx/query-640eda8540ee9ff418c99a67bb6744b6feff7ee0279025b7c2bd6bc457fc6890.json +28 -0
- .sqlx/query-714830734d9e787ce33c15e0027e83043ee456b16d6f4f856c3af00a16e977f3.json +64 -0
- .sqlx/query-be50288b93c89d7af01260c224d618b4f0503e6bc9ffe98a260d37781b4ffafe.json → .sqlx/query-71d04899eb9154c003e684424ff74f05dafe0fd7b11d51f9c572cee6591a9229.json +2 -39
- .sqlx/query-737f3d886474291e0875e7bd66d7aef4d7a718a6b900cf55725811cc0193c63b.json +0 -112
- .sqlx/query-7ef42e6925a0f1f65338d486da231542f6b2e0ea1ea0deb33a56e610e52a48ad.json +28 -0
- .sqlx/query-e0b4d2b3044ea3789088b96d5e94a26ddb6e2cf9a8c4975add584de027fd6129.json → .sqlx/query-81a7b9416011e6f61c2723adbc62c4499ac910c7d1228afb0ccfd1f28b02dc11.json +6 -6
- .sqlx/query-c3749cd58f34075bdd4568e519d212b3ead4691ab73272d0d1eae00b126d30f6.json → .sqlx/query-8752532672cac328e5a5a18d0cbd3d372f285cabee06be0a798fb477b5a98787.json +2 -38
- .sqlx/query-8bef59e3c15a1c19a23800bffe0dd2e43afa3a07509c593ac01828a9d511dcb3.json +28 -0
- .sqlx/query-8c457fff4a76cedba9338135a894713e2609cb8aed0e963ba491118d3aebe0a3.json +16 -0
- .sqlx/query-cbfa89d17e1e85a80d7d966b8a016241636a48ce16f69fb3c7a60ea0daeeae18.json → .sqlx/query-97201bc98edb694a2e07d8da4fd91718e519bfe092a9cdb735d65f654da2f58d.json +4 -3
- .sqlx/query-d55fea5f3a7984940247abf1f5aa70ab377956b5bd73eea3f052beda34c330d2.json → .sqlx/query-abfadabb2800fe7d24a29c2fefb9d53342ad156dd1ec856a31e61cd84ab14fc2.json +2 -38
- .sqlx/query-b13fbe46118621c9232dad317f012454024d0587e63d010f4f4e9c837b54ea46.json +28 -0
- .sqlx/query-b21b7cead2c7a5737594f65d926b19d442328c17626b2a9766a48a3fba108de3.json +17 -0
- .sqlx/query-98f14d5a29c39911636d47058ce39fd2e48177276cf04ef529625326b414a1ca.json → .sqlx/query-b2bccc168bdfc5b3fb5ae5d0f0164689877cb542d7a57e7bcb34e24f619122ca.json +4 -3
- .sqlx/query-b38dc08f857b6b4d513ab833a68c4f6f35d0883f920a16e133848377032f8ec7.json +0 -17
- .sqlx/query-b456d14c2d2995e199dd8469982675d5693328ba0bf54d95f392587025c044a3.json +0 -16
- .sqlx/query-b8a5a3348368cdff8471feda27935f12d583776ef91a10a879fc52b5ae35248a.json +64 -0
- .sqlx/query-b8cd6149b5f42e615c31018d2fdf306f157f5275587ae57d1e5146c9a76a51d3.json +17 -0
- .sqlx/query-b974949e3de075232f1220b8daec3799995ce55fd9f1097a7989c9ac466bccd2.json +0 -15
- .sqlx/query-b98d8909cb9032074d2ed751ed8196d28b55994655cab271d7660b050a37724d.json +0 -136
- .sqlx/query-c7a7010a5c92b584dfb05e486525b486f6789eacf8b91ee91ba6bfc41e28b224.json +28 -0
- .sqlx/query-99e79710dd2c15c90fdcbdadfa02b4f794bae5b308c904d4c1e21effdc10fd19.json → .sqlx/query-c8ff6de29d2a6825321c3de628a7d77fb6d3cfd2d74053304af55946ddeb5197.json +3 -39
- .sqlx/query-adf2538573b95fb3dd6138ee45469e4d1308caf090e0079b993cd350a6227325.json → .sqlx/query-cdf70b71ea45a12649a5586c9ef1185cf737b2284fc7e4b22cc15ca4470d62d0.json +3 -39
- .sqlx/query-8976db6b51d0e2019c6ecda3ada05fbbb8270044587c86a50396091e7ef542cd.json → .sqlx/query-d9dafaf7b0734e61a05c51caa2da71d7bfa5a6c70a05f03d431bfc6d956e73bd.json +2 -38
- .sqlx/query-db1585206cb88ca4a02b4f73b23e10ea7f51bf6c77bca5217040e11f0cf87239.json +0 -18
- .sqlx/query-bf12836a8da8bc01c3eb4ac728568f5777f33a4a250137dfd3b3ba0087741779.json → .sqlx/query-df7311334c93314352406e1097530e602a575930baf28e91933d9fa9adf7a2ed.json +4 -3
- .sqlx/query-46d41617a9a790c57a22c0c5dc3f1d8ff8efa70693c4ea8a67d9980f365499ae.json → .sqlx/query-e7049ca4ddf6a6103dbecabe61f56992e9e2105e5c2de3b148d5533e4ffc8989.json +6 -6
- .sqlx/query-e8a08dbbc2d58b7fd391beea26491ac2c61ac38d35a6805cc95dc2f370822b07.json +1 -1
- .sqlx/query-4dc841ae1b0ad493eb2b63a421ac3dc3e6026d28ac871a0d459a8422cbfd1c65.json → .sqlx/query-ec3f4c095d63d334a5c0af6ec8c73be375b10814ddef44ace4fca2919dadc8b1.json +3 -39
- .sqlx/query-ef02dcc7b39f93369deac9ba8bf0f5875142ea52b528f737165ac0ae7dcb606a.json +0 -16
- .sqlx/query-f030e7990981531cedf902ef0af1545a25eed85156ad89da42de5792d4a9d4a5.json +0 -16
- .sqlx/query-f033efcb08101eb7c3873abe1b079ccb175dc1dcacf75910ad9aa45d23210583.json +17 -0
- .sqlx/query-1b109ac4162684c4444aac1b25716ca51fbcfeaee5adc3d8ab8216a2b1ae22b9.json → .sqlx/query-f64594c9dd40fc944bcc77ae1bf62adc1a6d90c8cf53d4807dfa4db26d4faf41.json +6 -6
- .sqlx/query-168ce1cc3188b7e1ede75b8f783562f54c39ead09a8e41dc8d8ded3e1fcccef3.json → .sqlx/query-fcce69f1324abd0a60651f5f0bc3f0bcfbdf42be5b2f34f79a40d3c741055135.json +8 -7
- migrations/control/20260912000001_control.sql +5 -1
- migrations/control/20260913000001_person.sql +4 -0
- migrations/school/20260912000001_identity.sql +11 -1
- migrations/school/20260912000002_courses.sql +31 -10
- migrations/school/20260912000003_exams.sql +49 -20
- migrations/school/20260912000004_food_appointments_fees.sql +4 -2
- src/constant.rs +2 -0
- src/db/answer_image.rs +2 -2
- src/db/attendance.rs +8 -6
- src/db/badge.rs +4 -12
- src/db/bank_question.rs +1 -1
- src/db/bank_question_image.rs +2 -2
- src/db/builder.rs +2 -1
- src/db/chatbot_message.rs +2 -2
- src/db/chatbot_thread.rs +1 -1
- src/db/class_blueprint.rs +16 -7
- src/db/class_course.rs +10 -1
- src/db/class_group.rs +2 -2
- src/db/class_member.rs +2 -2
- src/db/class_pump.rs +34 -23
- src/db/course.rs +4 -4
- src/db/course_note_file.rs +1 -1
- src/db/course_session.rs +2 -2
- src/db/enrollment.rs +9 -6
- src/db/event.rs +2 -2
- src/db/exam.rs +6 -6
- src/db/exam_answer.rs +2 -2
- src/db/exam_attempt.rs +3 -8
- src/db/exam_question.rs +3 -8
- src/db/exam_result.rs +10 -7
- src/db/homework.rs +2 -2
- src/db/homework_file.rs +2 -2
- src/db/homework_result.rs +4 -4
- src/db/homework_submission.rs +3 -8
- src/db/meal_booking.rs +2 -2
- src/db/menu.rs +2 -2
- src/db/mod.rs +2 -0
- src/db/note_file.rs +1 -1
- src/db/person.rs +7 -6
- src/db/pomodoro.rs +1 -1
- src/db/pool_question.rs +156 -125
- src/db/pool_question_image.rs +53 -0
- src/db/profile.rs +4 -12
- src/db/rag_output.rs +1 -1
- src/db/registration.rs +6 -3
- src/db/session.rs +2 -2
- src/db/session_attendance.rs +7 -5
- src/db/solution.rs +99 -85
- src/db/solution_image.rs +49 -0
- src/db/term.rs +2 -2
- src/db/user.rs +67 -75
- src/db/work_entry.rs +2 -2
- src/domain/mod.rs +2 -0
- src/domain/pool_question.rs +8 -26
- src/domain/pool_question_image.rs +42 -0
- src/domain/solution.rs +0 -20
- src/domain/solution_image.rs +42 -0
- src/domain/user.rs +14 -10
- src/service/appointment.rs +2 -2
- src/service/appointment_slot.rs +2 -2
- src/service/class_member.rs +1 -6
- src/service/exam_attempt.rs +3 -8
- src/service/fee_plan_assignment.rs +2 -2
- src/service/meal_booking.rs +2 -2
- src/service/mod.rs +2 -0
- src/service/person.rs +2 -3
- src/service/pool_question.rs +14 -11
- src/service/pool_question_image.rs +26 -0
- src/service/solution.rs +18 -7
- src/service/solution_image.rs +23 -0
- src/service/user.rs +33 -54
- src/web/appointments.rs +2 -7
- src/web/auth.rs +1 -1
- src/web/bank_questions.rs +2 -7
- src/web/board_ws.rs +7 -16
- src/web/builder.rs +4 -7
- src/web/chatbot.rs +2 -2
- src/web/classes.rs +4 -12
- src/web/courses.rs +2 -7
- src/web/events.rs +2 -7
- src/web/mod.rs +4 -12
- src/web/questions.rs +86 -63
- src/web/tenant_state.rs +3 -11
- tests/builder_api.rs +3 -11
- tests/regress_classes.rs +2 -2
- tests/regress_course_child_orphans.rs +2 -2
- tests/regress_payments.rs +2 -2
- tests/regress_role_sweep.rs +2 -2
.sqlx/query-01137f478e8052ac393515c5a26cf1ef16e3209150b3d15d94d65c9b2ecb2824.jsondeleted+0 -15
| @@ -1,15 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "INSERT INTO person_school (person, school) VALUES ($1, $2) ON CONFLICT DO NOTHING", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text" | ||
| 10 | - ] | ||
| 11 | - }, | ||
| 12 | - "nullable": [] | ||
| 13 | - }, | ||
| 14 | - "hash": "01137f478e8052ac393515c5a26cf1ef16e3209150b3d15d94d65c9b2ecb2824" | ||
| 15 | -} | ||
.sqlx/query-0a8892a6a3eb57b0e02e4340abba3c6241102483de35c59e31fbb351bc677202.jsonadded+64 -0
| @@ -0,0 +1,64 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT solution AS \"solution: SolutionId\", file,\n content_type AS \"content_type: FileContentType\", size\n FROM solution_image WHERE solution = ANY($1)", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "solution: SolutionId", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution_image", | ||
| 13 | + "name": "solution" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + }, | ||
| 17 | + { | ||
| 18 | + "ordinal": 1, | ||
| 19 | + "name": "file", | ||
| 20 | + "type_info": "Text", | ||
| 21 | + "origin": { | ||
| 22 | + "Table": { | ||
| 23 | + "table": "solution_image", | ||
| 24 | + "name": "file" | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + }, | ||
| 28 | + { | ||
| 29 | + "ordinal": 2, | ||
| 30 | + "name": "content_type: FileContentType", | ||
| 31 | + "type_info": "Text", | ||
| 32 | + "origin": { | ||
| 33 | + "Table": { | ||
| 34 | + "table": "solution_image", | ||
| 35 | + "name": "content_type" | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "ordinal": 3, | ||
| 41 | + "name": "size", | ||
| 42 | + "type_info": "Int8", | ||
| 43 | + "origin": { | ||
| 44 | + "Table": { | ||
| 45 | + "table": "solution_image", | ||
| 46 | + "name": "size" | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + ], | ||
| 51 | + "parameters": { | ||
| 52 | + "Left": [ | ||
| 53 | + "UuidArray" | ||
| 54 | + ] | ||
| 55 | + }, | ||
| 56 | + "nullable": [ | ||
| 57 | + false, | ||
| 58 | + false, | ||
| 59 | + false, | ||
| 60 | + false | ||
| 61 | + ] | ||
| 62 | + }, | ||
| 63 | + "hash": "0a8892a6a3eb57b0e02e4340abba3c6241102483de35c59e31fbb351bc677202" | ||
| 64 | +} | ||
.sqlx/query-0bbcdb6f1b8b0c7d518b5e32c2b3aad7cbdab3e8e972c619c0cb05bfc2be7cac.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "DELETE FROM solution_image WHERE solution = $1 RETURNING file", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "file", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution_image", | ||
| 13 | + "name": "file" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "0bbcdb6f1b8b0c7d518b5e32c2b3aad7cbdab3e8e972c619c0cb05bfc2be7cac" | ||
| 28 | +} | ||
.sqlx/query-40a7f3cec635eeb143336c87ea38028e937608109e9f2bd583084a5d8febf6a4.json → .sqlx/query-0f4855352631239aaf9aac48ad4510afd1081f61c523106c60c62ae3c7ad9944.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = ANY($1)", | 3 | + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = ANY($1)", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -199,7 +199,7 @@ | |||
| 199 | "nullable": [ | 199 | "nullable": [ |
| 200 | false, | 200 | false, |
| 201 | false, | 201 | false, |
| 202 | - false, | 202 | + true, |
| 203 | false, | 203 | false, |
| 204 | true, | 204 | true, |
| 205 | true, | 205 | true, |
| @@ -216,5 +216,5 @@ | |||
| 216 | true | 216 | true |
| 217 | ] | 217 | ] |
| 218 | }, | 218 | }, |
| 219 | - "hash": "40a7f3cec635eeb143336c87ea38028e937608109e9f2bd583084a5d8febf6a4" | 219 | + "hash": "0f4855352631239aaf9aac48ad4510afd1081f61c523106c60c62ae3c7ad9944" |
| 220 | } | 220 | } |
.sqlx/query-2c7c0898e7f4d8131d5683d70e718ae35e1969cbe33e21781907c572bf2a66e3.json → .sqlx/query-110d348f669e2895d2537a67a3a5babd214d94d7d0c879a858311abc04da9560.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "WITH person AS (\n -- The lock handshake comes FIRST: FOR NO KEY UPDATE waits out a\n -- racing demotion and re-checks the role against the committed\n -- row. A data-modifying CTE executes even when the INSERT below\n -- matches nothing, so the bump must depend on this CTE's result —\n -- the EXISTS reference in `seat` forces that order.\n SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent'\n FOR NO KEY UPDATE),\n seat AS (\n UPDATE event SET registration_count = registration_count + 1\n WHERE id = $1\n AND (audience_capacity IS NULL OR registration_count < audience_capacity)\n AND EXISTS (SELECT 1 FROM person)\n RETURNING 1)\n INSERT INTO registration (event, app_user, registered_by)\n SELECT $1, $2, $3\n WHERE EXISTS (SELECT 1 FROM seat)\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", | 3 | + "query": "WITH person AS (\n -- The lock handshake comes FIRST: FOR NO KEY UPDATE waits out a\n -- racing demotion and re-checks the role against the committed\n -- row. A data-modifying CTE executes even when the INSERT below\n -- matches nothing, so the bump must depend on this CTE's result —\n -- the EXISTS reference in `seat` forces that order.\n SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent'\n FOR NO KEY UPDATE),\n seat AS (\n UPDATE event SET registration_count = registration_count + 1\n WHERE id = $1\n AND (audience_capacity IS NULL OR registration_count < audience_capacity)\n AND EXISTS (SELECT 1 FROM person)\n RETURNING 1)\n INSERT INTO registration (event, app_user, registered_by, created_at)\n SELECT $1, $2, $3, $4\n WHERE EXISTS (SELECT 1 FROM seat)\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -41,7 +41,8 @@ | |||
| 41 | "Left": [ | 41 | "Left": [ |
| 42 | "Uuid", | 42 | "Uuid", |
| 43 | "Uuid", | 43 | "Uuid", |
| 44 | - "Uuid" | 44 | + "Uuid", |
| 45 | + "Int8" | ||
| 45 | ] | 46 | ] |
| 46 | }, | 47 | }, |
| 47 | "nullable": [ | 48 | "nullable": [ |
| @@ -50,5 +51,5 @@ | |||
| 50 | false | 51 | false |
| 51 | ] | 52 | ] |
| 52 | }, | 53 | }, |
| 53 | - "hash": "2c7c0898e7f4d8131d5683d70e718ae35e1969cbe33e21781907c572bf2a66e3" | 54 | + "hash": "110d348f669e2895d2537a67a3a5babd214d94d7d0c879a858311abc04da9560" |
| 54 | } | 55 | } |
.sqlx/query-ba87bfbbbf6cdca3ac0d1544c86306944919cf6f4026744eef245e8fbd5d982a.json → .sqlx/query-1426cb1fc87d2e06ea919254bac9cb3403d07318c2bb43388a8dca245a952fc8.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "WITH seat AS (\n UPDATE course\n SET enrollment_count = enrollment_count + 1\n WHERE id = $1\n AND enrollment_count < COALESCE(capacity, $2)\n RETURNING 1)\n INSERT INTO enrollment (course, app_user, enrolled_by, source)\n SELECT $1, $3, $4, NULL WHERE EXISTS (SELECT 1 FROM seat)\n RETURNING course AS \"course: CourseId\", app_user AS \"user: UserId\",\n enrolled_by AS \"enrolled_by: UserId\", source AS \"source: ClassGroupId\"", | 3 | + "query": "WITH seat AS (\n UPDATE course\n SET enrollment_count = enrollment_count + 1\n WHERE id = $1\n AND enrollment_count < COALESCE(capacity, $2)\n RETURNING 1)\n INSERT INTO enrollment (course, app_user, enrolled_by, source, created_at)\n SELECT $1, $3, $4, NULL, $5 WHERE EXISTS (SELECT 1 FROM seat)\n RETURNING course AS \"course: CourseId\", app_user AS \"user: UserId\",\n enrolled_by AS \"enrolled_by: UserId\", source AS \"source: ClassGroupId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -53,7 +53,8 @@ | |||
| 53 | "Uuid", | 53 | "Uuid", |
| 54 | "Int8", | 54 | "Int8", |
| 55 | "Uuid", | 55 | "Uuid", |
| 56 | - "Uuid" | 56 | + "Uuid", |
| 57 | + "Int8" | ||
| 57 | ] | 58 | ] |
| 58 | }, | 59 | }, |
| 59 | "nullable": [ | 60 | "nullable": [ |
| @@ -63,5 +64,5 @@ | |||
| 63 | true | 64 | true |
| 64 | ] | 65 | ] |
| 65 | }, | 66 | }, |
| 66 | - "hash": "ba87bfbbbf6cdca3ac0d1544c86306944919cf6f4026744eef245e8fbd5d982a" | 67 | + "hash": "1426cb1fc87d2e06ea919254bac9cb3403d07318c2bb43388a8dca245a952fc8" |
| 67 | } | 68 | } |
.sqlx/query-14db52e674777efa73c824f94af93ab2d197bdbccf8d94beea4943d9a3b17f90.jsondeleted+0 -221
| @@ -1,221 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "UPDATE app_user SET password_hash = $2 WHERE id = $1\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [ | ||
| 6 | - { | ||
| 7 | - "ordinal": 0, | ||
| 8 | - "name": "id: UserId", | ||
| 9 | - "type_info": "Uuid", | ||
| 10 | - "origin": { | ||
| 11 | - "Table": { | ||
| 12 | - "table": "app_user", | ||
| 13 | - "name": "id" | ||
| 14 | - } | ||
| 15 | - } | ||
| 16 | - }, | ||
| 17 | - { | ||
| 18 | - "ordinal": 1, | ||
| 19 | - "name": "username: Username", | ||
| 20 | - "type_info": "Text", | ||
| 21 | - "origin": { | ||
| 22 | - "Table": { | ||
| 23 | - "table": "app_user", | ||
| 24 | - "name": "username" | ||
| 25 | - } | ||
| 26 | - } | ||
| 27 | - }, | ||
| 28 | - { | ||
| 29 | - "ordinal": 2, | ||
| 30 | - "name": "password_hash: PasswordHash", | ||
| 31 | - "type_info": "Text", | ||
| 32 | - "origin": { | ||
| 33 | - "Table": { | ||
| 34 | - "table": "app_user", | ||
| 35 | - "name": "password_hash" | ||
| 36 | - } | ||
| 37 | - } | ||
| 38 | - }, | ||
| 39 | - { | ||
| 40 | - "ordinal": 3, | ||
| 41 | - "name": "role: Role", | ||
| 42 | - "type_info": "Text", | ||
| 43 | - "origin": { | ||
| 44 | - "Table": { | ||
| 45 | - "table": "app_user", | ||
| 46 | - "name": "role" | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | - }, | ||
| 50 | - { | ||
| 51 | - "ordinal": 4, | ||
| 52 | - "name": "name: PersonName", | ||
| 53 | - "type_info": "Text", | ||
| 54 | - "origin": { | ||
| 55 | - "Table": { | ||
| 56 | - "table": "app_user", | ||
| 57 | - "name": "name" | ||
| 58 | - } | ||
| 59 | - } | ||
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "surname: PersonName", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "app_user", | ||
| 68 | - "name": "surname" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "email: Email", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "app_user", | ||
| 79 | - "name": "email" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "phone: Phone", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "app_user", | ||
| 90 | - "name": "phone" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "birth_date: BirthDate", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "app_user", | ||
| 101 | - "name": "birth_date" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "theme: Theme", | ||
| 108 | - "type_info": "Text", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "app_user", | ||
| 112 | - "name": "theme" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - }, | ||
| 116 | - { | ||
| 117 | - "ordinal": 10, | ||
| 118 | - "name": "language: Language", | ||
| 119 | - "type_info": "Text", | ||
| 120 | - "origin": { | ||
| 121 | - "Table": { | ||
| 122 | - "table": "app_user", | ||
| 123 | - "name": "language" | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - }, | ||
| 127 | - { | ||
| 128 | - "ordinal": 11, | ||
| 129 | - "name": "palette_color: PaletteColor", | ||
| 130 | - "type_info": "Text", | ||
| 131 | - "origin": { | ||
| 132 | - "Table": { | ||
| 133 | - "table": "app_user", | ||
| 134 | - "name": "palette_color" | ||
| 135 | - } | ||
| 136 | - } | ||
| 137 | - }, | ||
| 138 | - { | ||
| 139 | - "ordinal": 12, | ||
| 140 | - "name": "display_name: DisplayName", | ||
| 141 | - "type_info": "Text", | ||
| 142 | - "origin": { | ||
| 143 | - "Table": { | ||
| 144 | - "table": "app_user", | ||
| 145 | - "name": "display_name" | ||
| 146 | - } | ||
| 147 | - } | ||
| 148 | - }, | ||
| 149 | - { | ||
| 150 | - "ordinal": 13, | ||
| 151 | - "name": "bio: Bio", | ||
| 152 | - "type_info": "Text", | ||
| 153 | - "origin": { | ||
| 154 | - "Table": { | ||
| 155 | - "table": "app_user", | ||
| 156 | - "name": "bio" | ||
| 157 | - } | ||
| 158 | - } | ||
| 159 | - }, | ||
| 160 | - { | ||
| 161 | - "ordinal": 14, | ||
| 162 | - "name": "avatar_file", | ||
| 163 | - "type_info": "Text", | ||
| 164 | - "origin": { | ||
| 165 | - "Table": { | ||
| 166 | - "table": "app_user", | ||
| 167 | - "name": "avatar_file" | ||
| 168 | - } | ||
| 169 | - } | ||
| 170 | - }, | ||
| 171 | - { | ||
| 172 | - "ordinal": 15, | ||
| 173 | - "name": "avatar_content_type: FileContentType", | ||
| 174 | - "type_info": "Text", | ||
| 175 | - "origin": { | ||
| 176 | - "Table": { | ||
| 177 | - "table": "app_user", | ||
| 178 | - "name": "avatar_content_type" | ||
| 179 | - } | ||
| 180 | - } | ||
| 181 | - }, | ||
| 182 | - { | ||
| 183 | - "ordinal": 16, | ||
| 184 | - "name": "avatar_size", | ||
| 185 | - "type_info": "Int8", | ||
| 186 | - "origin": { | ||
| 187 | - "Table": { | ||
| 188 | - "table": "app_user", | ||
| 189 | - "name": "avatar_size" | ||
| 190 | - } | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | - ], | ||
| 194 | - "parameters": { | ||
| 195 | - "Left": [ | ||
| 196 | - "Uuid", | ||
| 197 | - "Text" | ||
| 198 | - ] | ||
| 199 | - }, | ||
| 200 | - "nullable": [ | ||
| 201 | - false, | ||
| 202 | - false, | ||
| 203 | - false, | ||
| 204 | - false, | ||
| 205 | - true, | ||
| 206 | - true, | ||
| 207 | - true, | ||
| 208 | - true, | ||
| 209 | - true, | ||
| 210 | - true, | ||
| 211 | - true, | ||
| 212 | - true, | ||
| 213 | - true, | ||
| 214 | - true, | ||
| 215 | - true, | ||
| 216 | - true, | ||
| 217 | - true | ||
| 218 | - ] | ||
| 219 | - }, | ||
| 220 | - "hash": "14db52e674777efa73c824f94af93ab2d197bdbccf8d94beea4943d9a3b17f90" | ||
| 221 | -} | ||
.sqlx/query-fc15e864cec24208e364d047c7c7fce91281a080da50c2c509cbb6470e7c212a.json → .sqlx/query-15e1d6d5b56bbdbc817402c8b92202dc705ca27d14da7016adb201145c2229b0.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE username = $1", | 3 | + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE username = $1", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -199,7 +199,7 @@ | |||
| 199 | "nullable": [ | 199 | "nullable": [ |
| 200 | false, | 200 | false, |
| 201 | false, | 201 | false, |
| 202 | - false, | 202 | + true, |
| 203 | false, | 203 | false, |
| 204 | true, | 204 | true, |
| 205 | true, | 205 | true, |
| @@ -216,5 +216,5 @@ | |||
| 216 | true | 216 | true |
| 217 | ] | 217 | ] |
| 218 | }, | 218 | }, |
| 219 | - "hash": "fc15e864cec24208e364d047c7c7fce91281a080da50c2c509cbb6470e7c212a" | 219 | + "hash": "15e1d6d5b56bbdbc817402c8b92202dc705ca27d14da7016adb201145c2229b0" |
| 220 | } | 220 | } |
.sqlx/query-f9a7f1eba3e17f7aec59c1c21d9e0335d0f648a8f8c8b25f27445161b131712b.json → .sqlx/query-201a66d66d53b7e6aa7b882bf250bad3806f7d066c09c241a2c3cbc28d58a0e5.jsonrenamed+3 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO solution (id, question, author, body, offered_at)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "INSERT INTO solution (id, question, author, body, offered_at)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -57,39 +57,6 @@ | |||
| 57 | "name": "offered_at" | 57 | "name": "offered_at" |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | } | 60 | } |
| 94 | ], | 61 | ], |
| 95 | "parameters": { | 62 | "parameters": { |
| @@ -106,11 +73,8 @@ | |||
| 106 | false, | 73 | false, |
| 107 | false, | 74 | false, |
| 108 | false, | 75 | false, |
| 109 | - false, | 76 | + false |
| 110 | - true, | ||
| 111 | - true, | ||
| 112 | - true | ||
| 113 | ] | 77 | ] |
| 114 | }, | 78 | }, |
| 115 | - "hash": "f9a7f1eba3e17f7aec59c1c21d9e0335d0f648a8f8c8b25f27445161b131712b" | 79 | + "hash": "201a66d66d53b7e6aa7b882bf250bad3806f7d066c09c241a2c3cbc28d58a0e5" |
| 116 | } | 80 | } |
.sqlx/query-8c139417415e49694c492d70fcf612de89bc3ef5dc2611d7a4cde2bf0c01d430.json → .sqlx/query-21038488baf4bb7c99de9f75dcf11b6183596b77bb5f3eadca699acc37016367.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO exam_result (exam, app_user, seq, mark, graded_by)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (exam, app_user, seq) DO UPDATE\n SET mark = EXCLUDED.mark, graded_by = EXCLUDED.graded_by\n RETURNING exam AS \"exam: ExamId\", app_user AS \"user: UserId\", seq,\n mark AS \"mark: Mark\", graded_by AS \"graded_by: UserId\"", | 3 | + "query": "INSERT INTO exam_result (exam, app_user, seq, mark, graded_by, graded_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (exam, app_user, seq) DO UPDATE\n SET mark = EXCLUDED.mark, graded_by = EXCLUDED.graded_by,\n graded_at = EXCLUDED.graded_at\n RETURNING exam AS \"exam: ExamId\", app_user AS \"user: UserId\", seq,\n mark AS \"mark: Mark\", graded_by AS \"graded_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -65,7 +65,8 @@ | |||
| 65 | "Uuid", | 65 | "Uuid", |
| 66 | "Int8", | 66 | "Int8", |
| 67 | "Int8", | 67 | "Int8", |
| 68 | - "Uuid" | 68 | + "Uuid", |
| 69 | + "Int8" | ||
| 69 | ] | 70 | ] |
| 70 | }, | 71 | }, |
| 71 | "nullable": [ | 72 | "nullable": [ |
| @@ -76,5 +77,5 @@ | |||
| 76 | false | 77 | false |
| 77 | ] | 78 | ] |
| 78 | }, | 79 | }, |
| 79 | - "hash": "8c139417415e49694c492d70fcf612de89bc3ef5dc2611d7a4cde2bf0c01d430" | 80 | + "hash": "21038488baf4bb7c99de9f75dcf11b6183596b77bb5f3eadca699acc37016367" |
| 80 | } | 81 | } |
.sqlx/query-eab35aebb71eda25b39cb97d4437f9fd1b3cc602ef0403cae3f0eef284ad5f98.json → .sqlx/query-23a1369a6a30b803cafaaa75e7203ace62afc4d3bbc55cdec686920ac0fdd570.jsonrenamed+2 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "DELETE FROM class_course WHERE class = $1 AND course = $2 AND source = $3\n RETURNING 1 AS \"one\"", | 3 | + "query": "DELETE FROM class_course WHERE class = $1 AND course = $2\n AND source = (SELECT id FROM class_blueprint WHERE grade = $3)\n RETURNING 1 AS \"one\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -21,5 +21,5 @@ | |||
| 21 | null | 21 | null |
| 22 | ] | 22 | ] |
| 23 | }, | 23 | }, |
| 24 | - "hash": "eab35aebb71eda25b39cb97d4437f9fd1b3cc602ef0403cae3f0eef284ad5f98" | 24 | + "hash": "23a1369a6a30b803cafaaa75e7203ace62afc4d3bbc55cdec686920ac0fdd570" |
| 25 | } | 25 | } |
.sqlx/query-24753c350019e38e0d71e5ec3677999f61acb40ca3530a6f187acbec4bafe95c.jsonadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO person (id, username, password_hash, created_at) VALUES ($1, $2, $3, $4)", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "Text", | ||
| 11 | + "Int8" | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + "nullable": [] | ||
| 15 | + }, | ||
| 16 | + "hash": "24753c350019e38e0d71e5ec3677999f61acb40ca3530a6f187acbec4bafe95c" | ||
| 17 | +} | ||
.sqlx/query-2d99e80f8fedbef5029e37e426f4c95766c83f19c4bc801d6f99baee11696569.jsondeleted+0 -23
| @@ -1,23 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "SELECT 1 AS \"one\" FROM class_blueprint WHERE grade = $1 FOR KEY SHARE", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [ | ||
| 6 | - { | ||
| 7 | - "ordinal": 0, | ||
| 8 | - "name": "one", | ||
| 9 | - "type_info": "Int4", | ||
| 10 | - "origin": "Expression" | ||
| 11 | - } | ||
| 12 | - ], | ||
| 13 | - "parameters": { | ||
| 14 | - "Left": [ | ||
| 15 | - "Text" | ||
| 16 | - ] | ||
| 17 | - }, | ||
| 18 | - "nullable": [ | ||
| 19 | - null | ||
| 20 | - ] | ||
| 21 | - }, | ||
| 22 | - "hash": "2d99e80f8fedbef5029e37e426f4c95766c83f19c4bc801d6f99baee11696569" | ||
| 23 | -} | ||
.sqlx/query-0e07d306c0ad413d269e73f90826d694154ba0e78011b42e277556069db1e1c2.json → .sqlx/query-3b7d8a00a0bba2941ab58aa40a4f4c53d14796284b8a2eafb482d1fac06966c5.jsonrenamed+3 -38
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM pool_question WHERE id = $1", | 3 | + "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"\n FROM pool_question\n WHERE status = $1 OR asker = $2\n ORDER BY asked_at DESC, id DESC", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,43 +79,11 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| 118 | "Left": [ | 85 | "Left": [ |
| 86 | + "Text", | ||
| 119 | "Uuid" | 87 | "Uuid" |
| 120 | ] | 88 | ] |
| 121 | }, | 89 | }, |
| @@ -126,11 +94,8 @@ | |||
| 126 | false, | 94 | false, |
| 127 | false, | 95 | false, |
| 128 | false, | 96 | false, |
| 129 | - true, | ||
| 130 | - true, | ||
| 131 | - true, | ||
| 132 | true | 97 | true |
| 133 | ] | 98 | ] |
| 134 | }, | 99 | }, |
| 135 | - "hash": "0e07d306c0ad413d269e73f90826d694154ba0e78011b42e277556069db1e1c2" | 100 | + "hash": "3b7d8a00a0bba2941ab58aa40a4f4c53d14796284b8a2eafb482d1fac06966c5" |
| 136 | } | 101 | } |
.sqlx/query-0f9e44ea5d44c057ea95a3dd7006e5e133f6df1a0f284e41bc64ba74b3bf348b.json → .sqlx/query-3d60209700585decbd009cd8d340e8a90d157e48fe791d84c45ed9c41ef8e745.jsonrenamed+2 -38
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO pool_question (id, asker, title, body, status, asked_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "INSERT INTO pool_question (id, asker, title, body, status, asked_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,39 +79,6 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| @@ -131,11 +98,8 @@ | |||
| 131 | false, | 98 | false, |
| 132 | false, | 99 | false, |
| 133 | false, | 100 | false, |
| 134 | - true, | ||
| 135 | - true, | ||
| 136 | - true, | ||
| 137 | true | 101 | true |
| 138 | ] | 102 | ] |
| 139 | }, | 103 | }, |
| 140 | - "hash": "0f9e44ea5d44c057ea95a3dd7006e5e133f6df1a0f284e41bc64ba74b3bf348b" | 104 | + "hash": "3d60209700585decbd009cd8d340e8a90d157e48fe791d84c45ed9c41ef8e745" |
| 141 | } | 105 | } |
.sqlx/query-3e61b9438e821420c2a19b4788c2a6697d4b0f89f6ea247b40adb7ef3bfadc9b.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT file FROM solution_image WHERE solution = $1", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "file", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution_image", | ||
| 13 | + "name": "file" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "3e61b9438e821420c2a19b4788c2a6697d4b0f89f6ea247b40adb7ef3bfadc9b" | ||
| 28 | +} | ||
.sqlx/query-447b194a72b03ed8f6ea2be70808c09778fb771a4d6a497dfc572eeec640a914.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT status FROM pool_question WHERE id = $1 FOR UPDATE", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "status", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "pool_question", | ||
| 13 | + "name": "status" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "447b194a72b03ed8f6ea2be70808c09778fb771a4d6a497dfc572eeec640a914" | ||
| 28 | +} | ||
.sqlx/query-6a9c3d65b96535b78994f3e86751b3d4d6aeea87621d61023f4bfa956e406690.json → .sqlx/query-4a0358abcaf4cb40aa163933b0693d0a07847c927cf227111eefddbbfcdd473d.jsonrenamed+3 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM solution WHERE id = $1 AND question = $2", | 3 | + "query": "SELECT id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\"\n FROM solution WHERE id = $1 AND question = $2", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -57,39 +57,6 @@ | |||
| 57 | "name": "offered_at" | 57 | "name": "offered_at" |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | } | 60 | } |
| 94 | ], | 61 | ], |
| 95 | "parameters": { | 62 | "parameters": { |
| @@ -103,11 +70,8 @@ | |||
| 103 | false, | 70 | false, |
| 104 | false, | 71 | false, |
| 105 | false, | 72 | false, |
| 106 | - false, | 73 | + false |
| 107 | - true, | ||
| 108 | - true, | ||
| 109 | - true | ||
| 110 | ] | 74 | ] |
| 111 | }, | 75 | }, |
| 112 | - "hash": "6a9c3d65b96535b78994f3e86751b3d4d6aeea87621d61023f4bfa956e406690" | 76 | + "hash": "4a0358abcaf4cb40aa163933b0693d0a07847c927cf227111eefddbbfcdd473d" |
| 113 | } | 77 | } |
.sqlx/query-4eb0c853e0f0dbfdab689b50ef7f49ad12806460e3181a728c9d213b86994759.jsonadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO pool_question_image (question, file, content_type, size)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (question) DO UPDATE\n SET file = EXCLUDED.file, content_type = EXCLUDED.content_type,\n size = EXCLUDED.size", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "Text", | ||
| 11 | + "Int8" | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + "nullable": [] | ||
| 15 | + }, | ||
| 16 | + "hash": "4eb0c853e0f0dbfdab689b50ef7f49ad12806460e3181a728c9d213b86994759" | ||
| 17 | +} | ||
.sqlx/query-5339f6bcf5b3634d8f56481af433ff85f4033d4bd9564e8c101e720ee5177b28.jsondeleted+0 -14
| @@ -1,14 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "UPDATE solution\n SET image_file = NULL, image_content_type = NULL, image_size = NULL\n WHERE id = $1", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid" | ||
| 9 | - ] | ||
| 10 | - }, | ||
| 11 | - "nullable": [] | ||
| 12 | - }, | ||
| 13 | - "hash": "5339f6bcf5b3634d8f56481af433ff85f4033d4bd9564e8c101e720ee5177b28" | ||
| 14 | -} | ||
.sqlx/query-56efb3614b74f560c67b4eded8840fa69edaafd90370717086bf5ea33587ccc9.jsonadded+64 -0
| @@ -0,0 +1,64 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT question AS \"question: PoolQuestionId\", file,\n content_type AS \"content_type: FileContentType\", size\n FROM pool_question_image WHERE question = ANY($1)", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "question: PoolQuestionId", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "pool_question_image", | ||
| 13 | + "name": "question" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + }, | ||
| 17 | + { | ||
| 18 | + "ordinal": 1, | ||
| 19 | + "name": "file", | ||
| 20 | + "type_info": "Text", | ||
| 21 | + "origin": { | ||
| 22 | + "Table": { | ||
| 23 | + "table": "pool_question_image", | ||
| 24 | + "name": "file" | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + }, | ||
| 28 | + { | ||
| 29 | + "ordinal": 2, | ||
| 30 | + "name": "content_type: FileContentType", | ||
| 31 | + "type_info": "Text", | ||
| 32 | + "origin": { | ||
| 33 | + "Table": { | ||
| 34 | + "table": "pool_question_image", | ||
| 35 | + "name": "content_type" | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "ordinal": 3, | ||
| 41 | + "name": "size", | ||
| 42 | + "type_info": "Int8", | ||
| 43 | + "origin": { | ||
| 44 | + "Table": { | ||
| 45 | + "table": "pool_question_image", | ||
| 46 | + "name": "size" | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + ], | ||
| 51 | + "parameters": { | ||
| 52 | + "Left": [ | ||
| 53 | + "UuidArray" | ||
| 54 | + ] | ||
| 55 | + }, | ||
| 56 | + "nullable": [ | ||
| 57 | + false, | ||
| 58 | + false, | ||
| 59 | + false, | ||
| 60 | + false | ||
| 61 | + ] | ||
| 62 | + }, | ||
| 63 | + "hash": "56efb3614b74f560c67b4eded8840fa69edaafd90370717086bf5ea33587ccc9" | ||
| 64 | +} | ||
.sqlx/query-f51d8ec191322860edab5b5691eb75608b7a97611865c7c60835b671620d341d.json → .sqlx/query-58e602261d1ddb31b9b0d25cb87f46934b0c584727551c8f85d4744b543af99f.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = $1", | 3 | + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = $1", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -199,7 +199,7 @@ | |||
| 199 | "nullable": [ | 199 | "nullable": [ |
| 200 | false, | 200 | false, |
| 201 | false, | 201 | false, |
| 202 | - false, | 202 | + true, |
| 203 | false, | 203 | false, |
| 204 | true, | 204 | true, |
| 205 | true, | 205 | true, |
| @@ -216,5 +216,5 @@ | |||
| 216 | true | 216 | true |
| 217 | ] | 217 | ] |
| 218 | }, | 218 | }, |
| 219 | - "hash": "f51d8ec191322860edab5b5691eb75608b7a97611865c7c60835b671620d341d" | 219 | + "hash": "58e602261d1ddb31b9b0d25cb87f46934b0c584727551c8f85d4744b543af99f" |
| 220 | } | 220 | } |
.sqlx/query-978ee2d572d4c605bc6efc79619a592706dab1a321d6a6afc02705624be5a9d2.json → .sqlx/query-5c49c6a3de866f7db70e13ce592b877972ba1729c8db31202abe0ece0337114b.jsonrenamed+2 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT class AS \"class: ClassGroupId\", course AS \"course: CourseId\"\n FROM class_course\n WHERE source = $1 AND course <> ALL($2)", | 3 | + "query": "SELECT class AS \"class: ClassGroupId\", course AS \"course: CourseId\"\n FROM class_course\n WHERE source = (SELECT id FROM class_blueprint WHERE grade = $1)\n AND course <> ALL($2)", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -37,5 +37,5 @@ | |||
| 37 | false | 37 | false |
| 38 | ] | 38 | ] |
| 39 | }, | 39 | }, |
| 40 | - "hash": "978ee2d572d4c605bc6efc79619a592706dab1a321d6a6afc02705624be5a9d2" | 40 | + "hash": "5c49c6a3de866f7db70e13ce592b877972ba1729c8db31202abe0ece0337114b" |
| 41 | } | 41 | } |
.sqlx/query-640eda8540ee9ff418c99a67bb6744b6feff7ee0279025b7c2bd6bc457fc6890.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT id FROM solution WHERE id = $1 FOR UPDATE", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "id", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution", | ||
| 13 | + "name": "id" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "640eda8540ee9ff418c99a67bb6744b6feff7ee0279025b7c2bd6bc457fc6890" | ||
| 28 | +} | ||
.sqlx/query-714830734d9e787ce33c15e0027e83043ee456b16d6f4f856c3af00a16e977f3.jsonadded+64 -0
| @@ -0,0 +1,64 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT solution AS \"solution: SolutionId\", file,\n content_type AS \"content_type: FileContentType\", size\n FROM solution_image WHERE solution = $1", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "solution: SolutionId", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution_image", | ||
| 13 | + "name": "solution" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + }, | ||
| 17 | + { | ||
| 18 | + "ordinal": 1, | ||
| 19 | + "name": "file", | ||
| 20 | + "type_info": "Text", | ||
| 21 | + "origin": { | ||
| 22 | + "Table": { | ||
| 23 | + "table": "solution_image", | ||
| 24 | + "name": "file" | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + }, | ||
| 28 | + { | ||
| 29 | + "ordinal": 2, | ||
| 30 | + "name": "content_type: FileContentType", | ||
| 31 | + "type_info": "Text", | ||
| 32 | + "origin": { | ||
| 33 | + "Table": { | ||
| 34 | + "table": "solution_image", | ||
| 35 | + "name": "content_type" | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "ordinal": 3, | ||
| 41 | + "name": "size", | ||
| 42 | + "type_info": "Int8", | ||
| 43 | + "origin": { | ||
| 44 | + "Table": { | ||
| 45 | + "table": "solution_image", | ||
| 46 | + "name": "size" | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + ], | ||
| 51 | + "parameters": { | ||
| 52 | + "Left": [ | ||
| 53 | + "Uuid" | ||
| 54 | + ] | ||
| 55 | + }, | ||
| 56 | + "nullable": [ | ||
| 57 | + false, | ||
| 58 | + false, | ||
| 59 | + false, | ||
| 60 | + false | ||
| 61 | + ] | ||
| 62 | + }, | ||
| 63 | + "hash": "714830734d9e787ce33c15e0027e83043ee456b16d6f4f856c3af00a16e977f3" | ||
| 64 | +} | ||
.sqlx/query-be50288b93c89d7af01260c224d618b4f0503e6bc9ffe98a260d37781b4ffafe.json → .sqlx/query-71d04899eb9154c003e684424ff74f05dafe0fd7b11d51f9c572cee6591a9229.jsonrenamed+2 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM pool_question\n WHERE status = $1 OR asker = $2\n ORDER BY asked_at DESC, id DESC", | 3 | + "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"\n FROM pool_question WHERE id = $1", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,44 +79,10 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| 118 | "Left": [ | 85 | "Left": [ |
| 119 | - "Text", | ||
| 120 | "Uuid" | 86 | "Uuid" |
| 121 | ] | 87 | ] |
| 122 | }, | 88 | }, |
| @@ -127,11 +93,8 @@ | |||
| 127 | false, | 93 | false, |
| 128 | false, | 94 | false, |
| 129 | false, | 95 | false, |
| 130 | - true, | ||
| 131 | - true, | ||
| 132 | - true, | ||
| 133 | true | 96 | true |
| 134 | ] | 97 | ] |
| 135 | }, | 98 | }, |
| 136 | - "hash": "be50288b93c89d7af01260c224d618b4f0503e6bc9ffe98a260d37781b4ffafe" | 99 | + "hash": "71d04899eb9154c003e684424ff74f05dafe0fd7b11d51f9c572cee6591a9229" |
| 137 | } | 100 | } |
.sqlx/query-737f3d886474291e0875e7bd66d7aef4d7a718a6b900cf55725811cc0193c63b.jsondeleted+0 -112
| @@ -1,112 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "SELECT id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM solution WHERE id = $1 FOR UPDATE", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [ | ||
| 6 | - { | ||
| 7 | - "ordinal": 0, | ||
| 8 | - "name": "id: SolutionId", | ||
| 9 | - "type_info": "Uuid", | ||
| 10 | - "origin": { | ||
| 11 | - "Table": { | ||
| 12 | - "table": "solution", | ||
| 13 | - "name": "id" | ||
| 14 | - } | ||
| 15 | - } | ||
| 16 | - }, | ||
| 17 | - { | ||
| 18 | - "ordinal": 1, | ||
| 19 | - "name": "question: PoolQuestionId", | ||
| 20 | - "type_info": "Uuid", | ||
| 21 | - "origin": { | ||
| 22 | - "Table": { | ||
| 23 | - "table": "solution", | ||
| 24 | - "name": "question" | ||
| 25 | - } | ||
| 26 | - } | ||
| 27 | - }, | ||
| 28 | - { | ||
| 29 | - "ordinal": 2, | ||
| 30 | - "name": "author: UserId", | ||
| 31 | - "type_info": "Uuid", | ||
| 32 | - "origin": { | ||
| 33 | - "Table": { | ||
| 34 | - "table": "solution", | ||
| 35 | - "name": "author" | ||
| 36 | - } | ||
| 37 | - } | ||
| 38 | - }, | ||
| 39 | - { | ||
| 40 | - "ordinal": 3, | ||
| 41 | - "name": "body: SolutionBody", | ||
| 42 | - "type_info": "Text", | ||
| 43 | - "origin": { | ||
| 44 | - "Table": { | ||
| 45 | - "table": "solution", | ||
| 46 | - "name": "body" | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | - }, | ||
| 50 | - { | ||
| 51 | - "ordinal": 4, | ||
| 52 | - "name": "offered_at: Timestamp", | ||
| 53 | - "type_info": "Int8", | ||
| 54 | - "origin": { | ||
| 55 | - "Table": { | ||
| 56 | - "table": "solution", | ||
| 57 | - "name": "offered_at" | ||
| 58 | - } | ||
| 59 | - } | ||
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - } | ||
| 94 | - ], | ||
| 95 | - "parameters": { | ||
| 96 | - "Left": [ | ||
| 97 | - "Uuid" | ||
| 98 | - ] | ||
| 99 | - }, | ||
| 100 | - "nullable": [ | ||
| 101 | - false, | ||
| 102 | - false, | ||
| 103 | - false, | ||
| 104 | - false, | ||
| 105 | - false, | ||
| 106 | - true, | ||
| 107 | - true, | ||
| 108 | - true | ||
| 109 | - ] | ||
| 110 | - }, | ||
| 111 | - "hash": "737f3d886474291e0875e7bd66d7aef4d7a718a6b900cf55725811cc0193c63b" | ||
| 112 | -} | ||
.sqlx/query-7ef42e6925a0f1f65338d486da231542f6b2e0ea1ea0deb33a56e610e52a48ad.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT file FROM pool_question_image WHERE question = $1", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "file", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "pool_question_image", | ||
| 13 | + "name": "file" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "7ef42e6925a0f1f65338d486da231542f6b2e0ea1ea0deb33a56e610e52a48ad" | ||
| 28 | +} | ||
.sqlx/query-e0b4d2b3044ea3789088b96d5e94a26ddb6e2cf9a8c4975add584de027fd6129.json → .sqlx/query-81a7b9416011e6f61c2723adbc62c4499ac910c7d1228afb0ccfd1f28b02dc11.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE role = $1 ORDER BY id DESC", | 3 | + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE role = $1 ORDER BY id DESC", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -199,7 +199,7 @@ | |||
| 199 | "nullable": [ | 199 | "nullable": [ |
| 200 | false, | 200 | false, |
| 201 | false, | 201 | false, |
| 202 | - false, | 202 | + true, |
| 203 | false, | 203 | false, |
| 204 | true, | 204 | true, |
| 205 | true, | 205 | true, |
| @@ -216,5 +216,5 @@ | |||
| 216 | true | 216 | true |
| 217 | ] | 217 | ] |
| 218 | }, | 218 | }, |
| 219 | - "hash": "e0b4d2b3044ea3789088b96d5e94a26ddb6e2cf9a8c4975add584de027fd6129" | 219 | + "hash": "81a7b9416011e6f61c2723adbc62c4499ac910c7d1228afb0ccfd1f28b02dc11" |
| 220 | } | 220 | } |
.sqlx/query-c3749cd58f34075bdd4568e519d212b3ead4691ab73272d0d1eae00b126d30f6.json → .sqlx/query-8752532672cac328e5a5a18d0cbd3d372f285cabee06be0a798fb477b5a98787.jsonrenamed+2 -38
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "UPDATE pool_question SET status = $2, approved_by = $3\n WHERE id = $1 AND status = $4\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "UPDATE pool_question SET status = $2, approved_by = $3\n WHERE id = $1 AND status = $4\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,39 +79,6 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| @@ -129,11 +96,8 @@ | |||
| 129 | false, | 96 | false, |
| 130 | false, | 97 | false, |
| 131 | false, | 98 | false, |
| 132 | - true, | ||
| 133 | - true, | ||
| 134 | - true, | ||
| 135 | true | 99 | true |
| 136 | ] | 100 | ] |
| 137 | }, | 101 | }, |
| 138 | - "hash": "c3749cd58f34075bdd4568e519d212b3ead4691ab73272d0d1eae00b126d30f6" | 102 | + "hash": "8752532672cac328e5a5a18d0cbd3d372f285cabee06be0a798fb477b5a98787" |
| 139 | } | 103 | } |
.sqlx/query-8bef59e3c15a1c19a23800bffe0dd2e43afa3a07509c593ac01828a9d511dcb3.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "DELETE FROM solution_image si\n USING solution s\n WHERE si.solution = s.id AND s.question = $1\n RETURNING si.file", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "file", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "solution_image", | ||
| 13 | + "name": "file" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "8bef59e3c15a1c19a23800bffe0dd2e43afa3a07509c593ac01828a9d511dcb3" | ||
| 28 | +} | ||
.sqlx/query-8c457fff4a76cedba9338135a894713e2609cb8aed0e963ba491118d3aebe0a3.jsonadded+16 -0
| @@ -0,0 +1,16 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO person_school (person, school, created_at) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "Int8" | ||
| 11 | + ] | ||
| 12 | + }, | ||
| 13 | + "nullable": [] | ||
| 14 | + }, | ||
| 15 | + "hash": "8c457fff4a76cedba9338135a894713e2609cb8aed0e963ba491118d3aebe0a3" | ||
| 16 | +} | ||
.sqlx/query-cbfa89d17e1e85a80d7d966b8a016241636a48ce16f69fb3c7a60ea0daeeae18.json → .sqlx/query-97201bc98edb694a2e07d8da4fd91718e519bfe092a9cdb735d65f654da2f58d.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO session_attendance (session, app_user, course, status, marked_by)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (session, app_user) DO UPDATE\n SET status = EXCLUDED.status, marked_by = EXCLUDED.marked_by\n RETURNING session AS \"session: CourseSessionId\", app_user AS \"user: UserId\",\n course AS \"course: CourseId\", status AS \"status: AttendanceStatus\",\n marked_by AS \"marked_by: UserId\"", | 3 | + "query": "INSERT INTO session_attendance (session, app_user, course, status, marked_by, marked_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (session, app_user) DO UPDATE\n SET status = EXCLUDED.status, marked_by = EXCLUDED.marked_by,\n marked_at = EXCLUDED.marked_at\n RETURNING session AS \"session: CourseSessionId\", app_user AS \"user: UserId\",\n course AS \"course: CourseId\", status AS \"status: AttendanceStatus\",\n marked_by AS \"marked_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -65,7 +65,8 @@ | |||
| 65 | "Uuid", | 65 | "Uuid", |
| 66 | "Uuid", | 66 | "Uuid", |
| 67 | "Text", | 67 | "Text", |
| 68 | - "Uuid" | 68 | + "Uuid", |
| 69 | + "Int8" | ||
| 69 | ] | 70 | ] |
| 70 | }, | 71 | }, |
| 71 | "nullable": [ | 72 | "nullable": [ |
| @@ -76,5 +77,5 @@ | |||
| 76 | false | 77 | false |
| 77 | ] | 78 | ] |
| 78 | }, | 79 | }, |
| 79 | - "hash": "cbfa89d17e1e85a80d7d966b8a016241636a48ce16f69fb3c7a60ea0daeeae18" | 80 | + "hash": "97201bc98edb694a2e07d8da4fd91718e519bfe092a9cdb735d65f654da2f58d" |
| 80 | } | 81 | } |
.sqlx/query-d55fea5f3a7984940247abf1f5aa70ab377956b5bd73eea3f052beda34c330d2.json → .sqlx/query-abfadabb2800fe7d24a29c2fefb9d53342ad156dd1ec856a31e61cd84ab14fc2.jsonrenamed+2 -38
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "DELETE FROM pool_question WHERE id = $1\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "DELETE FROM pool_question WHERE id = $1\n RETURNING id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,39 +79,6 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| @@ -126,11 +93,8 @@ | |||
| 126 | false, | 93 | false, |
| 127 | false, | 94 | false, |
| 128 | false, | 95 | false, |
| 129 | - true, | ||
| 130 | - true, | ||
| 131 | - true, | ||
| 132 | true | 96 | true |
| 133 | ] | 97 | ] |
| 134 | }, | 98 | }, |
| 135 | - "hash": "d55fea5f3a7984940247abf1f5aa70ab377956b5bd73eea3f052beda34c330d2" | 99 | + "hash": "abfadabb2800fe7d24a29c2fefb9d53342ad156dd1ec856a31e61cd84ab14fc2" |
| 136 | } | 100 | } |
.sqlx/query-b13fbe46118621c9232dad317f012454024d0587e63d010f4f4e9c837b54ea46.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "DELETE FROM pool_question_image WHERE question = $1 RETURNING file", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "file", | ||
| 9 | + "type_info": "Text", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "pool_question_image", | ||
| 13 | + "name": "file" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Uuid" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "b13fbe46118621c9232dad317f012454024d0587e63d010f4f4e9c837b54ea46" | ||
| 28 | +} | ||
.sqlx/query-b21b7cead2c7a5737594f65d926b19d442328c17626b2a9766a48a3fba108de3.jsonadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO solution_image (solution, file, content_type, size)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (solution) DO UPDATE\n SET file = EXCLUDED.file, content_type = EXCLUDED.content_type,\n size = EXCLUDED.size", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "Text", | ||
| 11 | + "Int8" | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + "nullable": [] | ||
| 15 | + }, | ||
| 16 | + "hash": "b21b7cead2c7a5737594f65d926b19d442328c17626b2a9766a48a3fba108de3" | ||
| 17 | +} | ||
.sqlx/query-98f14d5a29c39911636d47058ce39fd2e48177276cf04ef529625326b414a1ca.json → .sqlx/query-b2bccc168bdfc5b3fb5ae5d0f0164689877cb542d7a57e7bcb34e24f619122ca.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO attendance (event, app_user, status, marked_by)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (event, app_user) DO UPDATE SET status = $3, marked_by = $4\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", status AS \"status: AttendanceStatus\", marked_by AS \"marked_by: UserId\"", | 3 | + "query": "INSERT INTO attendance (event, app_user, status, marked_by, marked_at)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (event, app_user) DO UPDATE SET status = $3, marked_by = $4, marked_at = $5\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", status AS \"status: AttendanceStatus\", marked_by AS \"marked_by: UserId\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -53,7 +53,8 @@ | |||
| 53 | "Uuid", | 53 | "Uuid", |
| 54 | "Uuid", | 54 | "Uuid", |
| 55 | "Text", | 55 | "Text", |
| 56 | - "Uuid" | 56 | + "Uuid", |
| 57 | + "Int8" | ||
| 57 | ] | 58 | ] |
| 58 | }, | 59 | }, |
| 59 | "nullable": [ | 60 | "nullable": [ |
| @@ -63,5 +64,5 @@ | |||
| 63 | false | 64 | false |
| 64 | ] | 65 | ] |
| 65 | }, | 66 | }, |
| 66 | - "hash": "98f14d5a29c39911636d47058ce39fd2e48177276cf04ef529625326b414a1ca" | 67 | + "hash": "b2bccc168bdfc5b3fb5ae5d0f0164689877cb542d7a57e7bcb34e24f619122ca" |
| 67 | } | 68 | } |
.sqlx/query-b38dc08f857b6b4d513ab833a68c4f6f35d0883f920a16e133848377032f8ec7.jsondeleted+0 -17
| @@ -1,17 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "UPDATE solution\n SET image_file = $2, image_content_type = $3, image_size = $4\n WHERE id = $1", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text", | ||
| 10 | - "Text", | ||
| 11 | - "Int8" | ||
| 12 | - ] | ||
| 13 | - }, | ||
| 14 | - "nullable": [] | ||
| 15 | - }, | ||
| 16 | - "hash": "b38dc08f857b6b4d513ab833a68c4f6f35d0883f920a16e133848377032f8ec7" | ||
| 17 | -} | ||
.sqlx/query-b456d14c2d2995e199dd8469982675d5693328ba0bf54d95f392587025c044a3.jsondeleted+0 -16
| @@ -1,16 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "INSERT INTO person (id, username, password_hash) VALUES ($1, $2, $3)", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text", | ||
| 10 | - "Text" | ||
| 11 | - ] | ||
| 12 | - }, | ||
| 13 | - "nullable": [] | ||
| 14 | - }, | ||
| 15 | - "hash": "b456d14c2d2995e199dd8469982675d5693328ba0bf54d95f392587025c044a3" | ||
| 16 | -} | ||
.sqlx/query-b8a5a3348368cdff8471feda27935f12d583776ef91a10a879fc52b5ae35248a.jsonadded+64 -0
| @@ -0,0 +1,64 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT question AS \"question: PoolQuestionId\", file,\n content_type AS \"content_type: FileContentType\", size\n FROM pool_question_image WHERE question = $1", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "question: PoolQuestionId", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "pool_question_image", | ||
| 13 | + "name": "question" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + }, | ||
| 17 | + { | ||
| 18 | + "ordinal": 1, | ||
| 19 | + "name": "file", | ||
| 20 | + "type_info": "Text", | ||
| 21 | + "origin": { | ||
| 22 | + "Table": { | ||
| 23 | + "table": "pool_question_image", | ||
| 24 | + "name": "file" | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + }, | ||
| 28 | + { | ||
| 29 | + "ordinal": 2, | ||
| 30 | + "name": "content_type: FileContentType", | ||
| 31 | + "type_info": "Text", | ||
| 32 | + "origin": { | ||
| 33 | + "Table": { | ||
| 34 | + "table": "pool_question_image", | ||
| 35 | + "name": "content_type" | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "ordinal": 3, | ||
| 41 | + "name": "size", | ||
| 42 | + "type_info": "Int8", | ||
| 43 | + "origin": { | ||
| 44 | + "Table": { | ||
| 45 | + "table": "pool_question_image", | ||
| 46 | + "name": "size" | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + ], | ||
| 51 | + "parameters": { | ||
| 52 | + "Left": [ | ||
| 53 | + "Uuid" | ||
| 54 | + ] | ||
| 55 | + }, | ||
| 56 | + "nullable": [ | ||
| 57 | + false, | ||
| 58 | + false, | ||
| 59 | + false, | ||
| 60 | + false | ||
| 61 | + ] | ||
| 62 | + }, | ||
| 63 | + "hash": "b8a5a3348368cdff8471feda27935f12d583776ef91a10a879fc52b5ae35248a" | ||
| 64 | +} | ||
.sqlx/query-b8cd6149b5f42e615c31018d2fdf306f157f5275587ae57d1e5146c9a76a51d3.jsonadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO class_blueprint (id, grade, courses, creator)\n VALUES ($1, $2, $3, $4)", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "UuidArray", | ||
| 11 | + "Uuid" | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + "nullable": [] | ||
| 15 | + }, | ||
| 16 | + "hash": "b8cd6149b5f42e615c31018d2fdf306f157f5275587ae57d1e5146c9a76a51d3" | ||
| 17 | +} | ||
.sqlx/query-b974949e3de075232f1220b8daec3799995ce55fd9f1097a7989c9ac466bccd2.jsondeleted+0 -15
| @@ -1,15 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "UPDATE pool_question\n SET image_file = NULL, image_content_type = NULL, image_size = NULL\n WHERE id = $1 AND status = $2", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text" | ||
| 10 | - ] | ||
| 11 | - }, | ||
| 12 | - "nullable": [] | ||
| 13 | - }, | ||
| 14 | - "hash": "b974949e3de075232f1220b8daec3799995ce55fd9f1097a7989c9ac466bccd2" | ||
| 15 | -} | ||
.sqlx/query-b98d8909cb9032074d2ed751ed8196d28b55994655cab271d7660b050a37724d.jsondeleted+0 -136
| @@ -1,136 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM pool_question WHERE id = $1 FOR UPDATE", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [ | ||
| 6 | - { | ||
| 7 | - "ordinal": 0, | ||
| 8 | - "name": "id: PoolQuestionId", | ||
| 9 | - "type_info": "Uuid", | ||
| 10 | - "origin": { | ||
| 11 | - "Table": { | ||
| 12 | - "table": "pool_question", | ||
| 13 | - "name": "id" | ||
| 14 | - } | ||
| 15 | - } | ||
| 16 | - }, | ||
| 17 | - { | ||
| 18 | - "ordinal": 1, | ||
| 19 | - "name": "asker: UserId", | ||
| 20 | - "type_info": "Uuid", | ||
| 21 | - "origin": { | ||
| 22 | - "Table": { | ||
| 23 | - "table": "pool_question", | ||
| 24 | - "name": "asker" | ||
| 25 | - } | ||
| 26 | - } | ||
| 27 | - }, | ||
| 28 | - { | ||
| 29 | - "ordinal": 2, | ||
| 30 | - "name": "title: PoolQuestionTitle", | ||
| 31 | - "type_info": "Text", | ||
| 32 | - "origin": { | ||
| 33 | - "Table": { | ||
| 34 | - "table": "pool_question", | ||
| 35 | - "name": "title" | ||
| 36 | - } | ||
| 37 | - } | ||
| 38 | - }, | ||
| 39 | - { | ||
| 40 | - "ordinal": 3, | ||
| 41 | - "name": "body: PoolQuestionBody", | ||
| 42 | - "type_info": "Text", | ||
| 43 | - "origin": { | ||
| 44 | - "Table": { | ||
| 45 | - "table": "pool_question", | ||
| 46 | - "name": "body" | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | - }, | ||
| 50 | - { | ||
| 51 | - "ordinal": 4, | ||
| 52 | - "name": "status", | ||
| 53 | - "type_info": "Text", | ||
| 54 | - "origin": { | ||
| 55 | - "Table": { | ||
| 56 | - "table": "pool_question", | ||
| 57 | - "name": "status" | ||
| 58 | - } | ||
| 59 | - } | ||
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "asked_at: Timestamp", | ||
| 64 | - "type_info": "Int8", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "pool_question", | ||
| 68 | - "name": "asked_at" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "approved_by: UserId", | ||
| 75 | - "type_info": "Uuid", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "pool_question", | ||
| 79 | - "name": "approved_by" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - } | ||
| 116 | - ], | ||
| 117 | - "parameters": { | ||
| 118 | - "Left": [ | ||
| 119 | - "Uuid" | ||
| 120 | - ] | ||
| 121 | - }, | ||
| 122 | - "nullable": [ | ||
| 123 | - false, | ||
| 124 | - false, | ||
| 125 | - false, | ||
| 126 | - false, | ||
| 127 | - false, | ||
| 128 | - false, | ||
| 129 | - true, | ||
| 130 | - true, | ||
| 131 | - true, | ||
| 132 | - true | ||
| 133 | - ] | ||
| 134 | - }, | ||
| 135 | - "hash": "b98d8909cb9032074d2ed751ed8196d28b55994655cab271d7660b050a37724d" | ||
| 136 | -} | ||
.sqlx/query-c7a7010a5c92b584dfb05e486525b486f6789eacf8b91ee91ba6bfc41e28b224.jsonadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "SELECT id FROM class_blueprint WHERE grade = $1 FOR KEY SHARE", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [ | ||
| 6 | + { | ||
| 7 | + "ordinal": 0, | ||
| 8 | + "name": "id", | ||
| 9 | + "type_info": "Uuid", | ||
| 10 | + "origin": { | ||
| 11 | + "Table": { | ||
| 12 | + "table": "class_blueprint", | ||
| 13 | + "name": "id" | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + ], | ||
| 18 | + "parameters": { | ||
| 19 | + "Left": [ | ||
| 20 | + "Text" | ||
| 21 | + ] | ||
| 22 | + }, | ||
| 23 | + "nullable": [ | ||
| 24 | + false | ||
| 25 | + ] | ||
| 26 | + }, | ||
| 27 | + "hash": "c7a7010a5c92b584dfb05e486525b486f6789eacf8b91ee91ba6bfc41e28b224" | ||
| 28 | +} | ||
.sqlx/query-99e79710dd2c15c90fdcbdadfa02b4f794bae5b308c904d4c1e21effdc10fd19.json → .sqlx/query-c8ff6de29d2a6825321c3de628a7d77fb6d3cfd2d74053304af55946ddeb5197.jsonrenamed+3 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "UPDATE solution SET body = $2 WHERE id = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "UPDATE solution SET body = $2 WHERE id = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -57,39 +57,6 @@ | |||
| 57 | "name": "offered_at" | 57 | "name": "offered_at" |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | } | 60 | } |
| 94 | ], | 61 | ], |
| 95 | "parameters": { | 62 | "parameters": { |
| @@ -103,11 +70,8 @@ | |||
| 103 | false, | 70 | false, |
| 104 | false, | 71 | false, |
| 105 | false, | 72 | false, |
| 106 | - false, | 73 | + false |
| 107 | - true, | ||
| 108 | - true, | ||
| 109 | - true | ||
| 110 | ] | 74 | ] |
| 111 | }, | 75 | }, |
| 112 | - "hash": "99e79710dd2c15c90fdcbdadfa02b4f794bae5b308c904d4c1e21effdc10fd19" | 76 | + "hash": "c8ff6de29d2a6825321c3de628a7d77fb6d3cfd2d74053304af55946ddeb5197" |
| 113 | } | 77 | } |
.sqlx/query-adf2538573b95fb3dd6138ee45469e4d1308caf090e0079b993cd350a6227325.json → .sqlx/query-cdf70b71ea45a12649a5586c9ef1185cf737b2284fc7e4b22cc15ca4470d62d0.jsonrenamed+3 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "DELETE FROM solution WHERE id = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "DELETE FROM solution WHERE id = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -57,39 +57,6 @@ | |||
| 57 | "name": "offered_at" | 57 | "name": "offered_at" |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | } | 60 | } |
| 94 | ], | 61 | ], |
| 95 | "parameters": { | 62 | "parameters": { |
| @@ -102,11 +69,8 @@ | |||
| 102 | false, | 69 | false, |
| 103 | false, | 70 | false, |
| 104 | false, | 71 | false, |
| 105 | - false, | 72 | + false |
| 106 | - true, | ||
| 107 | - true, | ||
| 108 | - true | ||
| 109 | ] | 73 | ] |
| 110 | }, | 74 | }, |
| 111 | - "hash": "adf2538573b95fb3dd6138ee45469e4d1308caf090e0079b993cd350a6227325" | 75 | + "hash": "cdf70b71ea45a12649a5586c9ef1185cf737b2284fc7e4b22cc15ca4470d62d0" |
| 112 | } | 76 | } |
.sqlx/query-8976db6b51d0e2019c6ecda3ada05fbbb8270044587c86a50396091e7ef542cd.json → .sqlx/query-d9dafaf7b0734e61a05c51caa2da71d7bfa5a6c70a05f03d431bfc6d956e73bd.jsonrenamed+2 -38
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size\n FROM pool_question ORDER BY asked_at DESC, id DESC", | 3 | + "query": "SELECT id AS \"id: PoolQuestionId\", asker AS \"asker: UserId\",\n title AS \"title: PoolQuestionTitle\", body AS \"body: PoolQuestionBody\",\n status, asked_at AS \"asked_at: Timestamp\",\n approved_by AS \"approved_by: UserId\"\n FROM pool_question ORDER BY asked_at DESC, id DESC", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -79,39 +79,6 @@ | |||
| 79 | "name": "approved_by" | 79 | "name": "approved_by" |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_file", | ||
| 86 | - "type_info": "Text", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "pool_question", | ||
| 90 | - "name": "image_file" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - "ordinal": 8, | ||
| 96 | - "name": "image_content_type: FileContentType", | ||
| 97 | - "type_info": "Text", | ||
| 98 | - "origin": { | ||
| 99 | - "Table": { | ||
| 100 | - "table": "pool_question", | ||
| 101 | - "name": "image_content_type" | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | - }, | ||
| 105 | - { | ||
| 106 | - "ordinal": 9, | ||
| 107 | - "name": "image_size", | ||
| 108 | - "type_info": "Int8", | ||
| 109 | - "origin": { | ||
| 110 | - "Table": { | ||
| 111 | - "table": "pool_question", | ||
| 112 | - "name": "image_size" | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | } | 82 | } |
| 116 | ], | 83 | ], |
| 117 | "parameters": { | 84 | "parameters": { |
| @@ -124,11 +91,8 @@ | |||
| 124 | false, | 91 | false, |
| 125 | false, | 92 | false, |
| 126 | false, | 93 | false, |
| 127 | - true, | ||
| 128 | - true, | ||
| 129 | - true, | ||
| 130 | true | 94 | true |
| 131 | ] | 95 | ] |
| 132 | }, | 96 | }, |
| 133 | - "hash": "8976db6b51d0e2019c6ecda3ada05fbbb8270044587c86a50396091e7ef542cd" | 97 | + "hash": "d9dafaf7b0734e61a05c51caa2da71d7bfa5a6c70a05f03d431bfc6d956e73bd" |
| 134 | } | 98 | } |
.sqlx/query-db1585206cb88ca4a02b4f73b23e10ea7f51bf6c77bca5217040e11f0cf87239.jsondeleted+0 -18
| @@ -1,18 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "UPDATE pool_question\n SET image_file = $2, image_content_type = $3, image_size = $4\n WHERE id = $1 AND status = $5", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text", | ||
| 10 | - "Text", | ||
| 11 | - "Int8", | ||
| 12 | - "Text" | ||
| 13 | - ] | ||
| 14 | - }, | ||
| 15 | - "nullable": [] | ||
| 16 | - }, | ||
| 17 | - "hash": "db1585206cb88ca4a02b4f73b23e10ea7f51bf6c77bca5217040e11f0cf87239" | ||
| 18 | -} | ||
.sqlx/query-bf12836a8da8bc01c3eb4ac728568f5777f33a4a250137dfd3b3ba0087741779.json → .sqlx/query-df7311334c93314352406e1097530e602a575930baf28e91933d9fa9adf7a2ed.jsonrenamed+4 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO enrollment (course, app_user, enrolled_by, source)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (course, app_user) DO NOTHING\n RETURNING 1 AS \"one\"", | 3 | + "query": "INSERT INTO enrollment (course, app_user, enrolled_by, source, created_at)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (course, app_user) DO NOTHING\n RETURNING 1 AS \"one\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -15,12 +15,13 @@ | |||
| 15 | "Uuid", | 15 | "Uuid", |
| 16 | "Uuid", | 16 | "Uuid", |
| 17 | "Uuid", | 17 | "Uuid", |
| 18 | - "Uuid" | 18 | + "Uuid", |
| 19 | + "Int8" | ||
| 19 | ] | 20 | ] |
| 20 | }, | 21 | }, |
| 21 | "nullable": [ | 22 | "nullable": [ |
| 22 | null | 23 | null |
| 23 | ] | 24 | ] |
| 24 | }, | 25 | }, |
| 25 | - "hash": "bf12836a8da8bc01c3eb4ac728568f5777f33a4a250137dfd3b3ba0087741779" | 26 | + "hash": "df7311334c93314352406e1097530e602a575930baf28e91933d9fa9adf7a2ed" |
| 26 | } | 27 | } |
.sqlx/query-46d41617a9a790c57a22c0c5dc3f1d8ff8efa70693c4ea8a67d9980f365499ae.json → .sqlx/query-e7049ca4ddf6a6103dbecabe61f56992e9e2105e5c2de3b148d5533e4ffc8989.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = $1 FOR UPDATE", | 3 | + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size\n FROM app_user WHERE id = $1 FOR UPDATE", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -199,7 +199,7 @@ | |||
| 199 | "nullable": [ | 199 | "nullable": [ |
| 200 | false, | 200 | false, |
| 201 | false, | 201 | false, |
| 202 | - false, | 202 | + true, |
| 203 | false, | 203 | false, |
| 204 | true, | 204 | true, |
| 205 | true, | 205 | true, |
| @@ -216,5 +216,5 @@ | |||
| 216 | true | 216 | true |
| 217 | ] | 217 | ] |
| 218 | }, | 218 | }, |
| 219 | - "hash": "46d41617a9a790c57a22c0c5dc3f1d8ff8efa70693c4ea8a67d9980f365499ae" | 219 | + "hash": "e7049ca4ddf6a6103dbecabe61f56992e9e2105e5c2de3b148d5533e4ffc8989" |
| 220 | } | 220 | } |
.sqlx/query-e8a08dbbc2d58b7fd391beea26491ac2c61ac38d35a6805cc95dc2f370822b07.jsonmodified+1 -1
| @@ -17,7 +17,7 @@ | |||
| 17 | "Uuid", | 17 | "Uuid", |
| 18 | "Uuid", | 18 | "Uuid", |
| 19 | "Int8", | 19 | "Int8", |
| 20 | - "Text" | 20 | + "Uuid" |
| 21 | ] | 21 | ] |
| 22 | }, | 22 | }, |
| 23 | "nullable": [ | 23 | "nullable": [ |
.sqlx/query-4dc841ae1b0ad493eb2b63a421ac3dc3e6026d28ac871a0d459a8422cbfd1c65.json → .sqlx/query-ec3f4c095d63d334a5c0af6ec8c73be375b10814ddef44ace4fca2919dadc8b1.jsonrenamed+3 -39
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "DELETE FROM solution WHERE question = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\", image_file,\n image_content_type AS \"image_content_type: FileContentType\",\n image_size", | 3 | + "query": "DELETE FROM solution WHERE question = $1\n RETURNING id AS \"id: SolutionId\", question AS \"question: PoolQuestionId\",\n author AS \"author: UserId\", body AS \"body: SolutionBody\",\n offered_at AS \"offered_at: Timestamp\"", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -57,39 +57,6 @@ | |||
| 57 | "name": "offered_at" | 57 | "name": "offered_at" |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | - }, | ||
| 61 | - { | ||
| 62 | - "ordinal": 5, | ||
| 63 | - "name": "image_file", | ||
| 64 | - "type_info": "Text", | ||
| 65 | - "origin": { | ||
| 66 | - "Table": { | ||
| 67 | - "table": "solution", | ||
| 68 | - "name": "image_file" | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - }, | ||
| 72 | - { | ||
| 73 | - "ordinal": 6, | ||
| 74 | - "name": "image_content_type: FileContentType", | ||
| 75 | - "type_info": "Text", | ||
| 76 | - "origin": { | ||
| 77 | - "Table": { | ||
| 78 | - "table": "solution", | ||
| 79 | - "name": "image_content_type" | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - }, | ||
| 83 | - { | ||
| 84 | - "ordinal": 7, | ||
| 85 | - "name": "image_size", | ||
| 86 | - "type_info": "Int8", | ||
| 87 | - "origin": { | ||
| 88 | - "Table": { | ||
| 89 | - "table": "solution", | ||
| 90 | - "name": "image_size" | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | } | 60 | } |
| 94 | ], | 61 | ], |
| 95 | "parameters": { | 62 | "parameters": { |
| @@ -102,11 +69,8 @@ | |||
| 102 | false, | 69 | false, |
| 103 | false, | 70 | false, |
| 104 | false, | 71 | false, |
| 105 | - false, | 72 | + false |
| 106 | - true, | ||
| 107 | - true, | ||
| 108 | - true | ||
| 109 | ] | 73 | ] |
| 110 | }, | 74 | }, |
| 111 | - "hash": "4dc841ae1b0ad493eb2b63a421ac3dc3e6026d28ac871a0d459a8422cbfd1c65" | 75 | + "hash": "ec3f4c095d63d334a5c0af6ec8c73be375b10814ddef44ace4fca2919dadc8b1" |
| 112 | } | 76 | } |
.sqlx/query-ef02dcc7b39f93369deac9ba8bf0f5875142ea52b528f737165ac0ae7dcb606a.jsondeleted+0 -16
| @@ -1,16 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "INSERT INTO class_blueprint (grade, courses, creator)\n VALUES ($1, $2, $3)", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Text", | ||
| 9 | - "UuidArray", | ||
| 10 | - "Uuid" | ||
| 11 | - ] | ||
| 12 | - }, | ||
| 13 | - "nullable": [] | ||
| 14 | - }, | ||
| 15 | - "hash": "ef02dcc7b39f93369deac9ba8bf0f5875142ea52b528f737165ac0ae7dcb606a" | ||
| 16 | -} | ||
.sqlx/query-f030e7990981531cedf902ef0af1545a25eed85156ad89da42de5792d4a9d4a5.jsondeleted+0 -16
| @@ -1,16 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "db_name": "PostgreSQL", | ||
| 3 | - "query": "INSERT INTO builder (id, username, password_hash) VALUES ($1, $2, $3)", | ||
| 4 | - "describe": { | ||
| 5 | - "columns": [], | ||
| 6 | - "parameters": { | ||
| 7 | - "Left": [ | ||
| 8 | - "Uuid", | ||
| 9 | - "Text", | ||
| 10 | - "Text" | ||
| 11 | - ] | ||
| 12 | - }, | ||
| 13 | - "nullable": [] | ||
| 14 | - }, | ||
| 15 | - "hash": "f030e7990981531cedf902ef0af1545a25eed85156ad89da42de5792d4a9d4a5" | ||
| 16 | -} | ||
.sqlx/query-f033efcb08101eb7c3873abe1b079ccb175dc1dcacf75910ad9aa45d23210583.jsonadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +{ | ||
| 2 | + "db_name": "PostgreSQL", | ||
| 3 | + "query": "INSERT INTO builder (id, username, password_hash, created_at) VALUES ($1, $2, $3, $4)", | ||
| 4 | + "describe": { | ||
| 5 | + "columns": [], | ||
| 6 | + "parameters": { | ||
| 7 | + "Left": [ | ||
| 8 | + "Uuid", | ||
| 9 | + "Text", | ||
| 10 | + "Text", | ||
| 11 | + "Int8" | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + "nullable": [] | ||
| 15 | + }, | ||
| 16 | + "hash": "f033efcb08101eb7c3873abe1b079ccb175dc1dcacf75910ad9aa45d23210583" | ||
| 17 | +} | ||
.sqlx/query-1b109ac4162684c4444aac1b25716ca51fbcfeaee5adc3d8ab8216a2b1ae22b9.json → .sqlx/query-f64594c9dd40fc944bcc77ae1bf62adc1a6d90c8cf53d4807dfa4db26d4faf41.jsonrenamed+6 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "UPDATE app_user SET role = $2\n WHERE id = $1\n AND NOT (role = 'admin'\n AND $2 <> 'admin'\n AND (SELECT count(*) FROM app_user\n WHERE role = 'admin' AND id <> $1) = 0)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size", | 3 | + "query": "UPDATE app_user SET role = $2\n WHERE id = $1\n AND NOT (role = 'admin'\n AND $2 <> 'admin'\n AND (SELECT count(*) FROM app_user\n WHERE role = 'admin' AND id <> $1) = 0)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -200,7 +200,7 @@ | |||
| 200 | "nullable": [ | 200 | "nullable": [ |
| 201 | false, | 201 | false, |
| 202 | false, | 202 | false, |
| 203 | - false, | 203 | + true, |
| 204 | false, | 204 | false, |
| 205 | true, | 205 | true, |
| 206 | true, | 206 | true, |
| @@ -217,5 +217,5 @@ | |||
| 217 | true | 217 | true |
| 218 | ] | 218 | ] |
| 219 | }, | 219 | }, |
| 220 | - "hash": "1b109ac4162684c4444aac1b25716ca51fbcfeaee5adc3d8ab8216a2b1ae22b9" | 220 | + "hash": "f64594c9dd40fc944bcc77ae1bf62adc1a6d90c8cf53d4807dfa4db26d4faf41" |
| 221 | } | 221 | } |
.sqlx/query-168ce1cc3188b7e1ede75b8f783562f54c39ead09a8e41dc8d8ded3e1fcccef3.json → .sqlx/query-fcce69f1324abd0a60651f5f0bc3f0bcfbdf42be5b2f34f79a40d3c741055135.jsonrenamed+8 -7
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "db_name": "PostgreSQL", | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "INSERT INTO app_user (id, username, password_hash, role)\n VALUES ($1, $2, $3, $4)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n password_hash AS \"password_hash: PasswordHash\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size", | 3 | + "query": "INSERT INTO app_user (id, username, person, role, created_at)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n avatar_size", |
| 4 | "describe": { | 4 | "describe": { |
| 5 | "columns": [ | 5 | "columns": [ |
| 6 | { | 6 | { |
| @@ -27,12 +27,12 @@ | |||
| 27 | }, | 27 | }, |
| 28 | { | 28 | { |
| 29 | "ordinal": 2, | 29 | "ordinal": 2, |
| 30 | - "name": "password_hash: PasswordHash", | 30 | + "name": "person: PersonId", |
| 31 | - "type_info": "Text", | 31 | + "type_info": "Uuid", |
| 32 | "origin": { | 32 | "origin": { |
| 33 | "Table": { | 33 | "Table": { |
| 34 | "table": "app_user", | 34 | "table": "app_user", |
| 35 | - "name": "password_hash" | 35 | + "name": "person" |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }, | 38 | }, |
| @@ -195,14 +195,15 @@ | |||
| 195 | "Left": [ | 195 | "Left": [ |
| 196 | "Uuid", | 196 | "Uuid", |
| 197 | "Text", | 197 | "Text", |
| 198 | + "Uuid", | ||
| 198 | "Text", | 199 | "Text", |
| 199 | - "Text" | 200 | + "Int8" |
| 200 | ] | 201 | ] |
| 201 | }, | 202 | }, |
| 202 | "nullable": [ | 203 | "nullable": [ |
| 203 | false, | 204 | false, |
| 204 | false, | 205 | false, |
| 205 | - false, | 206 | + true, |
| 206 | false, | 207 | false, |
| 207 | true, | 208 | true, |
| 208 | true, | 209 | true, |
| @@ -219,5 +220,5 @@ | |||
| 219 | true | 220 | true |
| 220 | ] | 221 | ] |
| 221 | }, | 222 | }, |
| 222 | - "hash": "168ce1cc3188b7e1ede75b8f783562f54c39ead09a8e41dc8d8ded3e1fcccef3" | 223 | + "hash": "fcce69f1324abd0a60651f5f0bc3f0bcfbdf42be5b2f34f79a40d3c741055135" |
| 223 | } | 224 | } |
migrations/control/20260912000001_control.sqlmodified+5 -1
| @@ -23,9 +23,12 @@ | |||
| 23 | -- `tier:client:window` key, so the PK is TEXT. | 23 | -- `tier:client:window` key, so the PK is TEXT. |
| 24 | 24 | ||
| 25 | CREATE TABLE school ( | 25 | CREATE TABLE school ( |
| 26 | + -- Immutable: a rename is blocked by the school_slug primary key below and | ||
| 27 | + -- by the per-school database name ({control}_school_{slug}) minted from | ||
| 28 | + -- it — a slug change would orphan the database. | ||
| 26 | slug TEXT NOT NULL, | 29 | slug TEXT NOT NULL, |
| 27 | name TEXT NOT NULL, | 30 | name TEXT NOT NULL, |
| 28 | - status TEXT NOT NULL CHECK (status IN ('active', 'suspended')), | 31 | + status TEXT NOT NULL CONSTRAINT school_status CHECK (status IN ('active', 'suspended')), |
| 29 | created_at BIGINT NOT NULL, | 32 | created_at BIGINT NOT NULL, |
| 30 | -- Which product modules this school has bought; names bound from | 33 | -- Which product modules this school has bought; names bound from |
| 31 | -- Module::ALL at write time, never spelled here. | 34 | -- Module::ALL at write time, never spelled here. |
| @@ -37,6 +40,7 @@ CREATE TABLE builder ( | |||
| 37 | id uuid PRIMARY KEY, | 40 | id uuid PRIMARY KEY, |
| 38 | username TEXT NOT NULL, | 41 | username TEXT NOT NULL, |
| 39 | password_hash TEXT NOT NULL, | 42 | password_hash TEXT NOT NULL, |
| 43 | + created_at BIGINT NOT NULL, | ||
| 40 | CONSTRAINT builder_username UNIQUE (username) | 44 | CONSTRAINT builder_username UNIQUE (username) |
| 41 | ); | 45 | ); |
| 42 | 46 | ||
migrations/control/20260913000001_person.sqlmodified+4 -0
| @@ -19,6 +19,7 @@ CREATE TABLE person ( | |||
| 19 | id uuid PRIMARY KEY, | 19 | id uuid PRIMARY KEY, |
| 20 | username TEXT NOT NULL, | 20 | username TEXT NOT NULL, |
| 21 | password_hash TEXT NOT NULL, | 21 | password_hash TEXT NOT NULL, |
| 22 | + created_at BIGINT NOT NULL, | ||
| 22 | -- Globally unique: the same username in two school databases is one and | 23 | -- Globally unique: the same username in two school databases is one and |
| 23 | -- the same person, copied into each school's `app_user`. | 24 | -- the same person, copied into each school's `app_user`. |
| 24 | CONSTRAINT person_username UNIQUE (username) | 25 | CONSTRAINT person_username UNIQUE (username) |
| @@ -27,6 +28,7 @@ CREATE TABLE person ( | |||
| 27 | CREATE TABLE person_school ( | 28 | CREATE TABLE person_school ( |
| 28 | person uuid NOT NULL REFERENCES person(id) ON DELETE NO ACTION, | 29 | person uuid NOT NULL REFERENCES person(id) ON DELETE NO ACTION, |
| 29 | school TEXT NOT NULL REFERENCES school(slug) ON DELETE NO ACTION, | 30 | school TEXT NOT NULL REFERENCES school(slug) ON DELETE NO ACTION, |
| 31 | + created_at BIGINT NOT NULL, | ||
| 30 | CONSTRAINT person_school_person_school PRIMARY KEY (person, school) | 32 | CONSTRAINT person_school_person_school PRIMARY KEY (person, school) |
| 31 | ); | 33 | ); |
| 32 | 34 | ||
| @@ -40,3 +42,5 @@ CREATE TABLE person_session ( | |||
| 40 | ); | 42 | ); |
| 41 | 43 | ||
| 42 | CREATE INDEX person_session_expires ON person_session (expires_at); | 44 | CREATE INDEX person_session_expires ON person_session (expires_at); |
| 45 | + | ||
| 46 | +CREATE INDEX person_session_person ON person_session (person); | ||
migrations/school/20260912000001_identity.sqlmodified+11 -1
| @@ -33,10 +33,14 @@ | |||
| 33 | -- statuses / exam kinds are school-configurable at runtime, which a DDL | 33 | -- statuses / exam kinds are school-configurable at runtime, which a DDL |
| 34 | -- CHECK could not survive. | 34 | -- CHECK could not survive. |
| 35 | 35 | ||
| 36 | +-- The school-side identity row. The password hash is NOT here: the credential | ||
| 37 | +-- lives on the control database's `person` row, and `app_user.person` is the | ||
| 38 | +-- join key to it (uuid, no FK — the two halves are separate databases). The | ||
| 39 | +-- `username` copy stays for display and for the school-scoped unique name. | ||
| 36 | CREATE TABLE app_user ( | 40 | CREATE TABLE app_user ( |
| 37 | id uuid PRIMARY KEY, | 41 | id uuid PRIMARY KEY, |
| 38 | username TEXT NOT NULL, | 42 | username TEXT NOT NULL, |
| 39 | - password_hash TEXT NOT NULL, | 43 | + person uuid NULL, |
| 40 | role TEXT NOT NULL DEFAULT 'student' | 44 | role TEXT NOT NULL DEFAULT 'student' |
| 41 | CHECK (role IN ('ai', 'parent', 'student', 'teacher', 'manager', 'admin')), | 45 | CHECK (role IN ('ai', 'parent', 'student', 'teacher', 'manager', 'admin')), |
| 42 | name TEXT NULL, | 46 | name TEXT NULL, |
| @@ -74,9 +78,15 @@ CREATE TABLE app_user ( | |||
| 74 | study_streak_last_day BIGINT NULL, | 78 | study_streak_last_day BIGINT NULL, |
| 75 | pomodoro_counted_today BIGINT NOT NULL DEFAULT 0, | 79 | pomodoro_counted_today BIGINT NOT NULL DEFAULT 0, |
| 76 | pomodoro_counted_day BIGINT NULL, | 80 | pomodoro_counted_day BIGINT NULL, |
| 81 | + created_at BIGINT NOT NULL, | ||
| 77 | CONSTRAINT app_user_username UNIQUE (username) | 82 | CONSTRAINT app_user_username UNIQUE (username) |
| 78 | ); | 83 | ); |
| 79 | 84 | ||
| 85 | +-- At most one school identity per person: the join key is 1:1. Partial | ||
| 86 | +-- because a school row minted before its person was known (boot seed order) | ||
| 87 | +-- legally reads NULL. | ||
| 88 | +CREATE UNIQUE INDEX app_user_person ON app_user (person) WHERE person IS NOT NULL; | ||
| 89 | + | ||
| 80 | CREATE TABLE user_session ( | 90 | CREATE TABLE user_session ( |
| 81 | id uuid PRIMARY KEY, | 91 | id uuid PRIMARY KEY, |
| 82 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 92 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
migrations/school/20260912000002_courses.sqlmodified+31 -10
| @@ -22,7 +22,22 @@ CREATE TABLE term ( | |||
| 22 | course_count BIGINT NOT NULL DEFAULT 0, | 22 | course_count BIGINT NOT NULL DEFAULT 0, |
| 23 | class_count BIGINT NOT NULL DEFAULT 0 | 23 | class_count BIGINT NOT NULL DEFAULT 0 |
| 24 | ); | 24 | ); |
| 25 | - | 25 | +-- A term is dropped, not cascaded: the nullable `term` FKs on course and |
| 26 | +-- class_group (ON DELETE NO ACTION) must be cleared to NULL first — a delete | ||
| 27 | +-- with a reference still standing is a 23503, not a sweep. The stored | ||
| 28 | +-- course_count/class_count are the pre-flight counters that refuse the drop | ||
| 29 | +-- before the FKs get the chance. | ||
| 30 | + | ||
| 31 | +-- db::course::delete sweeps every child in ONE transaction — a crash between | ||
| 32 | +-- statements must orphan nothing — so the guard is the course row itself: | ||
| 33 | +-- locked FOR UPDATE and refused while its enrollment_count is non-zero. The | ||
| 34 | +-- child order is the FK-safest one: exam results/attempts/answers/images and | ||
| 35 | +-- questions, homework files/submissions/results, rag output, note files and | ||
| 36 | +-- notes, class_course links (each class gets its class_course_count back and | ||
| 37 | +-- every blueprint drops the id from its list), session_attendance and | ||
| 38 | +-- course_session, enrollment (each seat given back), then the exam, homework | ||
| 39 | +-- and subject rows themselves. Bank questions keep their templates; only | ||
| 40 | +-- their subject/source_exam links are cleared. | ||
| 26 | CREATE TABLE course ( | 41 | CREATE TABLE course ( |
| 27 | id uuid PRIMARY KEY, | 42 | id uuid PRIMARY KEY, |
| 28 | creator uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 43 | creator uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| @@ -106,10 +121,10 @@ CREATE TABLE session_attendance ( | |||
| 106 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, | 121 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, |
| 107 | status TEXT NOT NULL, | 122 | status TEXT NOT NULL, |
| 108 | marked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 123 | marked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 124 | + marked_at BIGINT NOT NULL, | ||
| 109 | CONSTRAINT session_attendance_session_user PRIMARY KEY (session, app_user) | 125 | CONSTRAINT session_attendance_session_user PRIMARY KEY (session, app_user) |
| 110 | ); | 126 | ); |
| 111 | 127 | ||
| 112 | -CREATE INDEX session_attendance_session ON session_attendance (session); | ||
| 113 | CREATE INDEX session_attendance_user ON session_attendance (app_user); | 128 | CREATE INDEX session_attendance_user ON session_attendance (app_user); |
| 114 | CREATE INDEX session_attendance_course ON session_attendance (course); | 129 | CREATE INDEX session_attendance_course ON session_attendance (course); |
| 115 | 130 | ||
| @@ -126,12 +141,17 @@ CREATE TABLE class_group ( | |||
| 126 | 141 | ||
| 127 | CREATE INDEX class_group_grade ON class_group (grade); | 142 | CREATE INDEX class_group_grade ON class_group (grade); |
| 128 | 143 | ||
| 129 | --- A grade's course template. The grade label IS the record key in Surreal, so | 144 | +-- A grade's course template. The grade label is the identity the whole API |
| 130 | --- the PK here is TEXT on grade itself (no id column, no uuid). | 145 | +-- speaks and it stays UNIQUE, but the row carries a surrogate uuid PK: it is |
| 146 | +-- what class_course.source references, and a delete-and-recreate of the same | ||
| 147 | +-- grade mints a new id, so links tagged by the old one were swept by that | ||
| 148 | +-- delete instead of being adopted by the new blueprint (a TEXT grade tag | ||
| 149 | +-- made the two indistinguishable). | ||
| 131 | CREATE TABLE class_blueprint ( | 150 | CREATE TABLE class_blueprint ( |
| 132 | - grade TEXT PRIMARY KEY, | 151 | + id uuid PRIMARY KEY, |
| 133 | - courses uuid[] NOT NULL DEFAULT '{}', | 152 | + grade TEXT NOT NULL CONSTRAINT class_blueprint_grade_key UNIQUE, |
| 134 | - creator uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION | 153 | + courses uuid[] NOT NULL DEFAULT '{}', |
| 154 | + creator uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION | ||
| 135 | ); | 155 | ); |
| 136 | 156 | ||
| 137 | CREATE TABLE class_member ( | 157 | CREATE TABLE class_member ( |
| @@ -143,7 +163,6 @@ CREATE TABLE class_member ( | |||
| 143 | CONSTRAINT class_member_class_user PRIMARY KEY (class, app_user) | 163 | CONSTRAINT class_member_class_user PRIMARY KEY (class, app_user) |
| 144 | ); | 164 | ); |
| 145 | 165 | ||
| 146 | -CREATE INDEX class_member_class ON class_member (class); | ||
| 147 | CREATE INDEX class_member_user ON class_member (app_user); | 166 | CREATE INDEX class_member_user ON class_member (app_user); |
| 148 | 167 | ||
| 149 | CREATE TABLE class_course ( | 168 | CREATE TABLE class_course ( |
| @@ -153,17 +172,17 @@ CREATE TABLE class_course ( | |||
| 153 | attached_at BIGINT NULL, | 172 | attached_at BIGINT NULL, |
| 154 | -- The blueprint that attached this course; NULL = attached by hand, which | 173 | -- The blueprint that attached this course; NULL = attached by hand, which |
| 155 | -- keeps a hand-attached course unreachable by every blueprint sweep. | 174 | -- keeps a hand-attached course unreachable by every blueprint sweep. |
| 156 | - source TEXT NULL REFERENCES class_blueprint(grade) ON DELETE NO ACTION, | 175 | + source uuid NULL REFERENCES class_blueprint(id) ON DELETE NO ACTION, |
| 157 | CONSTRAINT class_course_class_course PRIMARY KEY (class, course) | 176 | CONSTRAINT class_course_class_course PRIMARY KEY (class, course) |
| 158 | ); | 177 | ); |
| 159 | 178 | ||
| 160 | -CREATE INDEX class_course_class ON class_course (class); | ||
| 161 | CREATE INDEX class_course_course ON class_course (course); | 179 | CREATE INDEX class_course_course ON class_course (course); |
| 162 | 180 | ||
| 163 | CREATE TABLE enrollment ( | 181 | CREATE TABLE enrollment ( |
| 164 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, | 182 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, |
| 165 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 183 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 166 | enrolled_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 184 | enrolled_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 185 | + created_at BIGINT NOT NULL, | ||
| 167 | -- The class that pumped this row; NULL when a human placed the student. | 186 | -- The class that pumped this row; NULL when a human placed the student. |
| 168 | source uuid NULL REFERENCES class_group(id) ON DELETE NO ACTION, | 187 | source uuid NULL REFERENCES class_group(id) ON DELETE NO ACTION, |
| 169 | CONSTRAINT enrollment_course_user PRIMARY KEY (course, app_user) | 188 | CONSTRAINT enrollment_course_user PRIMARY KEY (course, app_user) |
| @@ -193,6 +212,7 @@ CREATE TABLE attendance ( | |||
| 193 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 212 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 194 | status TEXT NOT NULL, | 213 | status TEXT NOT NULL, |
| 195 | marked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 214 | marked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 215 | + marked_at BIGINT NOT NULL, | ||
| 196 | CONSTRAINT attendance_event_user PRIMARY KEY (event, app_user) | 216 | CONSTRAINT attendance_event_user PRIMARY KEY (event, app_user) |
| 197 | ); | 217 | ); |
| 198 | 218 | ||
| @@ -202,6 +222,7 @@ CREATE TABLE registration ( | |||
| 202 | event uuid NOT NULL REFERENCES event(id) ON DELETE NO ACTION, | 222 | event uuid NOT NULL REFERENCES event(id) ON DELETE NO ACTION, |
| 203 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 223 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 204 | registered_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 224 | registered_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 225 | + created_at BIGINT NOT NULL, | ||
| 205 | CONSTRAINT registration_event_user PRIMARY KEY (event, app_user) | 226 | CONSTRAINT registration_event_user PRIMARY KEY (event, app_user) |
| 206 | ); | 227 | ); |
| 207 | 228 | ||
migrations/school/20260912000003_exams.sqlmodified+49 -20
| @@ -67,7 +67,11 @@ CREATE TABLE exam_question ( | |||
| 67 | -- question was inserted from, banked_as = the template most recently | 67 | -- question was inserted from, banked_as = the template most recently |
| 68 | -- minted by saving it into the bank. | 68 | -- minted by saving it into the bank. |
| 69 | from_bank uuid NULL REFERENCES bank_question(id) ON DELETE NO ACTION, | 69 | from_bank uuid NULL REFERENCES bank_question(id) ON DELETE NO ACTION, |
| 70 | - banked_as uuid NULL REFERENCES bank_question(id) ON DELETE NO ACTION | 70 | + banked_as uuid NULL REFERENCES bank_question(id) ON DELETE NO ACTION, |
| 71 | + -- The composite target of every (exam, question) foreign key below: an | ||
| 72 | + -- answer or image pair can only name a question that belongs to that | ||
| 73 | + -- exam, so the two columns can never disagree about the owner. | ||
| 74 | + CONSTRAINT exam_question_id_exam UNIQUE (id, exam) | ||
| 71 | ); | 75 | ); |
| 72 | 76 | ||
| 73 | CREATE INDEX exam_question_exam ON exam_question (exam); | 77 | CREATE INDEX exam_question_exam ON exam_question (exam); |
| @@ -87,8 +91,8 @@ CREATE TABLE bank_question_image ( | |||
| 87 | ); | 91 | ); |
| 88 | 92 | ||
| 89 | CREATE TABLE question_image ( | 93 | CREATE TABLE question_image ( |
| 90 | - exam uuid NOT NULL REFERENCES exam(id) ON DELETE NO ACTION, | 94 | + exam uuid NOT NULL, |
| 91 | - question uuid NOT NULL REFERENCES exam_question(id) ON DELETE NO ACTION, | 95 | + question uuid NOT NULL, |
| 92 | -- NULL = the question's own illustration; otherwise the choice's id. A | 96 | -- NULL = the question's own illustration; otherwise the choice's id. A |
| 93 | -- (question, slot) pair holds at most one picture, and a question holds | 97 | -- (question, slot) pair holds at most one picture, and a question holds |
| 94 | -- at most one illustration — NULLS NOT DISTINCT is what makes the NULL | 98 | -- at most one illustration — NULLS NOT DISTINCT is what makes the NULL |
| @@ -97,7 +101,11 @@ CREATE TABLE question_image ( | |||
| 97 | file TEXT NOT NULL, | 101 | file TEXT NOT NULL, |
| 98 | content_type TEXT NOT NULL, | 102 | content_type TEXT NOT NULL, |
| 99 | size BIGINT NOT NULL, | 103 | size BIGINT NOT NULL, |
| 100 | - CONSTRAINT question_image_question_slot UNIQUE NULLS NOT DISTINCT (question, slot) | 104 | + CONSTRAINT question_image_question_slot UNIQUE NULLS NOT DISTINCT (question, slot), |
| 105 | + -- One composite key instead of the old two single-column ones: the pair | ||
| 106 | + -- must resolve to one exam_question row, not two that could disagree. | ||
| 107 | + CONSTRAINT question_image_exam_question_fkey FOREIGN KEY (exam, question) | ||
| 108 | + REFERENCES exam_question (exam, id) ON DELETE NO ACTION | ||
| 101 | ); | 109 | ); |
| 102 | 110 | ||
| 103 | CREATE INDEX question_image_exam ON question_image (exam); | 111 | CREATE INDEX question_image_exam ON question_image (exam); |
| @@ -113,31 +121,33 @@ CREATE TABLE exam_attempt ( | |||
| 113 | CONSTRAINT exam_attempt_exam_user_seq PRIMARY KEY (exam, app_user, seq) | 121 | CONSTRAINT exam_attempt_exam_user_seq PRIMARY KEY (exam, app_user, seq) |
| 114 | ); | 122 | ); |
| 115 | 123 | ||
| 116 | -CREATE INDEX exam_attempt_exam ON exam_attempt (exam); | ||
| 117 | 124 | ||
| 118 | CREATE TABLE exam_answer ( | 125 | CREATE TABLE exam_answer ( |
| 119 | - exam uuid NOT NULL REFERENCES exam(id) ON DELETE NO ACTION, | 126 | + exam uuid NOT NULL, |
| 120 | - question uuid NOT NULL REFERENCES exam_question(id) ON DELETE NO ACTION, | 127 | + question uuid NOT NULL, |
| 121 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 128 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 122 | selected TEXT NULL, | 129 | selected TEXT NULL, |
| 123 | text TEXT NULL, | 130 | text TEXT NULL, |
| 124 | updated_at BIGINT NOT NULL, | 131 | updated_at BIGINT NOT NULL, |
| 125 | seq BIGINT NOT NULL DEFAULT 1, | 132 | seq BIGINT NOT NULL DEFAULT 1, |
| 126 | - CONSTRAINT exam_answer_question_user_seq PRIMARY KEY (question, app_user, seq) | 133 | + CONSTRAINT exam_answer_question_user_seq PRIMARY KEY (question, app_user, seq), |
| 134 | + CONSTRAINT exam_answer_exam_question_fkey FOREIGN KEY (exam, question) | ||
| 135 | + REFERENCES exam_question (exam, id) ON DELETE NO ACTION | ||
| 127 | ); | 136 | ); |
| 128 | 137 | ||
| 129 | CREATE INDEX exam_answer_exam_user ON exam_answer (exam, app_user); | 138 | CREATE INDEX exam_answer_exam_user ON exam_answer (exam, app_user); |
| 130 | -CREATE INDEX exam_answer_exam ON exam_answer (exam); | ||
| 131 | 139 | ||
| 132 | CREATE TABLE answer_image ( | 140 | CREATE TABLE answer_image ( |
| 133 | - exam uuid NOT NULL REFERENCES exam(id) ON DELETE NO ACTION, | 141 | + exam uuid NOT NULL, |
| 134 | - question uuid NOT NULL REFERENCES exam_question(id) ON DELETE NO ACTION, | 142 | + question uuid NOT NULL, |
| 135 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 143 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 136 | file TEXT NOT NULL, | 144 | file TEXT NOT NULL, |
| 137 | content_type TEXT NOT NULL, | 145 | content_type TEXT NOT NULL, |
| 138 | size BIGINT NOT NULL, | 146 | size BIGINT NOT NULL, |
| 139 | seq BIGINT NOT NULL DEFAULT 1, | 147 | seq BIGINT NOT NULL DEFAULT 1, |
| 140 | - CONSTRAINT answer_image_question_user_seq PRIMARY KEY (question, app_user, seq) | 148 | + CONSTRAINT answer_image_question_user_seq PRIMARY KEY (question, app_user, seq), |
| 149 | + CONSTRAINT answer_image_exam_question_fkey FOREIGN KEY (exam, question) | ||
| 150 | + REFERENCES exam_question (exam, id) ON DELETE NO ACTION | ||
| 141 | ); | 151 | ); |
| 142 | 152 | ||
| 143 | CREATE INDEX answer_image_exam ON answer_image (exam); | 153 | CREATE INDEX answer_image_exam ON answer_image (exam); |
| @@ -148,6 +158,9 @@ CREATE TABLE exam_result ( | |||
| 148 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 158 | app_user uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 149 | mark BIGINT NOT NULL, | 159 | mark BIGINT NOT NULL, |
| 150 | graded_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 160 | graded_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 161 | + -- When this mark was written (now-millis, stamped by the grader's own | ||
| 162 | + -- transaction); a regrade of the sitting overwrites it. | ||
| 163 | + graded_at BIGINT NOT NULL, | ||
| 151 | seq BIGINT NOT NULL DEFAULT 1, | 164 | seq BIGINT NOT NULL DEFAULT 1, |
| 152 | CONSTRAINT exam_result_exam_user_seq PRIMARY KEY (exam, app_user, seq) | 165 | CONSTRAINT exam_result_exam_user_seq PRIMARY KEY (exam, app_user, seq) |
| 153 | ); | 166 | ); |
| @@ -159,10 +172,7 @@ CREATE TABLE pool_question ( | |||
| 159 | body TEXT NOT NULL, | 172 | body TEXT NOT NULL, |
| 160 | status TEXT NOT NULL DEFAULT 'pending', | 173 | status TEXT NOT NULL DEFAULT 'pending', |
| 161 | asked_at BIGINT NOT NULL, | 174 | asked_at BIGINT NOT NULL, |
| 162 | - approved_by uuid NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 175 | + approved_by uuid NULL REFERENCES app_user(id) ON DELETE NO ACTION |
| 163 | - image_file TEXT NULL, | ||
| 164 | - image_content_type TEXT NULL, | ||
| 165 | - image_size BIGINT NULL | ||
| 166 | ); | 176 | ); |
| 167 | 177 | ||
| 168 | CREATE INDEX pool_question_status ON pool_question (status); | 178 | CREATE INDEX pool_question_status ON pool_question (status); |
| @@ -173,14 +183,31 @@ CREATE TABLE solution ( | |||
| 173 | question uuid NOT NULL REFERENCES pool_question(id) ON DELETE NO ACTION, | 183 | question uuid NOT NULL REFERENCES pool_question(id) ON DELETE NO ACTION, |
| 174 | author uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 184 | author uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 175 | body TEXT NOT NULL, | 185 | body TEXT NOT NULL, |
| 176 | - offered_at BIGINT NOT NULL, | 186 | + offered_at BIGINT NOT NULL |
| 177 | - image_file TEXT NULL, | ||
| 178 | - image_content_type TEXT NULL, | ||
| 179 | - image_size BIGINT NULL | ||
| 180 | ); | 187 | ); |
| 181 | 188 | ||
| 182 | CREATE INDEX solution_question ON solution (question); | 189 | CREATE INDEX solution_question ON solution (question); |
| 183 | 190 | ||
| 191 | +-- The pool photos, one row per question/solution — the single-slot spelling | ||
| 192 | +-- of question_image's child-table shape: the parent rows carry no image | ||
| 193 | +-- columns, the metadata lives here, and the bytes live on disk under the | ||
| 194 | +-- `file` name. The primary key IS the "one image" rule; a replace is a | ||
| 195 | +-- plain upsert. | ||
| 196 | +CREATE TABLE pool_question_image ( | ||
| 197 | + question uuid PRIMARY KEY REFERENCES pool_question(id) ON DELETE NO ACTION, | ||
| 198 | + file TEXT NOT NULL, | ||
| 199 | + content_type TEXT NOT NULL, | ||
| 200 | + size BIGINT NOT NULL | ||
| 201 | +); | ||
| 202 | + | ||
| 203 | +CREATE TABLE solution_image ( | ||
| 204 | + solution uuid PRIMARY KEY REFERENCES solution(id) ON DELETE NO ACTION, | ||
| 205 | + file TEXT NOT NULL, | ||
| 206 | + content_type TEXT NOT NULL, | ||
| 207 | + size BIGINT NOT NULL | ||
| 208 | +); | ||
| 209 | + | ||
| 210 | + | ||
| 184 | CREATE TABLE homework ( | 211 | CREATE TABLE homework ( |
| 185 | id uuid PRIMARY KEY, | 212 | id uuid PRIMARY KEY, |
| 186 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, | 213 | course uuid NOT NULL REFERENCES course(id) ON DELETE NO ACTION, |
| @@ -222,6 +249,8 @@ CREATE TABLE homework_submission ( | |||
| 222 | -- The on-time verdict credited at the first hand-in, never re-judged. | 249 | -- The on-time verdict credited at the first hand-in, never re-judged. |
| 223 | counted_on_time BOOLEAN NULL, | 250 | counted_on_time BOOLEAN NULL, |
| 224 | -- The grade that froze this submission; NULL while it is still open. | 251 | -- The grade that froze this submission; NULL while it is still open. |
| 252 | + -- NO ACTION orders the deletes: this row must be removed before the | ||
| 253 | + -- homework_result it points at. | ||
| 225 | graded_by_result uuid NULL REFERENCES homework_result(id) ON DELETE NO ACTION, | 254 | graded_by_result uuid NULL REFERENCES homework_result(id) ON DELETE NO ACTION, |
| 226 | -- Same deterministic pair as homework_result: one submission per | 255 | -- Same deterministic pair as homework_result: one submission per |
| 227 | -- (homework, user) by construction. | 256 | -- (homework, user) by construction. |
migrations/school/20260912000004_food_appointments_fees.sqlmodified+4 -2
| @@ -66,7 +66,10 @@ CREATE INDEX appointment_status ON appointment (status); | |||
| 66 | 66 | ||
| 67 | -- A published menu per day+slot. `date` is a calendar day as YYYY-MM-DD | 67 | -- A published menu per day+slot. `date` is a calendar day as YYYY-MM-DD |
| 68 | -- text (an equality key, not a timestamp); `slot` is snapshotted text, so | 68 | -- text (an equality key, not a timestamp); `slot` is snapshotted text, so |
| 69 | --- retiring a slot in settings never rewrites a past menu. | 69 | +-- retiring a slot in settings never rewrites a past menu. Deleting a menu |
| 70 | +-- sweeps its menu_dish and meal_attendance rows (the children go first — | ||
| 71 | +-- both FKs are NO ACTION) and never meal_booking: those rows carry no FK | ||
| 72 | +-- and survive the delete, auditable against the ledger lines they charged. | ||
| 70 | CREATE TABLE menu ( | 73 | CREATE TABLE menu ( |
| 71 | -- The {date}_{slot} derived key — it IS the URL segment — with the two | 74 | -- The {date}_{slot} derived key — it IS the URL segment — with the two |
| 72 | -- components kept as their own columns (the unique pair keeps the old | 75 | -- components kept as their own columns (the unique pair keeps the old |
| @@ -130,7 +133,6 @@ CREATE TABLE meal_booking ( | |||
| 130 | CONSTRAINT meal_booking_menu_student PRIMARY KEY (menu, student) | 133 | CONSTRAINT meal_booking_menu_student PRIMARY KEY (menu, student) |
| 131 | ); | 134 | ); |
| 132 | 135 | ||
| 133 | -CREATE INDEX meal_booking_menu ON meal_booking (menu); | ||
| 134 | CREATE INDEX meal_booking_student ON meal_booking (student); | 136 | CREATE INDEX meal_booking_student ON meal_booking (student); |
| 135 | 137 | ||
| 136 | CREATE TABLE meal_attendance ( | 138 | CREATE TABLE meal_attendance ( |
src/constant.rsmodified+2 -0
| @@ -864,7 +864,9 @@ pub const SETTINGS_TABLE: &str = "settings"; | |||
| 864 | pub const TERM_TABLE: &str = "term"; | 864 | pub const TERM_TABLE: &str = "term"; |
| 865 | pub const SUBJECT_TABLE: &str = "subject"; | 865 | pub const SUBJECT_TABLE: &str = "subject"; |
| 866 | pub const POOL_QUESTION_TABLE: &str = "pool_question"; | 866 | pub const POOL_QUESTION_TABLE: &str = "pool_question"; |
| 867 | +pub const POOL_QUESTION_IMAGE_TABLE: &str = "pool_question_image"; | ||
| 867 | pub const SOLUTION_TABLE: &str = "solution"; | 868 | pub const SOLUTION_TABLE: &str = "solution"; |
| 869 | +pub const SOLUTION_IMAGE_TABLE: &str = "solution_image"; | ||
| 868 | pub const HOMEWORK_TABLE: &str = "homework"; | 870 | pub const HOMEWORK_TABLE: &str = "homework"; |
| 869 | pub const HOMEWORK_SUBMISSION_TABLE: &str = "homework_submission"; | 871 | pub const HOMEWORK_SUBMISSION_TABLE: &str = "homework_submission"; |
| 870 | pub const HOMEWORK_FILE_TABLE: &str = "homework_file"; | 872 | pub const HOMEWORK_FILE_TABLE: &str = "homework_file"; |
src/db/answer_image.rsmodified+2 -2
| @@ -243,7 +243,7 @@ mod tests { | |||
| 243 | /// foreign key now. | 243 | /// foreign key now. |
| 244 | async fn a_student(db: &Database) -> UserId { | 244 | async fn a_student(db: &Database) -> UserId { |
| 245 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000a11a"); | 245 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000a11a"); |
| 246 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, 'a11a', 'x')") | 246 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, 'a11a', 0)") |
| 247 | .bind(user.uuid()) | 247 | .bind(user.uuid()) |
| 248 | .execute(db) | 248 | .execute(db) |
| 249 | .await | 249 | .await |
| @@ -327,7 +327,7 @@ mod tests { | |||
| 327 | 327 | ||
| 328 | // Another student's drawing for the same question/sitting is its own row. | 328 | // Another student's drawing for the same question/sitting is its own row. |
| 329 | let other = UserId::generate(); | 329 | let other = UserId::generate(); |
| 330 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, 'b22b', 'x')") | 330 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, 'b22b', 0)") |
| 331 | .bind(other.uuid()) | 331 | .bind(other.uuid()) |
| 332 | .execute(&db) | 332 | .execute(&db) |
| 333 | .await | 333 | .await |
src/db/attendance.rsmodified+8 -6
| @@ -7,6 +7,7 @@ use crate::database::{Database, tx_with_retry}; | |||
| 7 | use crate::db::page::PagedList; | 7 | use crate::db::page::PagedList; |
| 8 | use crate::domain::attendance::{Attendance, AttendanceStatus}; | 8 | use crate::domain::attendance::{Attendance, AttendanceStatus}; |
| 9 | use crate::domain::event::EventId; | 9 | use crate::domain::event::EventId; |
| 10 | +use crate::domain::timestamp::Timestamp; | ||
| 10 | use crate::domain::user::UserId; | 11 | use crate::domain::user::UserId; |
| 11 | use crate::error::AppError; | 12 | use crate::error::AppError; |
| 12 | use sqlx::query_as; | 13 | use sqlx::query_as; |
| @@ -53,15 +54,16 @@ pub async fn mark( | |||
| 53 | } | 54 | } |
| 54 | let row = query_as!( | 55 | let row = query_as!( |
| 55 | Attendance, | 56 | Attendance, |
| 56 | - "INSERT INTO attendance (event, app_user, status, marked_by) | 57 | + "INSERT INTO attendance (event, app_user, status, marked_by, marked_at) |
| 57 | - VALUES ($1, $2, $3, $4) | 58 | + VALUES ($1, $2, $3, $4, $5) |
| 58 | - ON CONFLICT (event, app_user) DO UPDATE SET status = $3, marked_by = $4 | 59 | + ON CONFLICT (event, app_user) DO UPDATE SET status = $3, marked_by = $4, marked_at = $5 |
| 59 | RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", \ | 60 | RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", \ |
| 60 | status AS \"status: AttendanceStatus\", marked_by AS \"marked_by: UserId\"", | 61 | status AS \"status: AttendanceStatus\", marked_by AS \"marked_by: UserId\"", |
| 61 | event.uuid(), | 62 | event.uuid(), |
| 62 | user.uuid(), | 63 | user.uuid(), |
| 63 | status.as_str(), | 64 | status.as_str(), |
| 64 | - marked_by.uuid() | 65 | + marked_by.uuid(), |
| 66 | + Timestamp::now().as_millis(), | ||
| 65 | ) | 67 | ) |
| 66 | .fetch_one(&mut *tx) | 68 | .fetch_one(&mut *tx) |
| 67 | .await?; | 69 | .await?; |
| @@ -148,8 +150,8 @@ mod tests { | |||
| 148 | async fn a_person(db: &Database, label: &str) -> UserId { | 150 | async fn a_person(db: &Database, label: &str) -> UserId { |
| 149 | let user = UserId::generate(); | 151 | let user = UserId::generate(); |
| 150 | sqlx::query( | 152 | sqlx::query( |
| 151 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 153 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 152 | - VALUES ($1, $2, 'x', 'teacher')", | 154 | + VALUES ($1, $2, 0, 'teacher')", |
| 153 | ) | 155 | ) |
| 154 | .bind(user.uuid()) | 156 | .bind(user.uuid()) |
| 155 | .bind(format!("{label}-{}", &user.key()[30..])) | 157 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/db/badge.rsmodified+4 -12
| @@ -125,20 +125,12 @@ mod tests { | |||
| 125 | use super::*; | 125 | use super::*; |
| 126 | use crate::constant::BADGE_AWARD_TABLE; | 126 | use crate::constant::BADGE_AWARD_TABLE; |
| 127 | use crate::database::init_test_db; | 127 | use crate::database::init_test_db; |
| 128 | - use crate::domain::user::{Password, Username}; | 128 | + use crate::domain::user::Username; |
| 129 | 129 | ||
| 130 | async fn a_user(username: &str, db: &Database) -> crate::domain::user::User { | 130 | async fn a_user(username: &str, db: &Database) -> crate::domain::user::User { |
| 131 | - crate::db::user::create( | 131 | + crate::db::user::create(db, Username::try_new(username).unwrap(), None) |
| 132 | - db, | 132 | + .await |
| 133 | - Username::try_new(username).unwrap(), | 133 | + .unwrap() |
| 134 | - Password::try_new("secret1") | ||
| 135 | - .unwrap() | ||
| 136 | - .hash_async() | ||
| 137 | - .await | ||
| 138 | - .unwrap(), | ||
| 139 | - ) | ||
| 140 | - .await | ||
| 141 | - .unwrap() | ||
| 142 | } | 134 | } |
| 143 | 135 | ||
| 144 | async fn count_awards(db: &Database, user: &UserId) -> i64 { | 136 | async fn count_awards(db: &Database, user: &UserId) -> i64 { |
src/db/bank_question.rsmodified+1 -1
| @@ -398,7 +398,7 @@ mod tests { | |||
| 398 | /// minted per call, so repeated calls are new people, not the same row. | 398 | /// minted per call, so repeated calls are new people, not the same row. |
| 399 | async fn a_person(db: &Database, label: &str) -> UserId { | 399 | async fn a_person(db: &Database, label: &str) -> UserId { |
| 400 | let user = UserId::generate(); | 400 | let user = UserId::generate(); |
| 401 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 401 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 402 | .bind(user.uuid()) | 402 | .bind(user.uuid()) |
| 403 | .bind(format!("{label}-{}", &user.key()[30..])) | 403 | .bind(format!("{label}-{}", &user.key()[30..])) |
| 404 | .execute(db) | 404 | .execute(db) |
src/db/bank_question_image.rsmodified+2 -2
| @@ -196,8 +196,8 @@ mod tests { | |||
| 196 | let id = BankQuestionId::generate(); | 196 | let id = BankQuestionId::generate(); |
| 197 | let owner = crate::domain::user::UserId::generate(); | 197 | let owner = crate::domain::user::UserId::generate(); |
| 198 | sqlx::query( | 198 | sqlx::query( |
| 199 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 199 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 200 | - VALUES ($1, $2, 'x', 'teacher')", | 200 | + VALUES ($1, $2, 0, 'teacher')", |
| 201 | ) | 201 | ) |
| 202 | .bind(owner.uuid()) | 202 | .bind(owner.uuid()) |
| 203 | .bind(format!("bqi-owner-{}", &owner.key()[30..])) | 203 | .bind(format!("bqi-owner-{}", &owner.key()[30..])) |
src/db/builder.rsmodified+2 -1
| @@ -46,10 +46,11 @@ pub async fn read(db: &Database, id: &BuilderId) -> Result<Option<Builder>, AppE | |||
| 46 | /// constraint stands guard regardless. | 46 | /// constraint stands guard regardless. |
| 47 | pub async fn create(db: &Database, builder: Builder) -> Result<(), AppError> { | 47 | pub async fn create(db: &Database, builder: Builder) -> Result<(), AppError> { |
| 48 | sqlx::query!( | 48 | sqlx::query!( |
| 49 | - "INSERT INTO builder (id, username, password_hash) VALUES ($1, $2, $3)", | 49 | + "INSERT INTO builder (id, username, password_hash, created_at) VALUES ($1, $2, $3, $4)", |
| 50 | builder.id.uuid(), | 50 | builder.id.uuid(), |
| 51 | builder.username.as_str(), | 51 | builder.username.as_str(), |
| 52 | builder.password_hash.as_str(), | 52 | builder.password_hash.as_str(), |
| 53 | + Timestamp::now().as_millis(), | ||
| 53 | ) | 54 | ) |
| 54 | .execute(db) | 55 | .execute(db) |
| 55 | .await?; | 56 | .await?; |
src/db/chatbot_message.rsmodified+2 -2
| @@ -324,8 +324,8 @@ mod tests { | |||
| 324 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cafe"); | 324 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cafe"); |
| 325 | let thread = ChatbotThreadId::from_key("019732e3-7b00-7000-8000-00000000beef"); | 325 | let thread = ChatbotThreadId::from_key("019732e3-7b00-7000-8000-00000000beef"); |
| 326 | sqlx::query( | 326 | sqlx::query( |
| 327 | - "INSERT INTO app_user (id, username, password_hash) \ | 327 | + "INSERT INTO app_user (id, username, created_at) \ |
| 328 | - VALUES ($1, 'chat-fixture', 'x')", | 328 | + VALUES ($1, 'chat-fixture', 0)", |
| 329 | ) | 329 | ) |
| 330 | .bind(user.uuid()) | 330 | .bind(user.uuid()) |
| 331 | .execute(&db) | 331 | .execute(&db) |
src/db/chatbot_thread.rsmodified+1 -1
| @@ -224,7 +224,7 @@ mod tests { | |||
| 224 | 224 | ||
| 225 | async fn a_user_capped_at(threads: i64) -> (Database, crate::database::TestDatabases) { | 225 | async fn a_user_capped_at(threads: i64) -> (Database, crate::database::TestDatabases) { |
| 226 | let (db, leases) = crate::database::init_test_db().await; | 226 | let (db, leases) = crate::database::init_test_db().await; |
| 227 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, 'u', 'x')") | 227 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, 'u', 0)") |
| 228 | .bind(UserId::from_key(U).uuid()) | 228 | .bind(UserId::from_key(U).uuid()) |
| 229 | .execute(&db) | 229 | .execute(&db) |
| 230 | .await | 230 | .await |
src/db/class_blueprint.rsmodified+16 -7
| @@ -13,6 +13,7 @@ use crate::db::page::PagedList; | |||
| 13 | use crate::domain::class_blueprint::{ClassBlueprint, ClassBlueprintId}; | 13 | use crate::domain::class_blueprint::{ClassBlueprint, ClassBlueprintId}; |
| 14 | use crate::domain::class_group::{ClassGrade, ClassGroupId}; | 14 | use crate::domain::class_group::{ClassGrade, ClassGroupId}; |
| 15 | use crate::domain::course::CourseId; | 15 | use crate::domain::course::CourseId; |
| 16 | +use crate::domain::monotonic_id::next_uuid; | ||
| 16 | use crate::domain::user::UserId; | 17 | use crate::domain::user::UserId; |
| 17 | use crate::error::{AppError, ValidationError}; | 18 | use crate::error::{AppError, ValidationError}; |
| 18 | 19 | ||
| @@ -67,9 +68,11 @@ fn no_such_course() -> AppError { | |||
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | /// Write the blueprint's row. A second one for the same grade is a 409 the | 70 | /// Write the blueprint's row. A second one for the same grade is a 409 the |
| 70 | -/// store itself decides — the grade is the primary key, so the duplicate is | 71 | +/// store itself decides — the grade carries a UNIQUE constraint, so the |
| 71 | -/// seen rather than raced (`23505` on `class_blueprint_pkey`, mapped right | 72 | +/// duplicate is seen rather than raced (`23505` on |
| 72 | -/// here: a duplicate is a decision, never a retry). | 73 | +/// `class_blueprint_grade_key`, mapped right here: a duplicate is a |
| 74 | +/// decision, never a retry). The surrogate `id` is minted here and never | ||
| 75 | +/// read back: the grade label stays the only identity the API speaks. | ||
| 73 | pub async fn create( | 76 | pub async fn create( |
| 74 | db: &Database, | 77 | db: &Database, |
| 75 | creator: &UserId, | 78 | creator: &UserId, |
| @@ -83,11 +86,13 @@ pub async fn create( | |||
| 83 | creator: *creator, | 86 | creator: *creator, |
| 84 | }; | 87 | }; |
| 85 | let creator = *creator; | 88 | let creator = *creator; |
| 89 | + let id = next_uuid(); | ||
| 86 | tx_with_retry(db, false, async move |tx| { | 90 | tx_with_retry(db, false, async move |tx| { |
| 87 | courses_alive(tx, &courses).await?; | 91 | courses_alive(tx, &courses).await?; |
| 88 | let inserted = sqlx::query!( | 92 | let inserted = sqlx::query!( |
| 89 | - r#"INSERT INTO class_blueprint (grade, courses, creator) | 93 | + r#"INSERT INTO class_blueprint (id, grade, courses, creator) |
| 90 | - VALUES ($1, $2, $3)"#, | 94 | + VALUES ($1, $2, $3, $4)"#, |
| 95 | + id, | ||
| 91 | grade as _, | 96 | grade as _, |
| 92 | courses as _, | 97 | courses as _, |
| 93 | creator as _ | 98 | creator as _ |
| @@ -96,7 +101,7 @@ pub async fn create( | |||
| 96 | .await; | 101 | .await; |
| 97 | match inserted { | 102 | match inserted { |
| 98 | Ok(_) => Ok(blueprint.clone()), | 103 | Ok(_) => Ok(blueprint.clone()), |
| 99 | - Err(e) if unique_violation(&e) == Some("class_blueprint_pkey") => Err( | 104 | + Err(e) if unique_violation(&e) == Some("class_blueprint_grade_key") => Err( |
| 100 | AppError::Conflict("a blueprint already exists for that grade"), | 105 | AppError::Conflict("a blueprint already exists for that grade"), |
| 101 | ), | 106 | ), |
| 102 | Err(e) => Err(e.into()), | 107 | Err(e) => Err(e.into()), |
| @@ -315,6 +320,9 @@ pub async fn prune( | |||
| 315 | /// it. The rows are read rather than derived from the classes at this grade: | 320 | /// it. The rows are read rather than derived from the classes at this grade: |
| 316 | /// a class whose grade was edited after the pump still carries this | 321 | /// a class whose grade was edited after the pump still carries this |
| 317 | /// blueprint's attachments, and only the tag can find it. | 322 | /// blueprint's attachments, and only the tag can find it. |
| 323 | +/// | ||
| 324 | +/// The stored tag is the blueprint's surrogate uuid, not the grade label the | ||
| 325 | +/// API speaks — the query translates the label to it. | ||
| 318 | pub async fn sourced_links( | 326 | pub async fn sourced_links( |
| 319 | db: &Database, | 327 | db: &Database, |
| 320 | id: &ClassBlueprintId, | 328 | id: &ClassBlueprintId, |
| @@ -324,7 +332,8 @@ pub async fn sourced_links( | |||
| 324 | let rows = sqlx::query!( | 332 | let rows = sqlx::query!( |
| 325 | r#"SELECT class AS "class: ClassGroupId", course AS "course: CourseId" | 333 | r#"SELECT class AS "class: ClassGroupId", course AS "course: CourseId" |
| 326 | FROM class_course | 334 | FROM class_course |
| 327 | - WHERE source = $1 AND course <> ALL($2)"#, | 335 | + WHERE source = (SELECT id FROM class_blueprint WHERE grade = $1) |
| 336 | + AND course <> ALL($2)"#, | ||
| 328 | id as _, | 337 | id as _, |
| 329 | keep as _ | 338 | keep as _ |
| 330 | ) | 339 | ) |
src/db/class_course.rsmodified+10 -1
| @@ -49,8 +49,17 @@ pub async fn list_for_class( | |||
| 49 | limit: Option<i64>, | 49 | limit: Option<i64>, |
| 50 | offset: i64, | 50 | offset: i64, |
| 51 | ) -> Result<(Vec<ClassCourse>, i64), AppError> { | 51 | ) -> Result<(Vec<ClassCourse>, i64), AppError> { |
| 52 | + // The stored `source` is the blueprint's surrogate uuid; the domain row | ||
| 53 | + // speaks the grade label, so the projection joins it back (a hand attach, | ||
| 54 | + // source NULL, survives the LEFT JOIN as NULL). | ||
| 52 | PagedList::new( | 55 | PagedList::new( |
| 53 | - format!("{CLASS_COURSE_TABLE} WHERE class = $1"), | 56 | + format!( |
| 57 | + "(SELECT cc.class, cc.course, cc.attached_by, cc.attached_at, \ | ||
| 58 | + b.grade AS source \ | ||
| 59 | + FROM {CLASS_COURSE_TABLE} cc \ | ||
| 60 | + LEFT JOIN class_blueprint b ON b.id = cc.source) \ | ||
| 61 | + AS {CLASS_COURSE_TABLE} WHERE class = $1" | ||
| 62 | + ), | ||
| 54 | "ORDER BY attached_at DESC NULLS LAST, class DESC, course DESC", | 63 | "ORDER BY attached_at DESC NULLS LAST, class DESC, course DESC", |
| 55 | ) | 64 | ) |
| 56 | .bind(class.uuid()) | 65 | .bind(class.uuid()) |
src/db/class_group.rsmodified+2 -2
| @@ -313,8 +313,8 @@ mod tests { | |||
| 313 | // The username is unique: a second call for the same name must adopt | 313 | // The username is unique: a second call for the same name must adopt |
| 314 | // the existing row, not collide with it. | 314 | // the existing row, not collide with it. |
| 315 | sqlx::query( | 315 | sqlx::query( |
| 316 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 316 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 317 | - VALUES ($1, $2, 'x', 'teacher') ON CONFLICT DO NOTHING", | 317 | + VALUES ($1, $2, 0, 'teacher') ON CONFLICT DO NOTHING", |
| 318 | ) | 318 | ) |
| 319 | .bind(UserId::generate().uuid()) | 319 | .bind(UserId::generate().uuid()) |
| 320 | .bind(username) | 320 | .bind(username) |
src/db/class_member.rsmodified+2 -2
| @@ -62,8 +62,8 @@ pub(crate) mod tests { | |||
| 62 | /// fixture actors are rows, not fabricated ids. | 62 | /// fixture actors are rows, not fabricated ids. |
| 63 | pub(crate) async fn fixture_user(db: &Database, username: &str) -> UserId { | 63 | pub(crate) async fn fixture_user(db: &Database, username: &str) -> UserId { |
| 64 | sqlx::query( | 64 | sqlx::query( |
| 65 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 65 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 66 | - VALUES ($1, $2, 'x', 'student') ON CONFLICT DO NOTHING", | 66 | + VALUES ($1, $2, 0, 'student') ON CONFLICT DO NOTHING", |
| 67 | ) | 67 | ) |
| 68 | .bind(crate::domain::user::UserId::generate().uuid()) | 68 | .bind(crate::domain::user::UserId::generate().uuid()) |
| 69 | .bind(username) | 69 | .bind(username) |
src/db/class_pump.rsmodified+34 -23
| @@ -242,6 +242,10 @@ fn refusal_of<T>(early: Early) -> Attached<T> { | |||
| 242 | /// is the weakest strength that blocks the delete, so two sourced attaches | 242 | /// is the weakest strength that blocks the delete, so two sourced attaches |
| 243 | /// still run concurrently, exactly as they did under the old shared read | 243 | /// still run concurrently, exactly as they did under the old shared read |
| 244 | /// lease. | 244 | /// lease. |
| 245 | +/// | ||
| 246 | +/// The same locked read resolves the surrogate `id` the link row will | ||
| 247 | +/// store: the stored tag is that uuid, not the grade label the API | ||
| 248 | +/// speaks, and it rides out of this gate to the insert below. | ||
| 245 | /// 3. **Pivot** — the member axis takes the [`cap` role-claim | 249 | /// 3. **Pivot** — the member axis takes the [`cap` role-claim |
| 246 | /// recipe](crate::db::cap)'s `FOR NO KEY UPDATE` handshake on the user row: | 250 | /// recipe](crate::db::cap)'s `FOR NO KEY UPDATE` handshake on the user row: |
| 247 | /// a role change away from `student` sweeps this membership, and demotion | 251 | /// a role change away from `student` sweeps this membership, and demotion |
| @@ -258,7 +262,7 @@ async fn early_verdicts( | |||
| 258 | axis: Axis, | 262 | axis: Axis, |
| 259 | pivot: Pivot<'_>, | 263 | pivot: Pivot<'_>, |
| 260 | source: Option<&ClassBlueprintId>, | 264 | source: Option<&ClassBlueprintId>, |
| 261 | -) -> Result<Option<Early>, AppError> { | 265 | +) -> Result<(Option<Early>, Option<uuid::Uuid>), AppError> { |
| 262 | let held = match pivot { | 266 | let held = match pivot { |
| 263 | Pivot::User(user) => sqlx::query_scalar!( | 267 | Pivot::User(user) => sqlx::query_scalar!( |
| 264 | r#"SELECT 1 AS "one" FROM class_member WHERE class = $1 AND app_user = $2"#, | 268 | r#"SELECT 1 AS "one" FROM class_member WHERE class = $1 AND app_user = $2"#, |
| @@ -278,19 +282,23 @@ async fn early_verdicts( | |||
| 278 | .is_some(), | 282 | .is_some(), |
| 279 | }; | 283 | }; |
| 280 | if held { | 284 | if held { |
| 281 | - return Ok(Some(Early::Duplicate)); | 285 | + return Ok((Some(Early::Duplicate), None)); |
| 282 | } | 286 | } |
| 287 | + // The lock and the resolution are one read: the stored `source` is the | ||
| 288 | + // blueprint's surrogate uuid, and the row this read returns it from is | ||
| 289 | + // the very row the KEY SHARE lock holds against the blueprint's delete. | ||
| 290 | + let mut source_id = None; | ||
| 283 | if let Some(source) = source { | 291 | if let Some(source) = source { |
| 284 | - let alive = sqlx::query_scalar!( | 292 | + let locked = sqlx::query_scalar!( |
| 285 | - r#"SELECT 1 AS "one" FROM class_blueprint WHERE grade = $1 FOR KEY SHARE"#, | 293 | + r#"SELECT id FROM class_blueprint WHERE grade = $1 FOR KEY SHARE"#, |
| 286 | source as _ | 294 | source as _ |
| 287 | ) | 295 | ) |
| 288 | .fetch_optional(&mut *tx) | 296 | .fetch_optional(&mut *tx) |
| 289 | - .await? | 297 | + .await?; |
| 290 | - .is_some(); | 298 | + let Some(id) = locked else { |
| 291 | - if !alive { | 299 | + return Ok((Some(Early::SourceGone), None)); |
| 292 | - return Ok(Some(Early::SourceGone)); | 300 | + }; |
| 293 | - } | 301 | + source_id = Some(id); |
| 294 | } | 302 | } |
| 295 | match pivot { | 303 | match pivot { |
| 296 | Pivot::User(user) => { | 304 | Pivot::User(user) => { |
| @@ -301,7 +309,7 @@ async fn early_verdicts( | |||
| 301 | .fetch_optional(&mut *tx) | 309 | .fetch_optional(&mut *tx) |
| 302 | .await?; | 310 | .await?; |
| 303 | if row.map(|row| row.role) != Some(Role::Student) { | 311 | if row.map(|row| row.role) != Some(Role::Student) { |
| 304 | - return Ok(Some(Early::PivotGone)); | 312 | + return Ok((Some(Early::PivotGone), None)); |
| 305 | } | 313 | } |
| 306 | } | 314 | } |
| 307 | Pivot::Course(course) => { | 315 | Pivot::Course(course) => { |
| @@ -313,7 +321,7 @@ async fn early_verdicts( | |||
| 313 | .await? | 321 | .await? |
| 314 | .is_some(); | 322 | .is_some(); |
| 315 | if !alive { | 323 | if !alive { |
| 316 | - return Ok(Some(Early::PivotGone)); | 324 | + return Ok((Some(Early::PivotGone), None)); |
| 317 | } | 325 | } |
| 318 | } | 326 | } |
| 319 | } | 327 | } |
| @@ -339,7 +347,7 @@ async fn early_verdicts( | |||
| 339 | .await? | 347 | .await? |
| 340 | .is_some(), | 348 | .is_some(), |
| 341 | }; | 349 | }; |
| 342 | - Ok(over.then_some(Early::Overloaded)) | 350 | + Ok((over.then_some(Early::Overloaded), source_id)) |
| 343 | } | 351 | } |
| 344 | 352 | ||
| 345 | /// Write the member link and enroll the student into every course the class is | 353 | /// Write the member link and enroll the student into every course the class is |
| @@ -368,9 +376,9 @@ pub(crate) async fn add_member( | |||
| 368 | let class = class.clone(); | 376 | let class = class.clone(); |
| 369 | let (user, by) = (*user, *by); | 377 | let (user, by) = (*user, *by); |
| 370 | let outcome = tx_with_retry(db, false, async move |tx| { | 378 | let outcome = tx_with_retry(db, false, async move |tx| { |
| 371 | - if let Some(early) = | 379 | + let (early, _) = |
| 372 | - early_verdicts(tx, &class, Axis::Member, Pivot::User(&user), None).await? | 380 | + early_verdicts(tx, &class, Axis::Member, Pivot::User(&user), None).await?; |
| 373 | - { | 381 | + if let Some(early) = early { |
| 374 | return Ok(refusal_of(early)); | 382 | return Ok(refusal_of(early)); |
| 375 | } | 383 | } |
| 376 | // The claim and the link are one statement (the cap recipe's CTE): the | 384 | // The claim and the link are one statement (the cap recipe's CTE): the |
| @@ -463,15 +471,15 @@ pub(crate) async fn attach_course( | |||
| 463 | let by = *by; | 471 | let by = *by; |
| 464 | let source = source.cloned(); | 472 | let source = source.cloned(); |
| 465 | let outcome = tx_with_retry(db, false, async move |tx| { | 473 | let outcome = tx_with_retry(db, false, async move |tx| { |
| 466 | - if let Some(early) = early_verdicts( | 474 | + let (early, source_id) = early_verdicts( |
| 467 | tx, | 475 | tx, |
| 468 | &class, | 476 | &class, |
| 469 | Axis::Course, | 477 | Axis::Course, |
| 470 | Pivot::Course(&course), | 478 | Pivot::Course(&course), |
| 471 | source.as_ref(), | 479 | source.as_ref(), |
| 472 | ) | 480 | ) |
| 473 | - .await? | 481 | + .await?; |
| 474 | - { | 482 | + if let Some(early) = early { |
| 475 | return Ok(refusal_of(early)); | 483 | return Ok(refusal_of(early)); |
| 476 | } | 484 | } |
| 477 | let inserted = match sqlx::query_scalar!( | 485 | let inserted = match sqlx::query_scalar!( |
| @@ -487,7 +495,7 @@ pub(crate) async fn attach_course( | |||
| 487 | course as _, | 495 | course as _, |
| 488 | by as _, | 496 | by as _, |
| 489 | attached_at as _, | 497 | attached_at as _, |
| 490 | - source as _ | 498 | + source_id, |
| 491 | ) | 499 | ) |
| 492 | .fetch_optional(&mut *tx) | 500 | .fetch_optional(&mut *tx) |
| 493 | .await | 501 | .await |
| @@ -577,6 +585,7 @@ async fn enroll_pairs( | |||
| 577 | pairs: impl Iterator<Item = (uuid::Uuid, uuid::Uuid)>, | 585 | pairs: impl Iterator<Item = (uuid::Uuid, uuid::Uuid)>, |
| 578 | by: &UserId, | 586 | by: &UserId, |
| 579 | ) -> Result<(), AppError> { | 587 | ) -> Result<(), AppError> { |
| 588 | + let now = Timestamp::now(); | ||
| 580 | for (course, user) in pairs { | 589 | for (course, user) in pairs { |
| 581 | let held = sqlx::query_scalar!( | 590 | let held = sqlx::query_scalar!( |
| 582 | r#"SELECT 1 AS "one" FROM enrollment WHERE course = $1 AND app_user = $2"#, | 591 | r#"SELECT 1 AS "one" FROM enrollment WHERE course = $1 AND app_user = $2"#, |
| @@ -610,14 +619,15 @@ async fn enroll_pairs( | |||
| 610 | return Err(AppError::Internal(format!("{COURSE_FULL_MARK}{course}"))); | 619 | return Err(AppError::Internal(format!("{COURSE_FULL_MARK}{course}"))); |
| 611 | } | 620 | } |
| 612 | let wrote = sqlx::query_scalar!( | 621 | let wrote = sqlx::query_scalar!( |
| 613 | - r#"INSERT INTO enrollment (course, app_user, enrolled_by, source) | 622 | + r#"INSERT INTO enrollment (course, app_user, enrolled_by, source, created_at) |
| 614 | - VALUES ($1, $2, $3, $4) | 623 | + VALUES ($1, $2, $3, $4, $5) |
| 615 | ON CONFLICT (course, app_user) DO NOTHING | 624 | ON CONFLICT (course, app_user) DO NOTHING |
| 616 | RETURNING 1 AS "one""#, | 625 | RETURNING 1 AS "one""#, |
| 617 | course, | 626 | course, |
| 618 | user, | 627 | user, |
| 619 | by as _, | 628 | by as _, |
| 620 | - class as _ | 629 | + class as _, |
| 630 | + now.as_millis() | ||
| 621 | ) | 631 | ) |
| 622 | .fetch_optional(&mut *tx) | 632 | .fetch_optional(&mut *tx) |
| 623 | .await; | 633 | .await; |
| @@ -757,7 +767,8 @@ pub(crate) async fn detach_course( | |||
| 757 | let gone = match &source { | 767 | let gone = match &source { |
| 758 | Some(source) => { | 768 | Some(source) => { |
| 759 | sqlx::query_scalar!( | 769 | sqlx::query_scalar!( |
| 760 | - r#"DELETE FROM class_course WHERE class = $1 AND course = $2 AND source = $3 | 770 | + r#"DELETE FROM class_course WHERE class = $1 AND course = $2 |
| 771 | + AND source = (SELECT id FROM class_blueprint WHERE grade = $3) | ||
| 761 | RETURNING 1 AS "one""#, | 772 | RETURNING 1 AS "one""#, |
| 762 | class as _, | 773 | class as _, |
| 763 | course as _, | 774 | course as _, |
src/db/course.rsmodified+4 -4
| @@ -577,8 +577,8 @@ pub(crate) async fn a_test_course(db: &Database) -> CourseId { | |||
| 577 | // repeated calls are new people, not the same one. | 577 | // repeated calls are new people, not the same one. |
| 578 | let creator = UserId::generate(); | 578 | let creator = UserId::generate(); |
| 579 | sqlx::query( | 579 | sqlx::query( |
| 580 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 580 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 581 | - VALUES ($1, $2, 'x', 'teacher')", | 581 | + VALUES ($1, $2, 0, 'teacher')", |
| 582 | ) | 582 | ) |
| 583 | .bind(creator.uuid()) | 583 | .bind(creator.uuid()) |
| 584 | .bind(format!("course-fixture-{}", &creator.key()[30..])) | 584 | .bind(format!("course-fixture-{}", &creator.key()[30..])) |
| @@ -717,8 +717,8 @@ mod tests { | |||
| 717 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 717 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 718 | let user = UserId::generate(); | 718 | let user = UserId::generate(); |
| 719 | sqlx::query( | 719 | sqlx::query( |
| 720 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 720 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 721 | - VALUES ($1, $2, 'x', $3)", | 721 | + VALUES ($1, $2, 0, $3)", |
| 722 | ) | 722 | ) |
| 723 | .bind(user.uuid()) | 723 | .bind(user.uuid()) |
| 724 | .bind(format!("{label}-{}", &user.key()[30..])) | 724 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/db/course_note_file.rsmodified+1 -1
| @@ -168,7 +168,7 @@ mod tests { | |||
| 168 | /// A real `app_user` row: authors and creators are foreign keys now. | 168 | /// A real `app_user` row: authors and creators are foreign keys now. |
| 169 | async fn a_person(db: &Database) -> crate::domain::user::UserId { | 169 | async fn a_person(db: &Database) -> crate::domain::user::UserId { |
| 170 | let user = crate::domain::user::UserId::generate(); | 170 | let user = crate::domain::user::UserId::generate(); |
| 171 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 171 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 172 | .bind(user.uuid()) | 172 | .bind(user.uuid()) |
| 173 | .bind(format!("cnf-{}", &user.key()[30..])) | 173 | .bind(format!("cnf-{}", &user.key()[30..])) |
| 174 | .execute(db) | 174 | .execute(db) |
src/db/course_session.rsmodified+2 -2
| @@ -180,8 +180,8 @@ mod tests { | |||
| 180 | // The creator is a foreign key now: a real `app_user` row. | 180 | // The creator is a foreign key now: a real `app_user` row. |
| 181 | let creator = UserId::generate(); | 181 | let creator = UserId::generate(); |
| 182 | sqlx::query( | 182 | sqlx::query( |
| 183 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 183 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 184 | - VALUES ($1, $2, 'x', 'teacher')", | 184 | + VALUES ($1, $2, 0, 'teacher')", |
| 185 | ) | 185 | ) |
| 186 | .bind(creator.uuid()) | 186 | .bind(creator.uuid()) |
| 187 | .bind(format!("session-race-{}", &creator.key()[30..])) | 187 | .bind(format!("session-race-{}", &creator.key()[30..])) |
src/db/enrollment.rsmodified+9 -6
| @@ -11,6 +11,7 @@ use crate::domain::class_group::ClassGroupId; | |||
| 11 | use crate::domain::course::CourseId; | 11 | use crate::domain::course::CourseId; |
| 12 | use crate::domain::enrollment::Enrollment; | 12 | use crate::domain::enrollment::Enrollment; |
| 13 | use crate::domain::role::Role; | 13 | use crate::domain::role::Role; |
| 14 | +use crate::domain::timestamp::Timestamp; | ||
| 14 | use crate::domain::user::UserId; | 15 | use crate::domain::user::UserId; |
| 15 | use crate::error::{AppError, ValidationError}; | 16 | use crate::error::{AppError, ValidationError}; |
| 16 | 17 | ||
| @@ -62,6 +63,7 @@ pub async fn enroll( | |||
| 62 | } | 63 | } |
| 63 | let course_id = course.clone(); | 64 | let course_id = course.clone(); |
| 64 | let (user_id, enrolled_by_id) = (*user, *enrolled_by); | 65 | let (user_id, enrolled_by_id) = (*user, *enrolled_by); |
| 66 | + let created_at = Timestamp::now(); | ||
| 65 | let verdict = tx_with_retry(db, false, async move |tx| { | 67 | let verdict = tx_with_retry(db, false, async move |tx| { |
| 66 | // The duplicate gate rides ahead of the role check, so "you are | 68 | // The duplicate gate rides ahead of the role check, so "you are |
| 67 | // already in" still outranks everything. | 69 | // already in" still outranks everything. |
| @@ -99,14 +101,15 @@ pub async fn enroll( | |||
| 99 | WHERE id = $1 | 101 | WHERE id = $1 |
| 100 | AND enrollment_count < COALESCE(capacity, $2) | 102 | AND enrollment_count < COALESCE(capacity, $2) |
| 101 | RETURNING 1) | 103 | RETURNING 1) |
| 102 | - INSERT INTO enrollment (course, app_user, enrolled_by, source) | 104 | + INSERT INTO enrollment (course, app_user, enrolled_by, source, created_at) |
| 103 | - SELECT $1, $3, $4, NULL WHERE EXISTS (SELECT 1 FROM seat) | 105 | + SELECT $1, $3, $4, NULL, $5 WHERE EXISTS (SELECT 1 FROM seat) |
| 104 | RETURNING course AS "course: CourseId", app_user AS "user: UserId", | 106 | RETURNING course AS "course: CourseId", app_user AS "user: UserId", |
| 105 | enrolled_by AS "enrolled_by: UserId", source AS "source: ClassGroupId""#, | 107 | enrolled_by AS "enrolled_by: UserId", source AS "source: ClassGroupId""#, |
| 106 | course_id.uuid(), | 108 | course_id.uuid(), |
| 107 | cap::UNLIMITED, | 109 | cap::UNLIMITED, |
| 108 | user_id.uuid(), | 110 | user_id.uuid(), |
| 109 | enrolled_by_id.uuid(), | 111 | enrolled_by_id.uuid(), |
| 112 | + created_at as _, | ||
| 110 | ) | 113 | ) |
| 111 | .fetch_optional(&mut *tx) | 114 | .fetch_optional(&mut *tx) |
| 112 | .await?; | 115 | .await?; |
| @@ -274,8 +277,8 @@ mod tests { | |||
| 274 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 277 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 275 | let user = UserId::generate(); | 278 | let user = UserId::generate(); |
| 276 | sqlx::query( | 279 | sqlx::query( |
| 277 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 280 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 278 | - VALUES ($1, $2, 'x', $3)", | 281 | + VALUES ($1, $2, 0, $3)", |
| 279 | ) | 282 | ) |
| 280 | .bind(user.uuid()) | 283 | .bind(user.uuid()) |
| 281 | .bind(format!("{label}-{}", &user.key()[30..])) | 284 | .bind(format!("{label}-{}", &user.key()[30..])) |
| @@ -301,8 +304,8 @@ mod tests { | |||
| 301 | .bind({ | 304 | .bind({ |
| 302 | let mgr = UserId::generate(); | 305 | let mgr = UserId::generate(); |
| 303 | sqlx::query( | 306 | sqlx::query( |
| 304 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 307 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 305 | - VALUES ($1, 'enroll-fixture', 'x', 'manager')", | 308 | + VALUES ($1, 'enroll-fixture', 0, 'manager')", |
| 306 | ) | 309 | ) |
| 307 | .bind(mgr.uuid()) | 310 | .bind(mgr.uuid()) |
| 308 | .execute(&db) | 311 | .execute(&db) |
src/db/event.rsmodified+2 -2
| @@ -296,8 +296,8 @@ mod tests { | |||
| 296 | async fn a_person(db: &Database, label: &str) -> UserId { | 296 | async fn a_person(db: &Database, label: &str) -> UserId { |
| 297 | let user = UserId::generate(); | 297 | let user = UserId::generate(); |
| 298 | sqlx::query( | 298 | sqlx::query( |
| 299 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 299 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 300 | - VALUES ($1, $2, 'x', 'teacher')", | 300 | + VALUES ($1, $2, 0, 'teacher')", |
| 301 | ) | 301 | ) |
| 302 | .bind(user.uuid()) | 302 | .bind(user.uuid()) |
| 303 | .bind(format!("{label}-{}", &user.key()[30..])) | 303 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/db/exam.rsmodified+6 -6
| @@ -486,8 +486,8 @@ pub(crate) async fn published_exam(db: &Database) -> Exam { | |||
| 486 | // The creator is a foreign key now: a real `app_user` row, minted per call. | 486 | // The creator is a foreign key now: a real `app_user` row, minted per call. |
| 487 | let creator = UserId::generate(); | 487 | let creator = UserId::generate(); |
| 488 | sqlx::query( | 488 | sqlx::query( |
| 489 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 489 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 490 | - VALUES ($1, $2, 'x', 'teacher')", | 490 | + VALUES ($1, $2, 0, 'teacher')", |
| 491 | ) | 491 | ) |
| 492 | .bind(creator.uuid()) | 492 | .bind(creator.uuid()) |
| 493 | .bind(format!("exam-fixture-{}", &creator.key()[30..])) | 493 | .bind(format!("exam-fixture-{}", &creator.key()[30..])) |
| @@ -544,8 +544,8 @@ mod tests { | |||
| 544 | .to_vec(); | 544 | .to_vec(); |
| 545 | let creator = UserId::generate(); | 545 | let creator = UserId::generate(); |
| 546 | sqlx::query( | 546 | sqlx::query( |
| 547 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 547 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 548 | - VALUES ($1, $2, 'x', 'teacher')", | 548 | + VALUES ($1, $2, 0, 'teacher')", |
| 549 | ) | 549 | ) |
| 550 | .bind(creator.uuid()) | 550 | .bind(creator.uuid()) |
| 551 | .bind(format!("orphan-race-{}", &creator.key()[30..])) | 551 | .bind(format!("orphan-race-{}", &creator.key()[30..])) |
| @@ -578,8 +578,8 @@ mod tests { | |||
| 578 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 578 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 579 | let user = UserId::generate(); | 579 | let user = UserId::generate(); |
| 580 | sqlx::query( | 580 | sqlx::query( |
| 581 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 581 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 582 | - VALUES ($1, $2, 'x', $3)", | 582 | + VALUES ($1, $2, 0, $3)", |
| 583 | ) | 583 | ) |
| 584 | .bind(user.uuid()) | 584 | .bind(user.uuid()) |
| 585 | .bind(format!("{label}-{}", &user.key()[30..])) | 585 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/db/exam_answer.rsmodified+2 -2
| @@ -302,8 +302,8 @@ mod tests { | |||
| 302 | // The student is a foreign key now: a real row under the fixture's | 302 | // The student is a foreign key now: a real row under the fixture's |
| 303 | // fixed key. | 303 | // fixed key. |
| 304 | sqlx::query( | 304 | sqlx::query( |
| 305 | - "INSERT INTO app_user (id, username, password_hash) \ | 305 | + "INSERT INTO app_user (id, username, created_at) \ |
| 306 | - VALUES ($1, 'aaaa-fixture', 'x')", | 306 | + VALUES ($1, 'aaaa-fixture', 0)", |
| 307 | ) | 307 | ) |
| 308 | .bind(student().uuid()) | 308 | .bind(student().uuid()) |
| 309 | .execute(&db) | 309 | .execute(&db) |
src/db/exam_attempt.rsmodified+3 -8
| @@ -393,8 +393,8 @@ mod tests { | |||
| 393 | // The creator is a foreign key now: a real `app_user` row under the | 393 | // The creator is a foreign key now: a real `app_user` row under the |
| 394 | // fixture's fixed key. | 394 | // fixture's fixed key. |
| 395 | sqlx::query( | 395 | sqlx::query( |
| 396 | - "INSERT INTO app_user (id, username, password_hash) \ | 396 | + "INSERT INTO app_user (id, username, created_at) \ |
| 397 | - VALUES ($1, 'acdc-fixture', 'x') ON CONFLICT DO NOTHING", | 397 | + VALUES ($1, 'acdc-fixture', 0) ON CONFLICT DO NOTHING", |
| 398 | ) | 398 | ) |
| 399 | .bind(creator.uuid()) | 399 | .bind(creator.uuid()) |
| 400 | .execute(db) | 400 | .execute(db) |
| @@ -460,15 +460,10 @@ mod tests { | |||
| 460 | /// A real user row: the sitting counter lives on it, and the claim that | 460 | /// A real user row: the sitting counter lives on it, and the claim that |
| 461 | /// rides the attempt's create has nothing to write to without one. | 461 | /// rides the attempt's create has nothing to write to without one. |
| 462 | async fn student(db: &Database) -> UserId { | 462 | async fn student(db: &Database) -> UserId { |
| 463 | - let hash = crate::domain::user::Password::try_new("secret1") | ||
| 464 | - .unwrap() | ||
| 465 | - .hash_async() | ||
| 466 | - .await | ||
| 467 | - .unwrap(); | ||
| 468 | *crate::db::user::create( | 463 | *crate::db::user::create( |
| 469 | db, | 464 | db, |
| 470 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 465 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 471 | - hash, | 466 | + None, |
| 472 | ) | 467 | ) |
| 473 | .await | 468 | .await |
| 474 | .unwrap() | 469 | .unwrap() |
src/db/exam_question.rsmodified+3 -8
| @@ -450,8 +450,8 @@ mod tests { | |||
| 450 | // the fixture's fixed key. | 450 | // the fixture's fixed key. |
| 451 | let creator = UserId::from_key("019732e3-7b00-7000-8000-00000000acdc"); | 451 | let creator = UserId::from_key("019732e3-7b00-7000-8000-00000000acdc"); |
| 452 | sqlx::query( | 452 | sqlx::query( |
| 453 | - "INSERT INTO app_user (id, username, password_hash) \ | 453 | + "INSERT INTO app_user (id, username, created_at) \ |
| 454 | - VALUES ($1, 'acdc-fixture', 'x')", | 454 | + VALUES ($1, 'acdc-fixture', 0)", |
| 455 | ) | 455 | ) |
| 456 | .bind(creator.uuid()) | 456 | .bind(creator.uuid()) |
| 457 | .execute(db) | 457 | .execute(db) |
| @@ -547,15 +547,10 @@ mod tests { | |||
| 547 | // A real user row: starting a sitting moves that student's badge | 547 | // A real user row: starting a sitting moves that student's badge |
| 548 | // counter in the same transaction, and an `UPDATE` has nothing to | 548 | // counter in the same transaction, and an `UPDATE` has nothing to |
| 549 | // write to without one. | 549 | // write to without one. |
| 550 | - let hash = crate::domain::user::Password::try_new("secret1") | ||
| 551 | - .unwrap() | ||
| 552 | - .hash_async() | ||
| 553 | - .await | ||
| 554 | - .unwrap(); | ||
| 555 | let student = crate::db::user::create( | 550 | let student = crate::db::user::create( |
| 556 | &db, | 551 | &db, |
| 557 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 552 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 558 | - hash, | 553 | + None, |
| 559 | ) | 554 | ) |
| 560 | .await | 555 | .await |
| 561 | .unwrap(); | 556 | .unwrap(); |
src/db/exam_result.rsmodified+10 -7
| @@ -11,6 +11,7 @@ use crate::domain::exam::ExamId; | |||
| 11 | use crate::domain::exam_result::{ | 11 | use crate::domain::exam_result::{ |
| 12 | ExamResult, Mark, draft_error, latest_per_pair, retired_kind_error, | 12 | ExamResult, Mark, draft_error, latest_per_pair, retired_kind_error, |
| 13 | }; | 13 | }; |
| 14 | +use crate::domain::timestamp::Timestamp; | ||
| 14 | use crate::domain::user::UserId; | 15 | use crate::domain::user::UserId; |
| 15 | use crate::error::AppError; | 16 | use crate::error::AppError; |
| 16 | 17 | ||
| @@ -180,10 +181,11 @@ pub async fn grade( | |||
| 180 | } | 181 | } |
| 181 | let written = sqlx::query_as!( | 182 | let written = sqlx::query_as!( |
| 182 | ExamResult, | 183 | ExamResult, |
| 183 | - r#"INSERT INTO exam_result (exam, app_user, seq, mark, graded_by) | 184 | + r#"INSERT INTO exam_result (exam, app_user, seq, mark, graded_by, graded_at) |
| 184 | - VALUES ($1, $2, $3, $4, $5) | 185 | + VALUES ($1, $2, $3, $4, $5, $6) |
| 185 | ON CONFLICT (exam, app_user, seq) DO UPDATE | 186 | ON CONFLICT (exam, app_user, seq) DO UPDATE |
| 186 | - SET mark = EXCLUDED.mark, graded_by = EXCLUDED.graded_by | 187 | + SET mark = EXCLUDED.mark, graded_by = EXCLUDED.graded_by, |
| 188 | + graded_at = EXCLUDED.graded_at | ||
| 187 | RETURNING exam AS "exam: ExamId", app_user AS "user: UserId", seq, | 189 | RETURNING exam AS "exam: ExamId", app_user AS "user: UserId", seq, |
| 188 | mark AS "mark: Mark", graded_by AS "graded_by: UserId""#, | 190 | mark AS "mark: Mark", graded_by AS "graded_by: UserId""#, |
| 189 | exam.uuid(), | 191 | exam.uuid(), |
| @@ -191,6 +193,7 @@ pub async fn grade( | |||
| 191 | seq, | 193 | seq, |
| 192 | mark.as_i64(), | 194 | mark.as_i64(), |
| 193 | graded_by.uuid(), | 195 | graded_by.uuid(), |
| 196 | + Timestamp::now().as_millis(), | ||
| 194 | ) | 197 | ) |
| 195 | .fetch_one(&mut *conn) | 198 | .fetch_one(&mut *conn) |
| 196 | .await?; | 199 | .await?; |
| @@ -518,8 +521,8 @@ mod tests { | |||
| 518 | // too (the teacher idempotently — [`the_two_people`] re-runs it). | 521 | // too (the teacher idempotently — [`the_two_people`] re-runs it). |
| 519 | let teacher = UserId::from_key(TEACHER); | 522 | let teacher = UserId::from_key(TEACHER); |
| 520 | sqlx::query( | 523 | sqlx::query( |
| 521 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 524 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 522 | - VALUES ($1, 't', 'x', 'teacher') ON CONFLICT (id) DO NOTHING", | 525 | + VALUES ($1, 't', 0, 'teacher') ON CONFLICT (id) DO NOTHING", |
| 523 | ) | 526 | ) |
| 524 | .bind(teacher.uuid()) | 527 | .bind(teacher.uuid()) |
| 525 | .execute(db) | 528 | .execute(db) |
| @@ -622,8 +625,8 @@ mod tests { | |||
| 622 | async fn the_two_people(db: &Database) { | 625 | async fn the_two_people(db: &Database) { |
| 623 | for (role, key) in [("teacher", TEACHER), ("student", STUDENT)] { | 626 | for (role, key) in [("teacher", TEACHER), ("student", STUDENT)] { |
| 624 | sqlx::query( | 627 | sqlx::query( |
| 625 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 628 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 626 | - VALUES ($1, $2, 'x', $3) ON CONFLICT (id) DO NOTHING", | 629 | + VALUES ($1, $2, 0, $3) ON CONFLICT (id) DO NOTHING", |
| 627 | ) | 630 | ) |
| 628 | .bind(UserId::from_key(key).uuid()) | 631 | .bind(UserId::from_key(key).uuid()) |
| 629 | .bind(key) | 632 | .bind(key) |
src/db/homework.rsmodified+2 -2
| @@ -537,8 +537,8 @@ mod tests { | |||
| 537 | // (the subject's own fixture path mints one) and a real teacher. | 537 | // (the subject's own fixture path mints one) and a real teacher. |
| 538 | let teacher = UserId::generate(); | 538 | let teacher = UserId::generate(); |
| 539 | sqlx::query( | 539 | sqlx::query( |
| 540 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 540 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 541 | - VALUES ($1, $2, 'x', 'teacher')", | 541 | + VALUES ($1, $2, 0, 'teacher')", |
| 542 | ) | 542 | ) |
| 543 | .bind(teacher.uuid()) | 543 | .bind(teacher.uuid()) |
| 544 | .bind(format!("homework-fixture-{}", &teacher.key()[30..])) | 544 | .bind(format!("homework-fixture-{}", &teacher.key()[30..])) |
src/db/homework_file.rsmodified+2 -2
| @@ -310,7 +310,7 @@ mod tests { | |||
| 310 | /// A real `app_user` row: submitters are foreign keys too. | 310 | /// A real `app_user` row: submitters are foreign keys too. |
| 311 | async fn a_student(db: &Database) -> UserId { | 311 | async fn a_student(db: &Database) -> UserId { |
| 312 | let user = UserId::generate(); | 312 | let user = UserId::generate(); |
| 313 | - sqlx::query("INSERT INTO app_user (id, username, password_hash, role) VALUES ($1, $2, 'x', 'student')") | 313 | + sqlx::query("INSERT INTO app_user (id, username, created_at, role) VALUES ($1, $2, 0, 'student')") |
| 314 | .bind(user.uuid()) | 314 | .bind(user.uuid()) |
| 315 | .bind(format!("s-{}", &user.key()[30..])) | 315 | .bind(format!("s-{}", &user.key()[30..])) |
| 316 | .execute(db) | 316 | .execute(db) |
| @@ -322,7 +322,7 @@ mod tests { | |||
| 322 | /// A real `app_user` row: creators and submitters are foreign keys now. | 322 | /// A real `app_user` row: creators and submitters are foreign keys now. |
| 323 | async fn a_teacher(db: &Database) -> UserId { | 323 | async fn a_teacher(db: &Database) -> UserId { |
| 324 | let user = UserId::generate(); | 324 | let user = UserId::generate(); |
| 325 | - sqlx::query("INSERT INTO app_user (id, username, password_hash, role) VALUES ($1, $2, 'x', 'teacher')") | 325 | + sqlx::query("INSERT INTO app_user (id, username, created_at, role) VALUES ($1, $2, 0, 'teacher')") |
| 326 | .bind(user.uuid()) | 326 | .bind(user.uuid()) |
| 327 | .bind(format!("t-{}", &user.key()[30..])) | 327 | .bind(format!("t-{}", &user.key()[30..])) |
| 328 | .execute(db) | 328 | .execute(db) |
src/db/homework_result.rsmodified+4 -4
| @@ -333,8 +333,8 @@ mod tests { | |||
| 333 | async fn a_teacher(db: &Database) -> UserId { | 333 | async fn a_teacher(db: &Database) -> UserId { |
| 334 | let user = UserId::generate(); | 334 | let user = UserId::generate(); |
| 335 | sqlx::query( | 335 | sqlx::query( |
| 336 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 336 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 337 | - VALUES ($1, $2, 'x', 'teacher')", | 337 | + VALUES ($1, $2, 0, 'teacher')", |
| 338 | ) | 338 | ) |
| 339 | .bind(user.uuid()) | 339 | .bind(user.uuid()) |
| 340 | .bind(format!("t-{}", &user.key()[30..])) | 340 | .bind(format!("t-{}", &user.key()[30..])) |
| @@ -348,8 +348,8 @@ mod tests { | |||
| 348 | async fn a_student(db: &Database) -> UserId { | 348 | async fn a_student(db: &Database) -> UserId { |
| 349 | let user = UserId::generate(); | 349 | let user = UserId::generate(); |
| 350 | sqlx::query( | 350 | sqlx::query( |
| 351 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 351 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 352 | - VALUES ($1, $2, 'x', 'student')", | 352 | + VALUES ($1, $2, 0, 'student')", |
| 353 | ) | 353 | ) |
| 354 | .bind(user.uuid()) | 354 | .bind(user.uuid()) |
| 355 | .bind(format!("s-{}", &user.key()[30..])) | 355 | .bind(format!("s-{}", &user.key()[30..])) |
src/db/homework_submission.rsmodified+3 -8
| @@ -419,8 +419,8 @@ mod tests { | |||
| 419 | async fn a_teacher(db: &Database) -> UserId { | 419 | async fn a_teacher(db: &Database) -> UserId { |
| 420 | let user = UserId::generate(); | 420 | let user = UserId::generate(); |
| 421 | sqlx::query( | 421 | sqlx::query( |
| 422 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 422 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 423 | - VALUES ($1, $2, 'x', 'teacher')", | 423 | + VALUES ($1, $2, 0, 'teacher')", |
| 424 | ) | 424 | ) |
| 425 | .bind(user.uuid()) | 425 | .bind(user.uuid()) |
| 426 | .bind(format!("t-{}", &user.key()[30..])) | 426 | .bind(format!("t-{}", &user.key()[30..])) |
| @@ -439,15 +439,10 @@ mod tests { | |||
| 439 | /// A real user row: the counters live on it, and an `UPDATE` has nothing to | 439 | /// A real user row: the counters live on it, and an `UPDATE` has nothing to |
| 440 | /// write to without one. | 440 | /// write to without one. |
| 441 | async fn a_student(username: &str, db: &Database) -> UserId { | 441 | async fn a_student(username: &str, db: &Database) -> UserId { |
| 442 | - let hash = crate::domain::user::Password::try_new("secret1") | ||
| 443 | - .unwrap() | ||
| 444 | - .hash_async() | ||
| 445 | - .await | ||
| 446 | - .unwrap(); | ||
| 447 | *crate::db::user::create( | 442 | *crate::db::user::create( |
| 448 | db, | 443 | db, |
| 449 | crate::domain::user::Username::try_new(username).unwrap(), | 444 | crate::domain::user::Username::try_new(username).unwrap(), |
| 450 | - hash, | 445 | + None, |
| 451 | ) | 446 | ) |
| 452 | .await | 447 | .await |
| 453 | .unwrap() | 448 | .unwrap() |
src/db/meal_booking.rsmodified+2 -2
| @@ -412,8 +412,8 @@ mod tests { | |||
| 412 | // The menu's creator is a foreign key now: a real `app_user` row. | 412 | // The menu's creator is a foreign key now: a real `app_user` row. |
| 413 | let creator = UserId::generate(); | 413 | let creator = UserId::generate(); |
| 414 | sqlx::query( | 414 | sqlx::query( |
| 415 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 415 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 416 | - VALUES ($1, $2, 'x', 'teacher')", | 416 | + VALUES ($1, $2, 0, 'teacher')", |
| 417 | ) | 417 | ) |
| 418 | .bind(creator.uuid()) | 418 | .bind(creator.uuid()) |
| 419 | .bind(format!("menu-fixture-{}", &creator.key()[30..])) | 419 | .bind(format!("menu-fixture-{}", &creator.key()[30..])) |
src/db/menu.rsmodified+2 -2
| @@ -296,8 +296,8 @@ mod tests { | |||
| 296 | async fn school() -> (Database, crate::database::TestDatabases) { | 296 | async fn school() -> (Database, crate::database::TestDatabases) { |
| 297 | let (db, leases) = init_test_db().await; | 297 | let (db, leases) = init_test_db().await; |
| 298 | sqlx::query( | 298 | sqlx::query( |
| 299 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 299 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 300 | - VALUES ($1, 'teacher', 'x', 'teacher')", | 300 | + VALUES ($1, 'teacher', 0, 'teacher')", |
| 301 | ) | 301 | ) |
| 302 | .bind(UserId::from_key(TEACHER).uuid()) | 302 | .bind(UserId::from_key(TEACHER).uuid()) |
| 303 | .execute(&db) | 303 | .execute(&db) |
src/db/mod.rsmodified+2 -0
| @@ -50,6 +50,7 @@ pub mod person; | |||
| 50 | pub mod payment_ledger; | 50 | pub mod payment_ledger; |
| 51 | pub mod pomodoro; | 51 | pub mod pomodoro; |
| 52 | pub mod pool_question; | 52 | pub mod pool_question; |
| 53 | +pub mod pool_question_image; | ||
| 53 | pub mod profile; | 54 | pub mod profile; |
| 54 | pub mod question_image; | 55 | pub mod question_image; |
| 55 | pub mod rag_output; | 56 | pub mod rag_output; |
| @@ -58,6 +59,7 @@ pub mod session; | |||
| 58 | pub mod session_attendance; | 59 | pub mod session_attendance; |
| 59 | pub mod settings; | 60 | pub mod settings; |
| 60 | pub mod solution; | 61 | pub mod solution; |
| 62 | +pub mod solution_image; | ||
| 61 | pub mod subject; | 63 | pub mod subject; |
| 62 | pub mod term; | 64 | pub mod term; |
| 63 | pub mod user; | 65 | pub mod user; |
src/db/note_file.rsmodified+1 -1
| @@ -123,7 +123,7 @@ mod tests { | |||
| 123 | /// A real `app_user` row: the note's owner is a foreign key now. | 123 | /// A real `app_user` row: the note's owner is a foreign key now. |
| 124 | async fn a_person(db: &Database) -> crate::domain::user::UserId { | 124 | async fn a_person(db: &Database) -> crate::domain::user::UserId { |
| 125 | let user = crate::domain::user::UserId::generate(); | 125 | let user = crate::domain::user::UserId::generate(); |
| 126 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 126 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 127 | .bind(user.uuid()) | 127 | .bind(user.uuid()) |
| 128 | .bind(format!("nf-{}", &user.key()[30..])) | 128 | .bind(format!("nf-{}", &user.key()[30..])) |
| 129 | .execute(db) | 129 | .execute(db) |
src/db/person.rsmodified+7 -6
| @@ -18,10 +18,11 @@ use crate::tenant::{SchoolStatus, Slug}; | |||
| 18 | /// of a race gets the same `Conflict` a sequential duplicate would. | 18 | /// of a race gets the same `Conflict` a sequential duplicate would. |
| 19 | pub async fn create(db: &Database, person: Person) -> Result<(), AppError> { | 19 | pub async fn create(db: &Database, person: Person) -> Result<(), AppError> { |
| 20 | match sqlx::query!( | 20 | match sqlx::query!( |
| 21 | - "INSERT INTO person (id, username, password_hash) VALUES ($1, $2, $3)", | 21 | + "INSERT INTO person (id, username, password_hash, created_at) VALUES ($1, $2, $3, $4)", |
| 22 | person.id.uuid(), | 22 | person.id.uuid(), |
| 23 | person.username.as_str(), | 23 | person.username.as_str(), |
| 24 | person.password_hash.as_str(), | 24 | person.password_hash.as_str(), |
| 25 | + Timestamp::now().as_millis(), | ||
| 25 | ) | 26 | ) |
| 26 | .execute(db) | 27 | .execute(db) |
| 27 | .await | 28 | .await |
| @@ -112,9 +113,10 @@ pub async fn membership_of( | |||
| 112 | /// repeated join is a no-op, not an error. | 113 | /// repeated join is a no-op, not an error. |
| 113 | pub async fn add_membership(db: &Database, person: &PersonId, slug: &Slug) -> Result<(), AppError> { | 114 | pub async fn add_membership(db: &Database, person: &PersonId, slug: &Slug) -> Result<(), AppError> { |
| 114 | sqlx::query!( | 115 | sqlx::query!( |
| 115 | - "INSERT INTO person_school (person, school) VALUES ($1, $2) ON CONFLICT DO NOTHING", | 116 | + "INSERT INTO person_school (person, school, created_at) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING", |
| 116 | person.uuid(), | 117 | person.uuid(), |
| 117 | - slug.as_str() | 118 | + slug.as_str(), |
| 119 | + Timestamp::now().as_millis() | ||
| 118 | ) | 120 | ) |
| 119 | .execute(db) | 121 | .execute(db) |
| 120 | .await?; | 122 | .await?; |
| @@ -193,9 +195,8 @@ pub async fn delete_sessions_by_person(db: &Database, person: &PersonId) -> Resu | |||
| 193 | Ok(()) | 195 | Ok(()) |
| 194 | } | 196 | } |
| 195 | 197 | ||
| 196 | -/// Move the person credential — the one login reads. The school-side | 198 | +/// Move the person credential — the one login reads. The school-side row |
| 197 | -/// `app_user` copy is rewritten separately by the same caller, so the two | 199 | +/// carries no password at all, so this is the whole credential move. |
| 198 | -/// stay in step. | ||
| 199 | pub async fn set_password_hash( | 200 | pub async fn set_password_hash( |
| 200 | db: &Database, | 201 | db: &Database, |
| 201 | username: &Username, | 202 | username: &Username, |
src/db/pomodoro.rsmodified+1 -1
| @@ -244,7 +244,7 @@ mod tests { | |||
| 244 | /// nothing. The tests above need no row — they read only the stint log. | 244 | /// nothing. The tests above need no row — they read only the stint log. |
| 245 | async fn a_user(db: &Database) -> UserId { | 245 | async fn a_user(db: &Database) -> UserId { |
| 246 | let user = UserId::generate(); | 246 | let user = UserId::generate(); |
| 247 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 247 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 248 | .bind(user.uuid()) | 248 | .bind(user.uuid()) |
| 249 | .bind(format!("u{}", &user.key()[30..])) | 249 | .bind(format!("u{}", &user.key()[30..])) |
| 250 | .execute(db) | 250 | .execute(db) |
src/db/pool_question.rsmodified+156 -125
| @@ -23,9 +23,7 @@ pub async fn insert(db: &Database, question: PoolQuestion) -> Result<PoolQuestio | |||
| 23 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", | 23 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 24 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 24 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 25 | status, asked_at AS "asked_at: Timestamp", | 25 | status, asked_at AS "asked_at: Timestamp", |
| 26 | - approved_by AS "approved_by: UserId", image_file, | 26 | + approved_by AS "approved_by: UserId""#, |
| 27 | - image_content_type AS "image_content_type: FileContentType", | ||
| 28 | - image_size"#, | ||
| 29 | question.id.uuid(), | 27 | question.id.uuid(), |
| 30 | question.asker.uuid(), | 28 | question.asker.uuid(), |
| 31 | question.title.as_str(), | 29 | question.title.as_str(), |
| @@ -44,9 +42,7 @@ pub async fn read(db: &Database, id: &PoolQuestionId) -> Result<Option<PoolQuest | |||
| 44 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", | 42 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 45 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 43 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 46 | status, asked_at AS "asked_at: Timestamp", | 44 | status, asked_at AS "asked_at: Timestamp", |
| 47 | - approved_by AS "approved_by: UserId", image_file, | 45 | + approved_by AS "approved_by: UserId" |
| 48 | - image_content_type AS "image_content_type: FileContentType", | ||
| 49 | - image_size | ||
| 50 | FROM pool_question WHERE id = $1"#, | 46 | FROM pool_question WHERE id = $1"#, |
| 51 | id.uuid() | 47 | id.uuid() |
| 52 | ) | 48 | ) |
| @@ -63,9 +59,7 @@ pub async fn list_all(db: &Database) -> Result<Vec<PoolQuestion>, AppError> { | |||
| 63 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", | 59 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 64 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 60 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 65 | status, asked_at AS "asked_at: Timestamp", | 61 | status, asked_at AS "asked_at: Timestamp", |
| 66 | - approved_by AS "approved_by: UserId", image_file, | 62 | + approved_by AS "approved_by: UserId" |
| 67 | - image_content_type AS "image_content_type: FileContentType", | ||
| 68 | - image_size | ||
| 69 | FROM pool_question ORDER BY asked_at DESC, id DESC"#, | 63 | FROM pool_question ORDER BY asked_at DESC, id DESC"#, |
| 70 | ) | 64 | ) |
| 71 | .fetch_all(db) | 65 | .fetch_all(db) |
| @@ -81,9 +75,7 @@ pub async fn list_visible_to(db: &Database, user: &UserId) -> Result<Vec<PoolQue | |||
| 81 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", | 75 | r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 82 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 76 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 83 | status, asked_at AS "asked_at: Timestamp", | 77 | status, asked_at AS "asked_at: Timestamp", |
| 84 | - approved_by AS "approved_by: UserId", image_file, | 78 | + approved_by AS "approved_by: UserId" |
| 85 | - image_content_type AS "image_content_type: FileContentType", | ||
| 86 | - image_size | ||
| 87 | FROM pool_question | 79 | FROM pool_question |
| 88 | WHERE status = $1 OR asker = $2 | 80 | WHERE status = $1 OR asker = $2 |
| 89 | ORDER BY asked_at DESC, id DESC"#, | 81 | ORDER BY asked_at DESC, id DESC"#, |
| @@ -142,9 +134,7 @@ pub async fn approve( | |||
| 142 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", | 134 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 143 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 135 | title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 144 | status, asked_at AS "asked_at: Timestamp", | 136 | status, asked_at AS "asked_at: Timestamp", |
| 145 | - approved_by AS "approved_by: UserId", image_file, | 137 | + approved_by AS "approved_by: UserId""#, |
| 146 | - image_content_type AS "image_content_type: FileContentType", | ||
| 147 | - image_size"#, | ||
| 148 | id.uuid(), | 138 | id.uuid(), |
| 149 | STATUS_APPROVED, | 139 | STATUS_APPROVED, |
| 150 | approver.uuid(), | 140 | approver.uuid(), |
| @@ -153,59 +143,59 @@ pub async fn approve( | |||
| 153 | .fetch_optional(&mut *tx) | 143 | .fetch_optional(&mut *tx) |
| 154 | .await?; | 144 | .await?; |
| 155 | if let Some(question) = &approved | 145 | if let Some(question) = &approved |
| 156 | - && question.asker != approver { | 146 | + && question.asker != approver |
| 157 | - // The counter columns are NOT NULL DEFAULT 0 — the old | 147 | + { |
| 158 | - // absent-reads-as-zero coalesce is gone with the schema. | 148 | + // The counter columns are NOT NULL DEFAULT 0 — the old |
| 159 | - sqlx::query!( | 149 | + // absent-reads-as-zero coalesce is gone with the schema. |
| 160 | - "UPDATE app_user SET pool_approved_total = pool_approved_total + 1 | 150 | + sqlx::query!( |
| 151 | + "UPDATE app_user SET pool_approved_total = pool_approved_total + 1 | ||
| 161 | WHERE id = $1", | 152 | WHERE id = $1", |
| 162 | - approver.uuid() | 153 | + approver.uuid() |
| 163 | - ) | 154 | + ) |
| 164 | - .execute(&mut *tx) | 155 | + .execute(&mut *tx) |
| 165 | - .await?; | 156 | + .await?; |
| 166 | - sqlx::query!( | 157 | + sqlx::query!( |
| 167 | - "UPDATE app_user SET pool_published_total = pool_published_total + 1 | 158 | + "UPDATE app_user SET pool_published_total = pool_published_total + 1 |
| 168 | WHERE id = $1", | 159 | WHERE id = $1", |
| 169 | - question.asker.uuid() | 160 | + question.asker.uuid() |
| 170 | - ) | 161 | + ) |
| 171 | - .execute(&mut *tx) | 162 | + .execute(&mut *tx) |
| 172 | - .await?; | 163 | + .await?; |
| 173 | - } | 164 | + } |
| 174 | Ok(approved) | 165 | Ok(approved) |
| 175 | }) | 166 | }) |
| 176 | .await | 167 | .await |
| 177 | } | 168 | } |
| 178 | 169 | ||
| 179 | -/// Point the question at a freshly written image blob. Guarded on | 170 | +/// Point the question at a freshly written image blob. Guarded on `pending` |
| 180 | -/// `pending` for the same reason approval is: an image landing after | 171 | +/// for the same reason approval is: an image landing after approval would |
| 181 | -/// approval would put unmoderated bytes in the pool, so an upload that | 172 | +/// put unmoderated bytes in the pool, so an upload that loses the race gets |
| 182 | -/// loses the race gets `None` (and the caller takes the orphan blob back | 173 | +/// `Ok(None)` (and the caller takes the orphan blob back off disk). |
| 183 | -/// off disk). Returns the *before* row — its `image_file` is the replaced | 174 | +/// `Ok(Some(replaced))` names the blob this upload displaced — the caller's |
| 184 | -/// blob the caller must remove. | 175 | +/// to remove, `None` inside when nothing was there before. |
| 185 | /// | 176 | /// |
| 186 | -/// The row lock makes the before-read and the guarded write one switch; a | 177 | +/// The photo is its own row in `pool_question_image` (the child-table shape |
| 187 | -/// racing approve either predates this transaction's snapshot or waits on | 178 | +/// of `question_image`), so the write is that row's upsert; the parent's |
| 188 | -/// the lock, so a fresh image can never straddle an approval. | 179 | +/// `FOR UPDATE` row lock still makes the pending check and the write one |
| 180 | +/// switch — a racing approve either predates this transaction's snapshot or | ||
| 181 | +/// waits on the lock, so a fresh image can never straddle an approval. The | ||
| 182 | +/// replaced name is read *inside the same transaction*, not by the caller | ||
| 183 | +/// before it: two uploads to one question both write this row, so they | ||
| 184 | +/// contend on it and the loser re-reads the winner's blob name — the | ||
| 185 | +/// discipline `crate::db::question_image::upsert` documents. | ||
| 189 | pub async fn set_image( | 186 | pub async fn set_image( |
| 190 | db: &Database, | 187 | db: &Database, |
| 191 | id: &PoolQuestionId, | 188 | id: &PoolQuestionId, |
| 192 | file: &str, | 189 | file: &str, |
| 193 | content_type: &FileContentType, | 190 | content_type: &FileContentType, |
| 194 | size: i64, | 191 | size: i64, |
| 195 | -) -> Result<Option<PoolQuestion>, AppError> { | 192 | +) -> Result<Option<Option<String>>, AppError> { |
| 196 | let id = *id; | 193 | let id = *id; |
| 197 | let file = file.to_owned(); | 194 | let file = file.to_owned(); |
| 198 | let content_type = content_type.clone(); | 195 | let content_type = content_type.clone(); |
| 199 | tx_with_retry(db, false, async move |tx| { | 196 | tx_with_retry(db, false, async move |tx| { |
| 200 | - let before = sqlx::query_as!( | 197 | + let before = sqlx::query!( |
| 201 | - PoolQuestion, | 198 | + r#"SELECT status FROM pool_question WHERE id = $1 FOR UPDATE"#, |
| 202 | - r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", | ||
| 203 | - title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | ||
| 204 | - status, asked_at AS "asked_at: Timestamp", | ||
| 205 | - approved_by AS "approved_by: UserId", image_file, | ||
| 206 | - image_content_type AS "image_content_type: FileContentType", | ||
| 207 | - image_size | ||
| 208 | - FROM pool_question WHERE id = $1 FOR UPDATE"#, | ||
| 209 | id.uuid() | 199 | id.uuid() |
| 210 | ) | 200 | ) |
| 211 | .fetch_optional(&mut *tx) | 201 | .fetch_optional(&mut *tx) |
| @@ -213,43 +203,45 @@ pub async fn set_image( | |||
| 213 | let Some(before) = before else { | 203 | let Some(before) = before else { |
| 214 | return Ok(None); | 204 | return Ok(None); |
| 215 | }; | 205 | }; |
| 216 | - let written = sqlx::query!( | 206 | + if before.status != STATUS_PENDING { |
| 217 | - r#"UPDATE pool_question | 207 | + return Ok(None); |
| 218 | - SET image_file = $2, image_content_type = $3, image_size = $4 | 208 | + } |
| 219 | - WHERE id = $1 AND status = $5"#, | 209 | + let replaced = sqlx::query_scalar!( |
| 210 | + r#"SELECT file FROM pool_question_image WHERE question = $1"#, | ||
| 211 | + id.uuid() | ||
| 212 | + ) | ||
| 213 | + .fetch_optional(&mut *tx) | ||
| 214 | + .await?; | ||
| 215 | + sqlx::query!( | ||
| 216 | + r#"INSERT INTO pool_question_image (question, file, content_type, size) | ||
| 217 | + VALUES ($1, $2, $3, $4) | ||
| 218 | + ON CONFLICT (question) DO UPDATE | ||
| 219 | + SET file = EXCLUDED.file, content_type = EXCLUDED.content_type, | ||
| 220 | + size = EXCLUDED.size"#, | ||
| 220 | id.uuid(), | 221 | id.uuid(), |
| 221 | file, | 222 | file, |
| 222 | content_type.as_str(), | 223 | content_type.as_str(), |
| 223 | size, | 224 | size, |
| 224 | - STATUS_PENDING, | ||
| 225 | ) | 225 | ) |
| 226 | .execute(&mut *tx) | 226 | .execute(&mut *tx) |
| 227 | .await?; | 227 | .await?; |
| 228 | - if written.rows_affected() == 0 { | 228 | + Ok(Some(replaced)) |
| 229 | - return Ok(None); | ||
| 230 | - } | ||
| 231 | - Ok(Some(before)) | ||
| 232 | }) | 229 | }) |
| 233 | .await | 230 | .await |
| 234 | } | 231 | } |
| 235 | 232 | ||
| 236 | -/// Detach the question's image (pending only, like `set_image`). Returns | 233 | +/// Detach the question's image (pending only, like [`set_image`]). |
| 237 | -/// the *before* row — its `image_file` is the blob the caller must remove. | 234 | +/// `Ok(None)` = the question is gone or no longer pending; |
| 235 | +/// `Ok(Some(detached))` names the blob the caller removes — `None` inside | ||
| 236 | +/// when the question carried no image (the route answers that 404). | ||
| 238 | pub async fn clear_image( | 237 | pub async fn clear_image( |
| 239 | db: &Database, | 238 | db: &Database, |
| 240 | id: &PoolQuestionId, | 239 | id: &PoolQuestionId, |
| 241 | -) -> Result<Option<PoolQuestion>, AppError> { | 240 | +) -> Result<Option<Option<String>>, AppError> { |
| 242 | let id = *id; | 241 | let id = *id; |
| 243 | tx_with_retry(db, false, async move |tx| { | 242 | tx_with_retry(db, false, async move |tx| { |
| 244 | - let before = sqlx::query_as!( | 243 | + let before = sqlx::query!( |
| 245 | - PoolQuestion, | 244 | + r#"SELECT status FROM pool_question WHERE id = $1 FOR UPDATE"#, |
| 246 | - r#"SELECT id AS "id: PoolQuestionId", asker AS "asker: UserId", | ||
| 247 | - title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | ||
| 248 | - status, asked_at AS "asked_at: Timestamp", | ||
| 249 | - approved_by AS "approved_by: UserId", image_file, | ||
| 250 | - image_content_type AS "image_content_type: FileContentType", | ||
| 251 | - image_size | ||
| 252 | - FROM pool_question WHERE id = $1 FOR UPDATE"#, | ||
| 253 | id.uuid() | 245 | id.uuid() |
| 254 | ) | 246 | ) |
| 255 | .fetch_optional(&mut *tx) | 247 | .fetch_optional(&mut *tx) |
| @@ -257,66 +249,90 @@ pub async fn clear_image( | |||
| 257 | let Some(before) = before else { | 249 | let Some(before) = before else { |
| 258 | return Ok(None); | 250 | return Ok(None); |
| 259 | }; | 251 | }; |
| 260 | - let written = sqlx::query!( | 252 | + if before.status != STATUS_PENDING { |
| 261 | - r#"UPDATE pool_question | ||
| 262 | - SET image_file = NULL, image_content_type = NULL, image_size = NULL | ||
| 263 | - WHERE id = $1 AND status = $2"#, | ||
| 264 | - id.uuid(), | ||
| 265 | - STATUS_PENDING, | ||
| 266 | - ) | ||
| 267 | - .execute(&mut *tx) | ||
| 268 | - .await?; | ||
| 269 | - if written.rows_affected() == 0 { | ||
| 270 | return Ok(None); | 253 | return Ok(None); |
| 271 | } | 254 | } |
| 272 | - Ok(Some(before)) | 255 | + let detached = sqlx::query_scalar!( |
| 256 | + r#"DELETE FROM pool_question_image WHERE question = $1 RETURNING file"#, | ||
| 257 | + id.uuid() | ||
| 258 | + ) | ||
| 259 | + .fetch_optional(&mut *tx) | ||
| 260 | + .await?; | ||
| 261 | + Ok(Some(detached)) | ||
| 273 | }) | 262 | }) |
| 274 | .await | 263 | .await |
| 275 | } | 264 | } |
| 276 | 265 | ||
| 277 | -/// Delete the question and its solutions in one transaction, returning | 266 | +/// What [`delete`] took with the question: the rows ride back for their |
| 278 | -/// the removed rows — the question's *and* the swept solutions' — so the | 267 | +/// ids, and `image_files` is the caller's disk-GC list — the question's |
| 279 | -/// caller can take every image blob off disk (solutions carry photos too, | 268 | +/// photo and every swept solution's. |
| 280 | -/// and a row-only sweep would strand theirs forever). | 269 | +pub struct Deleted { |
| 270 | + pub question: PoolQuestion, | ||
| 271 | + pub solutions: Vec<Solution>, | ||
| 272 | + pub image_files: Vec<String>, | ||
| 273 | +} | ||
| 274 | + | ||
| 275 | +/// Delete the question and its solutions in one transaction, returning the | ||
| 276 | +/// removed rows plus every image blob key the two kinds of rows named, so | ||
| 277 | +/// the caller can take every blob off disk (solutions carry photos too, and | ||
| 278 | +/// a row-only sweep would strand theirs forever). | ||
| 281 | /// | 279 | /// |
| 282 | /// Children before the parent, so the foreign keys never refuse the parent | 280 | /// Children before the parent, so the foreign keys never refuse the parent |
| 283 | -/// delete. `cascade = true` because a solution offer committing inside this | 281 | +/// delete — the photo rows first (they name their parents), then the |
| 284 | -/// window makes the parent delete answer 23503 — a mid-cascade race the | 282 | +/// solutions, then the question. `cascade = true` because a solution offer |
| 285 | -/// retry loop re-runs, sweeping the latecomer with it. That foreign key is | 283 | +/// committing inside this window makes the parent delete answer 23503 — a |
| 286 | -/// also what keeps a solution from outliving its question on the insert | 284 | +/// mid-cascade race the retry loop re-runs, sweeping the latecomer with it. |
| 287 | -/// side, so the old existence-move transaction is simply gone. | 285 | +/// That foreign key is also what keeps a solution from outliving its |
| 288 | -pub async fn delete( | 286 | +/// question on the insert side, so the old existence-move transaction is |
| 289 | - db: &Database, | 287 | +/// simply gone. |
| 290 | - id: &PoolQuestionId, | 288 | +pub async fn delete(db: &Database, id: &PoolQuestionId) -> Result<Option<Deleted>, AppError> { |
| 291 | -) -> Result<Option<(PoolQuestion, Vec<Solution>)>, AppError> { | ||
| 292 | let id = *id; | 289 | let id = *id; |
| 293 | tx_with_retry(db, true, async move |tx| { | 290 | tx_with_retry(db, true, async move |tx| { |
| 291 | + let solution_files = sqlx::query_scalar!( | ||
| 292 | + r#"DELETE FROM solution_image si | ||
| 293 | + USING solution s | ||
| 294 | + WHERE si.solution = s.id AND s.question = $1 | ||
| 295 | + RETURNING si.file"#, | ||
| 296 | + id.uuid() | ||
| 297 | + ) | ||
| 298 | + .fetch_all(&mut *tx) | ||
| 299 | + .await?; | ||
| 294 | let solutions = sqlx::query_as!( | 300 | let solutions = sqlx::query_as!( |
| 295 | Solution, | 301 | Solution, |
| 296 | r#"DELETE FROM solution WHERE question = $1 | 302 | r#"DELETE FROM solution WHERE question = $1 |
| 297 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", | 303 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", |
| 298 | - author AS "author: UserId", body AS "body: SolutionBody", | 304 | + author AS "author: UserId", body AS "body: SolutionBody", |
| 299 | - offered_at AS "offered_at: Timestamp", image_file, | 305 | + offered_at AS "offered_at: Timestamp""#, |
| 300 | - image_content_type AS "image_content_type: FileContentType", | ||
| 301 | - image_size"#, | ||
| 302 | id.uuid() | 306 | id.uuid() |
| 303 | ) | 307 | ) |
| 304 | .fetch_all(&mut *tx) | 308 | .fetch_all(&mut *tx) |
| 305 | .await?; | 309 | .await?; |
| 310 | + let question_file = sqlx::query_scalar!( | ||
| 311 | + r#"DELETE FROM pool_question_image WHERE question = $1 RETURNING file"#, | ||
| 312 | + id.uuid() | ||
| 313 | + ) | ||
| 314 | + .fetch_optional(&mut *tx) | ||
| 315 | + .await?; | ||
| 306 | let question = sqlx::query_as!( | 316 | let question = sqlx::query_as!( |
| 307 | PoolQuestion, | 317 | PoolQuestion, |
| 308 | r#"DELETE FROM pool_question WHERE id = $1 | 318 | r#"DELETE FROM pool_question WHERE id = $1 |
| 309 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", | 319 | RETURNING id AS "id: PoolQuestionId", asker AS "asker: UserId", |
| 310 | - title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", | 320 | + title AS "title: PoolQuestionTitle", body AS "body: PoolQuestionBody", |
| 311 | - status, asked_at AS "asked_at: Timestamp", | 321 | + status, asked_at AS "asked_at: Timestamp", |
| 312 | - approved_by AS "approved_by: UserId", image_file, | 322 | + approved_by AS "approved_by: UserId""#, |
| 313 | - image_content_type AS "image_content_type: FileContentType", | ||
| 314 | - image_size"#, | ||
| 315 | id.uuid() | 323 | id.uuid() |
| 316 | ) | 324 | ) |
| 317 | .fetch_optional(&mut *tx) | 325 | .fetch_optional(&mut *tx) |
| 318 | .await?; | 326 | .await?; |
| 319 | - Ok(question.map(|question| (question, solutions))) | 327 | + Ok(question.map(|question| { |
| 328 | + let mut image_files = solution_files; | ||
| 329 | + image_files.extend(question_file); | ||
| 330 | + Deleted { | ||
| 331 | + question, | ||
| 332 | + solutions, | ||
| 333 | + image_files, | ||
| 334 | + } | ||
| 335 | + })) | ||
| 320 | }) | 336 | }) |
| 321 | .await | 337 | .await |
| 322 | } | 338 | } |
| @@ -332,7 +348,7 @@ mod tests { | |||
| 332 | /// the question, and the counters are plain `NOT NULL DEFAULT 0` columns. | 348 | /// the question, and the counters are plain `NOT NULL DEFAULT 0` columns. |
| 333 | async fn a_user(db: &Database) -> UserId { | 349 | async fn a_user(db: &Database) -> UserId { |
| 334 | let user = UserId::generate(); | 350 | let user = UserId::generate(); |
| 335 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 351 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 336 | .bind(user.uuid()) | 352 | .bind(user.uuid()) |
| 337 | .bind(format!("u{}", &user.key()[30..])) | 353 | .bind(format!("u{}", &user.key()[30..])) |
| 338 | .execute(db) | 354 | .execute(db) |
| @@ -483,31 +499,32 @@ mod tests { | |||
| 483 | let png = FileContentType::try_new("image/png").unwrap(); | 499 | let png = FileContentType::try_new("image/png").unwrap(); |
| 484 | 500 | ||
| 485 | let q = insert(&db, question(&asker)).await.unwrap(); | 501 | let q = insert(&db, question(&asker)).await.unwrap(); |
| 486 | - let before = set_image(&db, q.get_id(), "blob_a", &png, 3) | 502 | + let replaced = set_image(&db, q.get_id(), "blob_a", &png, 3) |
| 487 | .await | 503 | .await |
| 488 | .unwrap() | 504 | .unwrap() |
| 489 | .unwrap(); | 505 | .unwrap(); |
| 490 | - assert!(before.get_image_file().is_none()); | 506 | + assert!(replaced.is_none()); |
| 491 | 507 | ||
| 492 | // A replace reports the old blob for cleanup. | 508 | // A replace reports the old blob for cleanup. |
| 493 | - let before = set_image(&db, q.get_id(), "blob_b", &png, 5) | 509 | + let replaced = set_image(&db, q.get_id(), "blob_b", &png, 5) |
| 494 | .await | 510 | .await |
| 495 | .unwrap() | 511 | .unwrap() |
| 496 | .unwrap(); | 512 | .unwrap(); |
| 497 | - assert_eq!(before.get_image_file(), Some("blob_a")); | 513 | + assert_eq!(replaced.as_deref(), Some("blob_a")); |
| 498 | - let stored = read(&db, q.get_id()).await.unwrap().unwrap(); | 514 | + let stored = crate::db::pool_question_image::read(&db, q.get_id()) |
| 499 | - assert_eq!(stored.get_image_file(), Some("blob_b")); | 515 | + .await |
| 500 | - assert_eq!(stored.get_image_size(), Some(5)); | 516 | + .unwrap() |
| 501 | - | 517 | + .unwrap(); |
| 502 | - // Clearing reports the detached blob and empties the fields. | 518 | + assert_eq!(stored.get_file(), "blob_b"); |
| 503 | - let before = clear_image(&db, q.get_id()).await.unwrap().unwrap(); | 519 | + assert_eq!(stored.get_size(), 5); |
| 504 | - assert_eq!(before.get_image_file(), Some("blob_b")); | 520 | + |
| 521 | + // Clearing reports the detached blob and drops the row. | ||
| 522 | + let detached = clear_image(&db, q.get_id()).await.unwrap().unwrap(); | ||
| 523 | + assert_eq!(detached.as_deref(), Some("blob_b")); | ||
| 505 | assert!( | 524 | assert!( |
| 506 | - read(&db, q.get_id()) | 525 | + crate::db::pool_question_image::read(&db, q.get_id()) |
| 507 | .await | 526 | .await |
| 508 | .unwrap() | 527 | .unwrap() |
| 509 | - .unwrap() | ||
| 510 | - .get_image_file() | ||
| 511 | .is_none() | 528 | .is_none() |
| 512 | ); | 529 | ); |
| 513 | 530 | ||
| @@ -527,6 +544,7 @@ mod tests { | |||
| 527 | let (db, _leases) = database::init_test_db().await; | 544 | let (db, _leases) = database::init_test_db().await; |
| 528 | let asker = a_user(&db).await; | 545 | let asker = a_user(&db).await; |
| 529 | let helper = a_user(&db).await; | 546 | let helper = a_user(&db).await; |
| 547 | + let png = FileContentType::try_new("image/png").unwrap(); | ||
| 530 | 548 | ||
| 531 | let q = insert(&db, question(&asker)).await.unwrap(); | 549 | let q = insert(&db, question(&asker)).await.unwrap(); |
| 532 | let offered = crate::db::solution::insert( | 550 | let offered = crate::db::solution::insert( |
| @@ -539,13 +557,26 @@ mod tests { | |||
| 539 | ) | 557 | ) |
| 540 | .await | 558 | .await |
| 541 | .unwrap(); | 559 | .unwrap(); |
| 560 | + // Photos on both rows: their blob names must ride out with the | ||
| 561 | + // delete, or the files strand on disk forever. | ||
| 562 | + set_image(&db, q.get_id(), "q_blob", &png, 1) | ||
| 563 | + .await | ||
| 564 | + .unwrap() | ||
| 565 | + .unwrap(); | ||
| 566 | + crate::db::solution::set_image(&db, offered.get_id(), "s_blob", &png, 2) | ||
| 567 | + .await | ||
| 568 | + .unwrap() | ||
| 569 | + .unwrap(); | ||
| 542 | 570 | ||
| 543 | // The swept solutions ride back with the question so the caller can | 571 | // The swept solutions ride back with the question so the caller can |
| 544 | - // take their image blobs off disk. | 572 | + // take every image blob off disk. |
| 545 | - let (removed, swept) = delete(&db, q.get_id()).await.unwrap().unwrap(); | 573 | + let removed = delete(&db, q.get_id()).await.unwrap().unwrap(); |
| 546 | - assert_eq!(removed.get_id(), q.get_id()); | 574 | + assert_eq!(removed.question.get_id(), q.get_id()); |
| 547 | - assert_eq!(swept.len(), 1); | 575 | + assert_eq!(removed.solutions.len(), 1); |
| 548 | - assert_eq!(swept[0].get_id(), offered.get_id()); | 576 | + assert_eq!(removed.solutions[0].get_id(), offered.get_id()); |
| 577 | + assert_eq!(removed.image_files.len(), 2); | ||
| 578 | + assert!(removed.image_files.contains(&"q_blob".to_string())); | ||
| 579 | + assert!(removed.image_files.contains(&"s_blob".to_string())); | ||
| 549 | assert!(read(&db, q.get_id()).await.unwrap().is_none()); | 580 | assert!(read(&db, q.get_id()).await.unwrap().is_none()); |
| 550 | assert!( | 581 | assert!( |
| 551 | crate::db::solution::list_for(&db, q.get_id(), None, 0) | 582 | crate::db::solution::list_for(&db, q.get_id(), None, 0) |
src/db/pool_question_image.rsadded+53 -0
| @@ -0,0 +1,53 @@ | |||
| 1 | +//! The `pool_question_image` table: the reads behind the pool photo | ||
| 2 | +//! endpoints. One row per question at most (`question` is the primary key); | ||
| 3 | +//! the writes ride the question's own guarded transactions in | ||
| 4 | +//! [`crate::db::pool_question`] (`set_image`/`clear_image`/`delete`), where | ||
| 5 | +//! the pending-freeze discipline and the replaced-blob accounting live. The | ||
| 6 | +//! row's pure half lives in [`crate::domain::pool_question_image`]; the blob | ||
| 7 | +//! bytes stay the web layer's. | ||
| 8 | + | ||
| 9 | +use crate::database::Database; | ||
| 10 | +use crate::domain::note_file::FileContentType; | ||
| 11 | +use crate::domain::pool_question::PoolQuestionId; | ||
| 12 | +use crate::domain::pool_question_image::PoolQuestionImage; | ||
| 13 | +use crate::error::AppError; | ||
| 14 | + | ||
| 15 | +/// The question's photo row, if it carries one — the blob-serving read. | ||
| 16 | +pub async fn read( | ||
| 17 | + db: &Database, | ||
| 18 | + question: &PoolQuestionId, | ||
| 19 | +) -> Result<Option<PoolQuestionImage>, AppError> { | ||
| 20 | + let row = sqlx::query_as!( | ||
| 21 | + PoolQuestionImage, | ||
| 22 | + r#"SELECT question AS "question: PoolQuestionId", file, | ||
| 23 | + content_type AS "content_type: FileContentType", size | ||
| 24 | + FROM pool_question_image WHERE question = $1"#, | ||
| 25 | + question.uuid() | ||
| 26 | + ) | ||
| 27 | + .fetch_optional(db) | ||
| 28 | + .await?; | ||
| 29 | + Ok(row) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +/// The photo rows of several questions in one query — for bucketing onto a | ||
| 33 | +/// listing's *page* (one image per question at most, so a page of `n` | ||
| 34 | +/// questions reads at most `n` rows). | ||
| 35 | +pub async fn list_for_questions( | ||
| 36 | + db: &Database, | ||
| 37 | + questions: &[&PoolQuestionId], | ||
| 38 | +) -> Result<Vec<PoolQuestionImage>, AppError> { | ||
| 39 | + if questions.is_empty() { | ||
| 40 | + return Ok(Vec::new()); | ||
| 41 | + } | ||
| 42 | + let ids: Vec<uuid::Uuid> = questions.iter().map(|q| q.uuid()).collect(); | ||
| 43 | + let rows = sqlx::query_as!( | ||
| 44 | + PoolQuestionImage, | ||
| 45 | + r#"SELECT question AS "question: PoolQuestionId", file, | ||
| 46 | + content_type AS "content_type: FileContentType", size | ||
| 47 | + FROM pool_question_image WHERE question = ANY($1)"#, | ||
| 48 | + &ids | ||
| 49 | + ) | ||
| 50 | + .fetch_all(db) | ||
| 51 | + .await?; | ||
| 52 | + Ok(rows) | ||
| 53 | +} | ||
src/db/profile.rsmodified+4 -12
| @@ -79,20 +79,12 @@ pub async fn load( | |||
| 79 | mod tests { | 79 | mod tests { |
| 80 | use super::*; | 80 | use super::*; |
| 81 | use crate::database::init_test_db; | 81 | use crate::database::init_test_db; |
| 82 | - use crate::domain::user::{Password, Username}; | 82 | + use crate::domain::user::Username; |
| 83 | 83 | ||
| 84 | async fn a_user(username: &str, db: &Database) -> crate::domain::user::User { | 84 | async fn a_user(username: &str, db: &Database) -> crate::domain::user::User { |
| 85 | - crate::db::user::create( | 85 | + crate::db::user::create(db, Username::try_new(username).unwrap(), None) |
| 86 | - db, | 86 | + .await |
| 87 | - Username::try_new(username).unwrap(), | 87 | + .unwrap() |
| 88 | - Password::try_new("secret1") | ||
| 89 | - .unwrap() | ||
| 90 | - .hash_async() | ||
| 91 | - .await | ||
| 92 | - .unwrap(), | ||
| 93 | - ) | ||
| 94 | - .await | ||
| 95 | - .unwrap() | ||
| 96 | } | 88 | } |
| 97 | 89 | ||
| 98 | #[tokio::test] | 90 | #[tokio::test] |
src/db/rag_output.rsmodified+1 -1
| @@ -168,7 +168,7 @@ mod tests { | |||
| 168 | /// A real `app_user` row: the course's creator is a foreign key now. | 168 | /// A real `app_user` row: the course's creator is a foreign key now. |
| 169 | async fn a_person(db: &Database) -> crate::domain::user::UserId { | 169 | async fn a_person(db: &Database) -> crate::domain::user::UserId { |
| 170 | let user = crate::domain::user::UserId::generate(); | 170 | let user = crate::domain::user::UserId::generate(); |
| 171 | - sqlx::query("INSERT INTO app_user (id, username, password_hash) VALUES ($1, $2, 'x')") | 171 | + sqlx::query("INSERT INTO app_user (id, username, created_at) VALUES ($1, $2, 0)") |
| 172 | .bind(user.uuid()) | 172 | .bind(user.uuid()) |
| 173 | .bind(format!("rag-{}", &user.key()[30..])) | 173 | .bind(format!("rag-{}", &user.key()[30..])) |
| 174 | .execute(db) | 174 | .execute(db) |
src/db/registration.rsmodified+6 -3
| @@ -7,6 +7,7 @@ use crate::database::{Database, tx_with_retry, unique_violation}; | |||
| 7 | use crate::db::cap::Claimed; | 7 | use crate::db::cap::Claimed; |
| 8 | use crate::domain::event::EventId; | 8 | use crate::domain::event::EventId; |
| 9 | use crate::domain::registration::Registration; | 9 | use crate::domain::registration::Registration; |
| 10 | +use crate::domain::timestamp::Timestamp; | ||
| 10 | use crate::domain::user::UserId; | 11 | use crate::domain::user::UserId; |
| 11 | use crate::error::AppError; | 12 | use crate::error::AppError; |
| 12 | use sqlx::query_as; | 13 | use sqlx::query_as; |
| @@ -67,6 +68,7 @@ pub(crate) async fn claim_seat( | |||
| 67 | user: &UserId, | 68 | user: &UserId, |
| 68 | registered_by: &UserId, | 69 | registered_by: &UserId, |
| 69 | ) -> Result<Claimed<Registration>, AppError> { | 70 | ) -> Result<Claimed<Registration>, AppError> { |
| 71 | + let created_at = Timestamp::now().as_millis(); | ||
| 70 | match query_as!( | 72 | match query_as!( |
| 71 | Registration, | 73 | Registration, |
| 72 | "WITH person AS ( | 74 | "WITH person AS ( |
| @@ -83,13 +85,14 @@ pub(crate) async fn claim_seat( | |||
| 83 | AND (audience_capacity IS NULL OR registration_count < audience_capacity) | 85 | AND (audience_capacity IS NULL OR registration_count < audience_capacity) |
| 84 | AND EXISTS (SELECT 1 FROM person) | 86 | AND EXISTS (SELECT 1 FROM person) |
| 85 | RETURNING 1) | 87 | RETURNING 1) |
| 86 | - INSERT INTO registration (event, app_user, registered_by) | 88 | + INSERT INTO registration (event, app_user, registered_by, created_at) |
| 87 | - SELECT $1, $2, $3 | 89 | + SELECT $1, $2, $3, $4 |
| 88 | WHERE EXISTS (SELECT 1 FROM seat) | 90 | WHERE EXISTS (SELECT 1 FROM seat) |
| 89 | RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", | 91 | RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", |
| 90 | event.uuid(), | 92 | event.uuid(), |
| 91 | user.uuid(), | 93 | user.uuid(), |
| 92 | - registered_by.uuid() | 94 | + registered_by.uuid(), |
| 95 | + created_at, | ||
| 93 | ) | 96 | ) |
| 94 | .fetch_optional(db) | 97 | .fetch_optional(db) |
| 95 | .await | 98 | .await |
src/db/session.rsmodified+2 -2
| @@ -92,8 +92,8 @@ mod tests { | |||
| 92 | // under the fixture's fixed key, then two rows either side of `now`. | 92 | // under the fixture's fixed key, then two rows either side of `now`. |
| 93 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cab0"); | 93 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cab0"); |
| 94 | sqlx::query( | 94 | sqlx::query( |
| 95 | - "INSERT INTO app_user (id, username, password_hash) \ | 95 | + "INSERT INTO app_user (id, username, created_at) \ |
| 96 | - VALUES ($1, 'purge-fixture', 'x')", | 96 | + VALUES ($1, 'purge-fixture', 0)", |
| 97 | ) | 97 | ) |
| 98 | .bind(user.uuid()) | 98 | .bind(user.uuid()) |
| 99 | .execute(&db) | 99 | .execute(&db) |
src/db/session_attendance.rsmodified+7 -5
| @@ -130,10 +130,11 @@ pub async fn mark( | |||
| 130 | .unwrap_or(false); | 130 | .unwrap_or(false); |
| 131 | let row = sqlx::query_as!( | 131 | let row = sqlx::query_as!( |
| 132 | SessionAttendance, | 132 | SessionAttendance, |
| 133 | - r#"INSERT INTO session_attendance (session, app_user, course, status, marked_by) | 133 | + r#"INSERT INTO session_attendance (session, app_user, course, status, marked_by, marked_at) |
| 134 | - VALUES ($1, $2, $3, $4, $5) | 134 | + VALUES ($1, $2, $3, $4, $5, $6) |
| 135 | ON CONFLICT (session, app_user) DO UPDATE | 135 | ON CONFLICT (session, app_user) DO UPDATE |
| 136 | - SET status = EXCLUDED.status, marked_by = EXCLUDED.marked_by | 136 | + SET status = EXCLUDED.status, marked_by = EXCLUDED.marked_by, |
| 137 | + marked_at = EXCLUDED.marked_at | ||
| 137 | RETURNING session AS "session: CourseSessionId", app_user AS "user: UserId", | 138 | RETURNING session AS "session: CourseSessionId", app_user AS "user: UserId", |
| 138 | course AS "course: CourseId", status AS "status: AttendanceStatus", | 139 | course AS "course: CourseId", status AS "status: AttendanceStatus", |
| 139 | marked_by AS "marked_by: UserId""#, | 140 | marked_by AS "marked_by: UserId""#, |
| @@ -142,6 +143,7 @@ pub async fn mark( | |||
| 142 | session.course.uuid(), | 143 | session.course.uuid(), |
| 143 | status.as_str(), | 144 | status.as_str(), |
| 144 | marked_by.uuid(), | 145 | marked_by.uuid(), |
| 146 | + now.as_millis(), | ||
| 145 | ) | 147 | ) |
| 146 | .fetch_one(&mut *tx) | 148 | .fetch_one(&mut *tx) |
| 147 | .await?; | 149 | .await?; |
| @@ -311,8 +313,8 @@ mod tests { | |||
| 311 | // keeps repeated calls (same label, new person) collision-free. | 313 | // keeps repeated calls (same label, new person) collision-free. |
| 312 | let user = UserId::generate(); | 314 | let user = UserId::generate(); |
| 313 | sqlx::query( | 315 | sqlx::query( |
| 314 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 316 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 315 | - VALUES ($1, $2, 'x', $3)", | 317 | + VALUES ($1, $2, 0, $3)", |
| 316 | ) | 318 | ) |
| 317 | .bind(user.uuid()) | 319 | .bind(user.uuid()) |
| 318 | .bind(format!("{key}-{}", &user.key()[30..])) | 320 | .bind(format!("{key}-{}", &user.key()[30..])) |
src/db/solution.rsmodified+99 -85
| @@ -33,9 +33,7 @@ pub async fn insert(db: &Database, solution: Solution) -> Result<Solution, AppEr | |||
| 33 | VALUES ($1, $2, $3, $4, $5) | 33 | VALUES ($1, $2, $3, $4, $5) |
| 34 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", | 34 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", |
| 35 | author AS "author: UserId", body AS "body: SolutionBody", | 35 | author AS "author: UserId", body AS "body: SolutionBody", |
| 36 | - offered_at AS "offered_at: Timestamp", image_file, | 36 | + offered_at AS "offered_at: Timestamp""#, |
| 37 | - image_content_type AS "image_content_type: FileContentType", | ||
| 38 | - image_size"#, | ||
| 39 | solution.id.uuid(), | 37 | solution.id.uuid(), |
| 40 | solution.question.uuid(), | 38 | solution.question.uuid(), |
| 41 | solution.author.uuid(), | 39 | solution.author.uuid(), |
| @@ -68,9 +66,7 @@ pub async fn read_for( | |||
| 68 | Solution, | 66 | Solution, |
| 69 | r#"SELECT id AS "id: SolutionId", question AS "question: PoolQuestionId", | 67 | r#"SELECT id AS "id: SolutionId", question AS "question: PoolQuestionId", |
| 70 | author AS "author: UserId", body AS "body: SolutionBody", | 68 | author AS "author: UserId", body AS "body: SolutionBody", |
| 71 | - offered_at AS "offered_at: Timestamp", image_file, | 69 | + offered_at AS "offered_at: Timestamp" |
| 72 | - image_content_type AS "image_content_type: FileContentType", | ||
| 73 | - image_size | ||
| 74 | FROM solution WHERE id = $1 AND question = $2"#, | 70 | FROM solution WHERE id = $1 AND question = $2"#, |
| 75 | id.uuid(), | 71 | id.uuid(), |
| 76 | question.uuid() | 72 | question.uuid() |
| @@ -140,9 +136,7 @@ pub async fn set_body( | |||
| 140 | r#"UPDATE solution SET body = $2 WHERE id = $1 | 136 | r#"UPDATE solution SET body = $2 WHERE id = $1 |
| 141 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", | 137 | RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", |
| 142 | author AS "author: UserId", body AS "body: SolutionBody", | 138 | author AS "author: UserId", body AS "body: SolutionBody", |
| 143 | - offered_at AS "offered_at: Timestamp", image_file, | 139 | + offered_at AS "offered_at: Timestamp""#, |
| 144 | - image_content_type AS "image_content_type: FileContentType", | ||
| 145 | - image_size"#, | ||
| 146 | id.uuid(), | 140 | id.uuid(), |
| 147 | body.as_str() | 141 | body.as_str() |
| 148 | ) | 142 | ) |
| @@ -152,104 +146,124 @@ pub async fn set_body( | |||
| 152 | } | 146 | } |
| 153 | 147 | ||
| 154 | /// Point the solution at a freshly written image blob. Unconditional for | 148 | /// Point the solution at a freshly written image blob. Unconditional for |
| 155 | -/// the same reason as [`set_body`]. Returns the *before* row — its | 149 | +/// the same reason as [`set_body`]. `Ok(None)` means the row was deleted |
| 156 | -/// `image_file` is the replaced blob the caller must remove; `None` means | 150 | +/// mid-flight (the fresh blob is the caller's orphan to take back off |
| 157 | -/// the row was deleted mid-flight (the fresh blob is the caller's orphan | 151 | +/// disk); `Ok(Some(replaced))` names the blob this upload displaced — the |
| 158 | -/// to take back off disk). | 152 | +/// caller's to remove, `None` inside when nothing was there before. |
| 159 | /// | 153 | /// |
| 160 | -/// The row lock makes the before-read and the write one switch, so two | 154 | +/// The photo is its own row in `solution_image` (the child-table shape of |
| 161 | -/// racing uploads can never both be told they replaced the same blob. | 155 | +/// `question_image`), so the write is that row's upsert; the parent's |
| 156 | +/// `FOR UPDATE` row lock still makes the before-read and the write one | ||
| 157 | +/// switch, so two racing uploads can never both be told they replaced the | ||
| 158 | +/// same blob — the loser re-reads the winner's blob name, the discipline | ||
| 159 | +/// `crate::db::question_image::upsert` documents. | ||
| 162 | pub async fn set_image( | 160 | pub async fn set_image( |
| 163 | db: &Database, | 161 | db: &Database, |
| 164 | id: &SolutionId, | 162 | id: &SolutionId, |
| 165 | file: &str, | 163 | file: &str, |
| 166 | content_type: &FileContentType, | 164 | content_type: &FileContentType, |
| 167 | size: i64, | 165 | size: i64, |
| 168 | -) -> Result<Option<Solution>, AppError> { | 166 | +) -> Result<Option<Option<String>>, AppError> { |
| 169 | // Owned captures (`Send` rule of `tx_with_retry` closures). | 167 | // Owned captures (`Send` rule of `tx_with_retry` closures). |
| 170 | let id = *id; | 168 | let id = *id; |
| 171 | let file = file.to_owned(); | 169 | let file = file.to_owned(); |
| 172 | let content_type = content_type.clone(); | 170 | let content_type = content_type.clone(); |
| 173 | tx_with_retry(db, false, async move |tx| { | 171 | tx_with_retry(db, false, async move |tx| { |
| 174 | - let before = sqlx::query_as!( | 172 | + let before = sqlx::query!( |
| 175 | - Solution, | 173 | + r#"SELECT id FROM solution WHERE id = $1 FOR UPDATE"#, |
| 176 | - r#"SELECT id AS "id: SolutionId", question AS "question: PoolQuestionId", | ||
| 177 | - author AS "author: UserId", body AS "body: SolutionBody", | ||
| 178 | - offered_at AS "offered_at: Timestamp", image_file, | ||
| 179 | - image_content_type AS "image_content_type: FileContentType", | ||
| 180 | - image_size | ||
| 181 | - FROM solution WHERE id = $1 FOR UPDATE"#, | ||
| 182 | id.uuid() | 174 | id.uuid() |
| 183 | ) | 175 | ) |
| 184 | .fetch_optional(&mut *tx) | 176 | .fetch_optional(&mut *tx) |
| 185 | .await?; | 177 | .await?; |
| 186 | - let Some(before) = before else { | 178 | + if before.is_none() { |
| 187 | return Ok(None); | 179 | return Ok(None); |
| 188 | - }; | 180 | + } |
| 181 | + let replaced = sqlx::query_scalar!( | ||
| 182 | + r#"SELECT file FROM solution_image WHERE solution = $1"#, | ||
| 183 | + id.uuid() | ||
| 184 | + ) | ||
| 185 | + .fetch_optional(&mut *tx) | ||
| 186 | + .await?; | ||
| 189 | sqlx::query!( | 187 | sqlx::query!( |
| 190 | - r#"UPDATE solution | 188 | + r#"INSERT INTO solution_image (solution, file, content_type, size) |
| 191 | - SET image_file = $2, image_content_type = $3, image_size = $4 | 189 | + VALUES ($1, $2, $3, $4) |
| 192 | - WHERE id = $1"#, | 190 | + ON CONFLICT (solution) DO UPDATE |
| 191 | + SET file = EXCLUDED.file, content_type = EXCLUDED.content_type, | ||
| 192 | + size = EXCLUDED.size"#, | ||
| 193 | id.uuid(), | 193 | id.uuid(), |
| 194 | - file.as_str(), | 194 | + file, |
| 195 | content_type.as_str(), | 195 | content_type.as_str(), |
| 196 | size, | 196 | size, |
| 197 | ) | 197 | ) |
| 198 | .execute(&mut *tx) | 198 | .execute(&mut *tx) |
| 199 | .await?; | 199 | .await?; |
| 200 | - Ok(Some(before)) | 200 | + Ok(Some(replaced)) |
| 201 | }) | 201 | }) |
| 202 | .await | 202 | .await |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | -/// Detach the solution's image. Returns the *before* row — its | 205 | +/// Detach the solution's image. `Ok(None)` = the row was deleted mid-flight; |
| 206 | -/// `image_file` is the blob the caller must remove. | 206 | +/// `Ok(Some(detached))` names the blob the caller removes — `None` inside |
| 207 | -pub async fn clear_image(db: &Database, id: &SolutionId) -> Result<Option<Solution>, AppError> { | 207 | +/// when the solution carried no image (the route answers that 404). |
| 208 | +pub async fn clear_image( | ||
| 209 | + db: &Database, | ||
| 210 | + id: &SolutionId, | ||
| 211 | +) -> Result<Option<Option<String>>, AppError> { | ||
| 208 | // Owned capture (`Send` rule of `tx_with_retry` closures). | 212 | // Owned capture (`Send` rule of `tx_with_retry` closures). |
| 209 | let id = *id; | 213 | let id = *id; |
| 210 | tx_with_retry(db, false, async move |tx| { | 214 | tx_with_retry(db, false, async move |tx| { |
| 211 | - let before = sqlx::query_as!( | 215 | + let before = sqlx::query!( |
| 212 | - Solution, | 216 | + r#"SELECT id FROM solution WHERE id = $1 FOR UPDATE"#, |
| 213 | - r#"SELECT id AS "id: SolutionId", question AS "question: PoolQuestionId", | ||
| 214 | - author AS "author: UserId", body AS "body: SolutionBody", | ||
| 215 | - offered_at AS "offered_at: Timestamp", image_file, | ||
| 216 | - image_content_type AS "image_content_type: FileContentType", | ||
| 217 | - image_size | ||
| 218 | - FROM solution WHERE id = $1 FOR UPDATE"#, | ||
| 219 | id.uuid() | 217 | id.uuid() |
| 220 | ) | 218 | ) |
| 221 | .fetch_optional(&mut *tx) | 219 | .fetch_optional(&mut *tx) |
| 222 | .await?; | 220 | .await?; |
| 223 | - let Some(before) = before else { | 221 | + if before.is_none() { |
| 224 | return Ok(None); | 222 | return Ok(None); |
| 225 | - }; | 223 | + } |
| 226 | - sqlx::query!( | 224 | + let detached = sqlx::query_scalar!( |
| 227 | - r#"UPDATE solution | 225 | + r#"DELETE FROM solution_image WHERE solution = $1 RETURNING file"#, |
| 228 | - SET image_file = NULL, image_content_type = NULL, image_size = NULL | 226 | + id.uuid() |
| 229 | - WHERE id = $1"#, | ||
| 230 | - id.uuid(), | ||
| 231 | ) | 227 | ) |
| 232 | - .execute(&mut *tx) | 228 | + .fetch_optional(&mut *tx) |
| 233 | .await?; | 229 | .await?; |
| 234 | - Ok(Some(before)) | 230 | + Ok(Some(detached)) |
| 235 | }) | 231 | }) |
| 236 | .await | 232 | .await |
| 237 | } | 233 | } |
| 238 | 234 | ||
| 239 | -pub async fn delete(db: &Database, solution: Solution) -> Result<Solution, AppError> { | 235 | +/// Delete a solution, returning the row plus the blob name of the photo it |
| 240 | - let deleted = sqlx::query_as!( | 236 | +/// carried (the caller's disk-GC list — one entry at most). The photo row |
| 241 | - Solution, | 237 | +/// goes first: its foreign key is `NO ACTION`, so it cannot outlive being |
| 242 | - r#"DELETE FROM solution WHERE id = $1 | 238 | +/// pointed at, and its file name is read on the way out, under the same |
| 243 | - RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", | 239 | +/// transaction — a photo uploaded by a racing `set_image` loses the row |
| 244 | - author AS "author: UserId", body AS "body: SolutionBody", | 240 | +/// lock to this delete and comes back as the caller's orphan. |
| 245 | - offered_at AS "offered_at: Timestamp", image_file, | 241 | +pub async fn delete( |
| 246 | - image_content_type AS "image_content_type: FileContentType", | 242 | + db: &Database, |
| 247 | - image_size"#, | 243 | + solution: Solution, |
| 248 | - solution.id.uuid() | 244 | +) -> Result<Option<(Solution, Option<String>)>, AppError> { |
| 249 | - ) | 245 | + // Owned capture (`Send` rule of `tx_with_retry` closures). |
| 250 | - .fetch_optional(db) | 246 | + let id = *solution.get_id(); |
| 251 | - .await?; | 247 | + tx_with_retry(db, false, async move |tx| { |
| 252 | - deleted.ok_or(AppError::NotFound) | 248 | + let image = sqlx::query_scalar!( |
| 249 | + r#"DELETE FROM solution_image WHERE solution = $1 RETURNING file"#, | ||
| 250 | + id.uuid() | ||
| 251 | + ) | ||
| 252 | + .fetch_optional(&mut *tx) | ||
| 253 | + .await?; | ||
| 254 | + let deleted = sqlx::query_as!( | ||
| 255 | + Solution, | ||
| 256 | + r#"DELETE FROM solution WHERE id = $1 | ||
| 257 | + RETURNING id AS "id: SolutionId", question AS "question: PoolQuestionId", | ||
| 258 | + author AS "author: UserId", body AS "body: SolutionBody", | ||
| 259 | + offered_at AS "offered_at: Timestamp""#, | ||
| 260 | + id.uuid() | ||
| 261 | + ) | ||
| 262 | + .fetch_optional(&mut *tx) | ||
| 263 | + .await?; | ||
| 264 | + Ok(deleted.map(|deleted| (deleted, image))) | ||
| 265 | + }) | ||
| 266 | + .await | ||
| 253 | } | 267 | } |
| 254 | 268 | ||
| 255 | #[cfg(test)] | 269 | #[cfg(test)] |
| @@ -264,8 +278,8 @@ mod tests { | |||
| 264 | async fn a_person(db: &Database, label: &str) -> UserId { | 278 | async fn a_person(db: &Database, label: &str) -> UserId { |
| 265 | let user = UserId::generate(); | 279 | let user = UserId::generate(); |
| 266 | sqlx::query( | 280 | sqlx::query( |
| 267 | - "INSERT INTO app_user (id, username, password_hash) \ | 281 | + "INSERT INTO app_user (id, username, created_at) \ |
| 268 | - VALUES ($1, $2, 'x')", | 282 | + VALUES ($1, $2, 0)", |
| 269 | ) | 283 | ) |
| 270 | .bind(user.uuid()) | 284 | .bind(user.uuid()) |
| 271 | .bind(format!("{label}-{}", &user.key()[30..])) | 285 | .bind(format!("{label}-{}", &user.key()[30..])) |
| @@ -345,7 +359,10 @@ mod tests { | |||
| 345 | .is_none() | 359 | .is_none() |
| 346 | ); | 360 | ); |
| 347 | 361 | ||
| 348 | - delete(&db, first).await.unwrap(); | 362 | + let first_id = *first.get_id(); |
| 363 | + let (deleted, image) = delete(&db, first).await.unwrap().unwrap(); | ||
| 364 | + assert_eq!(deleted.get_id(), &first_id); | ||
| 365 | + assert!(image.is_none()); | ||
| 349 | assert_eq!( | 366 | assert_eq!( |
| 350 | list_for(&db, &question_a, None, 0).await.unwrap().0.len(), | 367 | list_for(&db, &question_a, None, 0).await.unwrap().0.len(), |
| 351 | 1 | 368 | 1 |
| @@ -370,40 +387,39 @@ mod tests { | |||
| 370 | .await | 387 | .await |
| 371 | .unwrap(); | 388 | .unwrap(); |
| 372 | 389 | ||
| 373 | - let before = set_image(&db, solution.get_id(), "blob_a", &png, 3) | 390 | + let replaced = set_image(&db, solution.get_id(), "blob_a", &png, 3) |
| 374 | .await | 391 | .await |
| 375 | .unwrap() | 392 | .unwrap() |
| 376 | .unwrap(); | 393 | .unwrap(); |
| 377 | - assert!(before.get_image_file().is_none()); | 394 | + assert!(replaced.is_none()); |
| 378 | 395 | ||
| 379 | // A replace reports the old blob for cleanup. | 396 | // A replace reports the old blob for cleanup. |
| 380 | - let before = set_image(&db, solution.get_id(), "blob_b", &png, 5) | 397 | + let replaced = set_image(&db, solution.get_id(), "blob_b", &png, 5) |
| 381 | .await | 398 | .await |
| 382 | .unwrap() | 399 | .unwrap() |
| 383 | .unwrap(); | 400 | .unwrap(); |
| 384 | - assert_eq!(before.get_image_file(), Some("blob_a")); | 401 | + assert_eq!(replaced.as_deref(), Some("blob_a")); |
| 385 | - let stored = read_for(&db, solution.get_id(), &question) | 402 | + let stored = crate::db::solution_image::read(&db, solution.get_id()) |
| 386 | .await | 403 | .await |
| 387 | .unwrap() | 404 | .unwrap() |
| 388 | .unwrap(); | 405 | .unwrap(); |
| 389 | - assert_eq!(stored.get_image_file(), Some("blob_b")); | 406 | + assert_eq!(stored.get_file(), "blob_b"); |
| 390 | - assert_eq!(stored.get_image_size(), Some(5)); | 407 | + assert_eq!(stored.get_size(), 5); |
| 391 | 408 | ||
| 392 | - // Clearing reports the detached blob and empties the fields. | 409 | + // Clearing reports the detached blob and drops the row. |
| 393 | - let before = clear_image(&db, solution.get_id()).await.unwrap().unwrap(); | 410 | + let detached = clear_image(&db, solution.get_id()).await.unwrap().unwrap(); |
| 394 | - assert_eq!(before.get_image_file(), Some("blob_b")); | 411 | + assert_eq!(detached.as_deref(), Some("blob_b")); |
| 395 | assert!( | 412 | assert!( |
| 396 | - read_for(&db, solution.get_id(), &question) | 413 | + crate::db::solution_image::read(&db, solution.get_id()) |
| 397 | .await | 414 | .await |
| 398 | .unwrap() | 415 | .unwrap() |
| 399 | - .unwrap() | ||
| 400 | - .get_image_file() | ||
| 401 | .is_none() | 416 | .is_none() |
| 402 | ); | 417 | ); |
| 403 | 418 | ||
| 404 | // A row deleted mid-flight surfaces as None, not an error. | 419 | // A row deleted mid-flight surfaces as None, not an error. |
| 405 | - let deleted = delete(&db, solution.clone()).await.unwrap(); | 420 | + let (deleted, image) = delete(&db, solution.clone()).await.unwrap().unwrap(); |
| 406 | assert_eq!(deleted.get_id(), solution.get_id()); | 421 | assert_eq!(deleted.get_id(), solution.get_id()); |
| 422 | + assert!(image.is_none()); | ||
| 407 | assert!( | 423 | assert!( |
| 408 | set_image(&db, solution.get_id(), "blob_c", &png, 7) | 424 | set_image(&db, solution.get_id(), "blob_c", &png, 7) |
| 409 | .await | 425 | .await |
| @@ -473,9 +489,7 @@ mod tests { | |||
| 473 | } | 489 | } |
| 474 | } | 490 | } |
| 475 | 491 | ||
| 476 | - let counts = counts_for(&db, &[two, one, none]) | 492 | + let counts = counts_for(&db, &[two, one, none]).await.unwrap(); |
| 477 | - .await | ||
| 478 | - .unwrap(); | ||
| 479 | assert_eq!(counts.get(two.key().as_str()), Some(&2)); | 493 | assert_eq!(counts.get(two.key().as_str()), Some(&2)); |
| 480 | assert_eq!(counts.get(one.key().as_str()), Some(&1)); | 494 | assert_eq!(counts.get(one.key().as_str()), Some(&1)); |
| 481 | // No solutions = no entry; the caller reads the miss as zero. | 495 | // No solutions = no entry; the caller reads the miss as zero. |
src/db/solution_image.rsadded+49 -0
| @@ -0,0 +1,49 @@ | |||
| 1 | +//! The `solution_image` table: the reads behind the solution photo | ||
| 2 | +//! endpoints. One row per solution at most (`solution` is the primary key); | ||
| 3 | +//! the writes ride the solution's own transactions in | ||
| 4 | +//! [`crate::db::solution`] (`set_image`/`clear_image`/`delete`), where the | ||
| 5 | +//! replaced-blob accounting lives. The row's pure half lives in | ||
| 6 | +//! [`crate::domain::solution_image`]; the blob bytes stay the web layer's. | ||
| 7 | + | ||
| 8 | +use crate::database::Database; | ||
| 9 | +use crate::domain::note_file::FileContentType; | ||
| 10 | +use crate::domain::solution::SolutionId; | ||
| 11 | +use crate::domain::solution_image::SolutionImage; | ||
| 12 | +use crate::error::AppError; | ||
| 13 | + | ||
| 14 | +/// The solution's photo row, if it carries one — the blob-serving read. | ||
| 15 | +pub async fn read(db: &Database, solution: &SolutionId) -> Result<Option<SolutionImage>, AppError> { | ||
| 16 | + let row = sqlx::query_as!( | ||
| 17 | + SolutionImage, | ||
| 18 | + r#"SELECT solution AS "solution: SolutionId", file, | ||
| 19 | + content_type AS "content_type: FileContentType", size | ||
| 20 | + FROM solution_image WHERE solution = $1"#, | ||
| 21 | + solution.uuid() | ||
| 22 | + ) | ||
| 23 | + .fetch_optional(db) | ||
| 24 | + .await?; | ||
| 25 | + Ok(row) | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +/// The photo rows of several solutions in one query — for bucketing onto a | ||
| 29 | +/// listing's *page* (one image per solution at most, so a page of `n` | ||
| 30 | +/// solutions reads at most `n` rows). | ||
| 31 | +pub async fn list_for_solutions( | ||
| 32 | + db: &Database, | ||
| 33 | + solutions: &[&SolutionId], | ||
| 34 | +) -> Result<Vec<SolutionImage>, AppError> { | ||
| 35 | + if solutions.is_empty() { | ||
| 36 | + return Ok(Vec::new()); | ||
| 37 | + } | ||
| 38 | + let ids: Vec<uuid::Uuid> = solutions.iter().map(|s| s.uuid()).collect(); | ||
| 39 | + let rows = sqlx::query_as!( | ||
| 40 | + SolutionImage, | ||
| 41 | + r#"SELECT solution AS "solution: SolutionId", file, | ||
| 42 | + content_type AS "content_type: FileContentType", size | ||
| 43 | + FROM solution_image WHERE solution = ANY($1)"#, | ||
| 44 | + &ids | ||
| 45 | + ) | ||
| 46 | + .fetch_all(db) | ||
| 47 | + .await?; | ||
| 48 | + Ok(rows) | ||
| 49 | +} | ||
src/db/term.rsmodified+2 -2
| @@ -274,8 +274,8 @@ mod tests { | |||
| 274 | // every create in every round. | 274 | // every create in every round. |
| 275 | let teacher = UserId::generate(); | 275 | let teacher = UserId::generate(); |
| 276 | sqlx::query( | 276 | sqlx::query( |
| 277 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 277 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 278 | - VALUES ($1, $2, 'x', 'teacher')", | 278 | + VALUES ($1, $2, 0, 'teacher')", |
| 279 | ) | 279 | ) |
| 280 | .bind(teacher.uuid()) | 280 | .bind(teacher.uuid()) |
| 281 | .bind(format!("term-race-{}", &teacher.key()[30..])) | 281 | .bind(format!("term-race-{}", &teacher.key()[30..])) |
src/db/user.rsmodified+67 -75
| @@ -13,23 +13,27 @@ use crate::db::field_update::FieldUpdate; | |||
| 13 | use crate::db::page::{PagedList, Param}; | 13 | use crate::db::page::{PagedList, Param}; |
| 14 | use crate::domain::board::{Board, BoardId, BoardTitle}; | 14 | use crate::domain::board::{Board, BoardId, BoardTitle}; |
| 15 | use crate::domain::note_file::FileContentType; | 15 | use crate::domain::note_file::FileContentType; |
| 16 | +use crate::domain::person::PersonId; | ||
| 16 | use crate::domain::preferences::{Language, PaletteColor, Theme}; | 17 | use crate::domain::preferences::{Language, PaletteColor, Theme}; |
| 17 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; | 18 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; |
| 18 | use crate::domain::role::Role; | 19 | use crate::domain::role::Role; |
| 19 | use crate::domain::text_fold::{search_fold, search_fold_sql}; | 20 | use crate::domain::text_fold::{search_fold, search_fold_sql}; |
| 20 | use crate::domain::timestamp::Timestamp; | 21 | use crate::domain::timestamp::Timestamp; |
| 21 | -use crate::domain::user::{PasswordHash, User, UserId, Username}; | 22 | +use crate::domain::user::{User, UserId, Username}; |
| 22 | use crate::error::AppError; | 23 | use crate::error::AppError; |
| 23 | 24 | ||
| 24 | -/// Register a new account. New users always start as [`Role::Student`]; | 25 | +/// Register a new school account for the control-plane `person` whose |
| 25 | -/// elevation is a separate, admin-only action | 26 | +/// credential login verifies — `person` is the join key, `None` only where the |
| 27 | +/// caller cannot know it yet (tests, the boot seed's row-first order — see | ||
| 28 | +/// [`crate::service::user::ensure_admin`]). New users always start as | ||
| 29 | +/// [`Role::Student`]; elevation is a separate, admin-only action | ||
| 26 | /// (see [`crate::service::user::set_role`]). | 30 | /// (see [`crate::service::user::set_role`]). |
| 27 | pub async fn create( | 31 | pub async fn create( |
| 28 | db: &Database, | 32 | db: &Database, |
| 29 | username: Username, | 33 | username: Username, |
| 30 | - password_hash: PasswordHash, | 34 | + person: Option<PersonId>, |
| 31 | ) -> Result<User, AppError> { | 35 | ) -> Result<User, AppError> { |
| 32 | - create_with_role(db, username, password_hash, Role::Student).await | 36 | + create_with_role(db, username, person, Role::Student).await |
| 33 | } | 37 | } |
| 34 | 38 | ||
| 35 | /// The one row-minting path. `role` is written *with* the row rather than | 39 | /// The one row-minting path. `role` is written *with* the row rather than |
| @@ -44,20 +48,23 @@ pub async fn create( | |||
| 44 | /// the constraint a racing insert had violated; here the violated | 48 | /// the constraint a racing insert had violated; here the violated |
| 45 | /// constraint's name answers directly (`app_user_username`), and the loser | 49 | /// constraint's name answers directly (`app_user_username`), and the loser |
| 46 | /// of a race gets the same 409 the sequential duplicate always got. | 50 | /// of a race gets the same 409 the sequential duplicate always got. |
| 51 | +/// | ||
| 52 | +/// The row carries its `created_at` mint stamp and, when the caller knows it, | ||
| 53 | +/// the `person` id the credential lives on. | ||
| 47 | pub async fn create_with_role( | 54 | pub async fn create_with_role( |
| 48 | db: &Database, | 55 | db: &Database, |
| 49 | username: Username, | 56 | username: Username, |
| 50 | - password_hash: PasswordHash, | 57 | + person: Option<PersonId>, |
| 51 | role: Role, | 58 | role: Role, |
| 52 | ) -> Result<User, AppError> { | 59 | ) -> Result<User, AppError> { |
| 53 | let id = UserId::generate(); | 60 | let id = UserId::generate(); |
| 54 | match sqlx::query_as!( | 61 | match sqlx::query_as!( |
| 55 | User, | 62 | User, |
| 56 | - r#"INSERT INTO app_user (id, username, password_hash, role) | 63 | + r#"INSERT INTO app_user (id, username, person, role, created_at) |
| 57 | - VALUES ($1, $2, $3, $4) | 64 | + VALUES ($1, $2, $3, $4, $5) |
| 58 | RETURNING id AS "id: UserId", | 65 | RETURNING id AS "id: UserId", |
| 59 | username AS "username: Username", | 66 | username AS "username: Username", |
| 60 | - password_hash AS "password_hash: PasswordHash", | 67 | + person AS "person: PersonId", |
| 61 | role AS "role: Role", | 68 | role AS "role: Role", |
| 62 | name AS "name: PersonName", | 69 | name AS "name: PersonName", |
| 63 | surname AS "surname: PersonName", | 70 | surname AS "surname: PersonName", |
| @@ -74,13 +81,20 @@ pub async fn create_with_role( | |||
| 74 | avatar_size"#, | 81 | avatar_size"#, |
| 75 | id.uuid(), | 82 | id.uuid(), |
| 76 | username.as_str(), | 83 | username.as_str(), |
| 77 | - password_hash.as_str(), | 84 | + person.as_ref().map(PersonId::uuid), |
| 78 | role.as_str(), | 85 | role.as_str(), |
| 86 | + Timestamp::now().as_millis(), | ||
| 79 | ) | 87 | ) |
| 80 | .fetch_one(db) | 88 | .fetch_one(db) |
| 81 | .await | 89 | .await |
| 82 | { | 90 | { |
| 83 | - Ok(user) => Ok(user), | 91 | + Ok(user) => { |
| 92 | + debug_assert_eq!( | ||
| 93 | + user.get_person().map(PersonId::uuid), | ||
| 94 | + person.as_ref().map(PersonId::uuid) | ||
| 95 | + ); | ||
| 96 | + Ok(user) | ||
| 97 | + } | ||
| 84 | Err(err) if crate::database::unique_violation(&err) == Some("app_user_username") => { | 98 | Err(err) if crate::database::unique_violation(&err) == Some("app_user_username") => { |
| 85 | Err(AppError::Conflict("username already taken")) | 99 | Err(AppError::Conflict("username already taken")) |
| 86 | } | 100 | } |
| @@ -93,7 +107,7 @@ pub async fn read(db: &Database, id: &UserId) -> Result<Option<User>, AppError> | |||
| 93 | User, | 107 | User, |
| 94 | r#"SELECT id AS "id: UserId", | 108 | r#"SELECT id AS "id: UserId", |
| 95 | username AS "username: Username", | 109 | username AS "username: Username", |
| 96 | - password_hash AS "password_hash: PasswordHash", | 110 | + person AS "person: PersonId", |
| 97 | role AS "role: Role", | 111 | role AS "role: Role", |
| 98 | name AS "name: PersonName", | 112 | name AS "name: PersonName", |
| 99 | surname AS "surname: PersonName", | 113 | surname AS "surname: PersonName", |
| @@ -137,7 +151,7 @@ pub async fn list_by_ids(db: &Database, ids: &[UserId]) -> Result<Vec<User>, App | |||
| 137 | User, | 151 | User, |
| 138 | r#"SELECT id AS "id: UserId", | 152 | r#"SELECT id AS "id: UserId", |
| 139 | username AS "username: Username", | 153 | username AS "username: Username", |
| 140 | - password_hash AS "password_hash: PasswordHash", | 154 | + person AS "person: PersonId", |
| 141 | role AS "role: Role", | 155 | role AS "role: Role", |
| 142 | name AS "name: PersonName", | 156 | name AS "name: PersonName", |
| 143 | surname AS "surname: PersonName", | 157 | surname AS "surname: PersonName", |
| @@ -168,7 +182,7 @@ pub async fn list_by_role(db: &Database, role: Role) -> Result<Vec<User>, AppErr | |||
| 168 | User, | 182 | User, |
| 169 | r#"SELECT id AS "id: UserId", | 183 | r#"SELECT id AS "id: UserId", |
| 170 | username AS "username: Username", | 184 | username AS "username: Username", |
| 171 | - password_hash AS "password_hash: PasswordHash", | 185 | + person AS "person: PersonId", |
| 172 | role AS "role: Role", | 186 | role AS "role: Role", |
| 173 | name AS "name: PersonName", | 187 | name AS "name: PersonName", |
| 174 | surname AS "surname: PersonName", | 188 | surname AS "surname: PersonName", |
| @@ -389,7 +403,7 @@ pub async fn set_role_cascade( | |||
| 389 | WHERE role = 'admin' AND id <> $1) = 0) | 403 | WHERE role = 'admin' AND id <> $1) = 0) |
| 390 | RETURNING id AS "id: UserId", | 404 | RETURNING id AS "id: UserId", |
| 391 | username AS "username: Username", | 405 | username AS "username: Username", |
| 392 | - password_hash AS "password_hash: PasswordHash", | 406 | + person AS "person: PersonId", |
| 393 | role AS "role: Role", | 407 | role AS "role: Role", |
| 394 | name AS "name: PersonName", | 408 | name AS "name: PersonName", |
| 395 | surname AS "surname: PersonName", | 409 | surname AS "surname: PersonName", |
| @@ -622,13 +636,38 @@ pub async fn set_profile( | |||
| 622 | value.map(|inner| Param::OptText(inner.map(str::to_string))) | 636 | value.map(|inner| Param::OptText(inner.map(str::to_string))) |
| 623 | } | 637 | } |
| 624 | FieldUpdate::new("app_user", id.uuid()) | 638 | FieldUpdate::new("app_user", id.uuid()) |
| 625 | - .set("name", text(name.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 639 | + .set( |
| 626 | - .set("surname", text(surname.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 640 | + "name", |
| 627 | - .set("email", text(email.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 641 | + text(name.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), |
| 628 | - .set("phone", text(phone.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 642 | + ) |
| 629 | - .set("birth_date", text(birth_date.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 643 | + .set( |
| 630 | - .set("display_name", text(display_name.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 644 | + "surname", |
| 631 | - .set("bio", text(bio.as_ref().map(|n| n.as_ref().map(|x| x.as_str())))) | 645 | + text(surname.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), |
| 646 | + ) | ||
| 647 | + .set( | ||
| 648 | + "email", | ||
| 649 | + text(email.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), | ||
| 650 | + ) | ||
| 651 | + .set( | ||
| 652 | + "phone", | ||
| 653 | + text(phone.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), | ||
| 654 | + ) | ||
| 655 | + .set( | ||
| 656 | + "birth_date", | ||
| 657 | + text(birth_date.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), | ||
| 658 | + ) | ||
| 659 | + .set( | ||
| 660 | + "display_name", | ||
| 661 | + text( | ||
| 662 | + display_name | ||
| 663 | + .as_ref() | ||
| 664 | + .map(|n| n.as_ref().map(|x| x.as_str())), | ||
| 665 | + ), | ||
| 666 | + ) | ||
| 667 | + .set( | ||
| 668 | + "bio", | ||
| 669 | + text(bio.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), | ||
| 670 | + ) | ||
| 632 | .run(db) | 671 | .run(db) |
| 633 | .await | 672 | .await |
| 634 | } | 673 | } |
| @@ -662,7 +701,7 @@ pub async fn set_avatar( | |||
| 662 | User, | 701 | User, |
| 663 | r#"SELECT id AS "id: UserId", | 702 | r#"SELECT id AS "id: UserId", |
| 664 | username AS "username: Username", | 703 | username AS "username: Username", |
| 665 | - password_hash AS "password_hash: PasswordHash", | 704 | + person AS "person: PersonId", |
| 666 | role AS "role: Role", | 705 | role AS "role: Role", |
| 667 | name AS "name: PersonName", | 706 | name AS "name: PersonName", |
| 668 | surname AS "surname: PersonName", | 707 | surname AS "surname: PersonName", |
| @@ -710,7 +749,7 @@ pub async fn clear_avatar(db: &Database, id: &UserId) -> Result<Option<User>, Ap | |||
| 710 | User, | 749 | User, |
| 711 | r#"SELECT id AS "id: UserId", | 750 | r#"SELECT id AS "id: UserId", |
| 712 | username AS "username: Username", | 751 | username AS "username: Username", |
| 713 | - password_hash AS "password_hash: PasswordHash", | 752 | + person AS "person: PersonId", |
| 714 | role AS "role: Role", | 753 | role AS "role: Role", |
| 715 | name AS "name: PersonName", | 754 | name AS "name: PersonName", |
| 716 | surname AS "surname: PersonName", | 755 | surname AS "surname: PersonName", |
| @@ -746,44 +785,6 @@ pub async fn clear_avatar(db: &Database, id: &UserId) -> Result<Option<User>, Ap | |||
| 746 | .await | 785 | .await |
| 747 | } | 786 | } |
| 748 | 787 | ||
| 749 | -/// Replace a user's password hash — the builder's admin-password reset | ||
| 750 | -/// (`POST /schools/{slug}/admin-password`). Only the credential is | ||
| 751 | -/// rewritten; revoking the sessions minted under the old one is the | ||
| 752 | -/// caller's second half ([`crate::db::session::delete_by_user`]), because a | ||
| 753 | -/// reset that leaves a stolen cookie working resets nothing. | ||
| 754 | -pub async fn set_password_hash( | ||
| 755 | - db: &Database, | ||
| 756 | - id: &UserId, | ||
| 757 | - password_hash: PasswordHash, | ||
| 758 | -) -> Result<Option<User>, AppError> { | ||
| 759 | - let user = sqlx::query_as!( | ||
| 760 | - User, | ||
| 761 | - r#"UPDATE app_user SET password_hash = $2 WHERE id = $1 | ||
| 762 | - RETURNING id AS "id: UserId", | ||
| 763 | - username AS "username: Username", | ||
| 764 | - password_hash AS "password_hash: PasswordHash", | ||
| 765 | - role AS "role: Role", | ||
| 766 | - name AS "name: PersonName", | ||
| 767 | - surname AS "surname: PersonName", | ||
| 768 | - email AS "email: Email", | ||
| 769 | - phone AS "phone: Phone", | ||
| 770 | - birth_date AS "birth_date: BirthDate", | ||
| 771 | - theme AS "theme: Theme", | ||
| 772 | - language AS "language: Language", | ||
| 773 | - palette_color AS "palette_color: PaletteColor", | ||
| 774 | - display_name AS "display_name: DisplayName", | ||
| 775 | - bio AS "bio: Bio", | ||
| 776 | - avatar_file, | ||
| 777 | - avatar_content_type AS "avatar_content_type: FileContentType", | ||
| 778 | - avatar_size"#, | ||
| 779 | - id.uuid(), | ||
| 780 | - password_hash.as_str(), | ||
| 781 | - ) | ||
| 782 | - .fetch_optional(db) | ||
| 783 | - .await?; | ||
| 784 | - Ok(user) | ||
| 785 | -} | ||
| 786 | - | ||
| 787 | /// Write the UI-preference fields the request actually carried. Same | 788 | /// Write the UI-preference fields the request actually carried. Same |
| 788 | /// contract as [`set_profile`]: `None` = omitted (not written), | 789 | /// contract as [`set_profile`]: `None` = omitted (not written), |
| 789 | /// `Some(None)` = cleared back to "never chose", `Some(Some(v))` = set. | 790 | /// `Some(None)` = cleared back to "never chose", `Some(Some(v))` = set. |
| @@ -810,7 +811,7 @@ pub async fn find_by_username(db: &Database, username: &str) -> Result<Option<Us | |||
| 810 | User, | 811 | User, |
| 811 | r#"SELECT id AS "id: UserId", | 812 | r#"SELECT id AS "id: UserId", |
| 812 | username AS "username: Username", | 813 | username AS "username: Username", |
| 813 | - password_hash AS "password_hash: PasswordHash", | 814 | + person AS "person: PersonId", |
| 814 | role AS "role: Role", | 815 | role AS "role: Role", |
| 815 | name AS "name: PersonName", | 816 | name AS "name: PersonName", |
| 816 | surname AS "surname: PersonName", | 817 | surname AS "surname: PersonName", |
| @@ -837,24 +838,15 @@ pub async fn find_by_username(db: &Database, username: &str) -> Result<Option<Us | |||
| 837 | mod tests { | 838 | mod tests { |
| 838 | use super::*; | 839 | use super::*; |
| 839 | use crate::database::init_test_db; | 840 | use crate::database::init_test_db; |
| 840 | - use crate::domain::user::Password; | ||
| 841 | 841 | ||
| 842 | fn png() -> FileContentType { | 842 | fn png() -> FileContentType { |
| 843 | FileContentType::try_new("image/png").unwrap() | 843 | FileContentType::try_new("image/png").unwrap() |
| 844 | } | 844 | } |
| 845 | 845 | ||
| 846 | async fn a_user(username: &str, db: &Database) -> User { | 846 | async fn a_user(username: &str, db: &Database) -> User { |
| 847 | - create( | 847 | + create(db, Username::try_new(username).unwrap(), None) |
| 848 | - db, | 848 | + .await |
| 849 | - Username::try_new(username).unwrap(), | 849 | + .unwrap() |
| 850 | - Password::try_new("secret1") | ||
| 851 | - .unwrap() | ||
| 852 | - .hash_async() | ||
| 853 | - .await | ||
| 854 | - .unwrap(), | ||
| 855 | - ) | ||
| 856 | - .await | ||
| 857 | - .unwrap() | ||
| 858 | } | 850 | } |
| 859 | 851 | ||
| 860 | #[tokio::test] | 852 | #[tokio::test] |
src/db/work_entry.rsmodified+2 -2
| @@ -204,8 +204,8 @@ mod tests { | |||
| 204 | // The stint's owner is a foreign key now: a real `app_user` row. | 204 | // The stint's owner is a foreign key now: a real `app_user` row. |
| 205 | let user = UserId::generate(); | 205 | let user = UserId::generate(); |
| 206 | sqlx::query( | 206 | sqlx::query( |
| 207 | - "INSERT INTO app_user (id, username, password_hash) \ | 207 | + "INSERT INTO app_user (id, username, created_at) \ |
| 208 | - VALUES ($1, 'work-fixture', 'x')", | 208 | + VALUES ($1, 'work-fixture', 0)", |
| 209 | ) | 209 | ) |
| 210 | .bind(user.uuid()) | 210 | .bind(user.uuid()) |
| 211 | .execute(&db) | 211 | .execute(&db) |
src/domain/mod.rsmodified+2 -0
| @@ -52,6 +52,7 @@ pub mod parent_link; | |||
| 52 | pub mod payment_ledger; | 52 | pub mod payment_ledger; |
| 53 | pub mod pomodoro; | 53 | pub mod pomodoro; |
| 54 | pub mod pool_question; | 54 | pub mod pool_question; |
| 55 | +pub mod pool_question_image; | ||
| 55 | pub mod preferences; | 56 | pub mod preferences; |
| 56 | pub mod profile; | 57 | pub mod profile; |
| 57 | pub mod question_image; | 58 | pub mod question_image; |
| @@ -63,6 +64,7 @@ pub mod session; | |||
| 63 | pub mod session_attendance; | 64 | pub mod session_attendance; |
| 64 | pub mod settings; | 65 | pub mod settings; |
| 65 | pub mod solution; | 66 | pub mod solution; |
| 67 | +pub mod solution_image; | ||
| 66 | pub mod subject; | 68 | pub mod subject; |
| 67 | pub mod term; | 69 | pub mod term; |
| 68 | pub mod text_fold; | 70 | pub mod text_fold; |
src/domain/pool_question.rsmodified+8 -26
| @@ -4,11 +4,13 @@ | |||
| 4 | //! the whole school for everyone to read and offer solutions on. Approved | 4 | //! the whole school for everyone to read and offer solutions on. Approved |
| 5 | //! content is frozen — edits after approval would bypass moderation — so the | 5 | //! content is frozen — edits after approval would bypass moderation — so the |
| 6 | //! only post-approval change is deletion (asker or teacher+), which takes the | 6 | //! only post-approval change is deletion (asker or teacher+), which takes the |
| 7 | -//! question's solutions with it. An optional photo of the problem rides on | 7 | +//! question's solutions with it. An optional photo of the problem is its own |
| 8 | -//! the row as metadata (`image_*`); the bytes live on disk under | 8 | +//! row in `pool_question_image` — the child-table shape of |
| 9 | -//! [`crate::config::Config::files_path`] in a file named by `image_file` — a | 9 | +//! [`crate::domain::question_image`] with a single (implicit) slot — and the |
| 10 | -//! fresh server-generated id per upload. The web layer owns the blob I/O; | 10 | +//! bytes live on disk under [`crate::config::Config::files_path`] in a file |
| 11 | -//! the queries live in [`crate::db::pool_question`], the workflows in | 11 | +//! named by that row's `file` — a fresh server-generated id per upload. The |
| 12 | +//! web layer owns the blob I/O; the queries live in | ||
| 13 | +//! [`crate::db::pool_question`], the workflows in | ||
| 12 | //! [`crate::service::pool_question`]. | 14 | //! [`crate::service::pool_question`]. |
| 13 | 15 | ||
| 14 | use uuid::Uuid; | 16 | use uuid::Uuid; |
| @@ -17,7 +19,6 @@ use crate::constant::{ | |||
| 17 | MAX_POOL_QUESTION_BODY_LEN, MAX_POOL_QUESTION_TITLE_LEN, STATUS_APPROVED, STATUS_PENDING, | 19 | MAX_POOL_QUESTION_BODY_LEN, MAX_POOL_QUESTION_TITLE_LEN, STATUS_APPROVED, STATUS_PENDING, |
| 18 | }; | 20 | }; |
| 19 | use crate::domain::monotonic_id::next_uuid; | 21 | use crate::domain::monotonic_id::next_uuid; |
| 20 | -use crate::domain::note_file::FileContentType; | ||
| 21 | use crate::domain::timestamp::Timestamp; | 22 | use crate::domain::timestamp::Timestamp; |
| 22 | use crate::domain::user::UserId; | 23 | use crate::domain::user::UserId; |
| 23 | use crate::error::ValidationError; | 24 | use crate::error::ValidationError; |
| @@ -97,11 +98,6 @@ pub struct PoolQuestion { | |||
| 97 | pub(crate) status: String, | 98 | pub(crate) status: String, |
| 98 | pub(crate) asked_at: Timestamp, | 99 | pub(crate) asked_at: Timestamp, |
| 99 | pub(crate) approved_by: Option<UserId>, | 100 | pub(crate) approved_by: Option<UserId>, |
| 100 | - /// The photo's on-disk blob name — a fresh server-generated id every | ||
| 101 | - /// upload; `None` when the question carries no image. | ||
| 102 | - pub(crate) image_file: Option<String>, | ||
| 103 | - pub(crate) image_content_type: Option<FileContentType>, | ||
| 104 | - pub(crate) image_size: Option<i64>, | ||
| 105 | } | 101 | } |
| 106 | 102 | ||
| 107 | impl PoolQuestion { | 103 | impl PoolQuestion { |
| @@ -114,9 +110,6 @@ impl PoolQuestion { | |||
| 114 | status: STATUS_PENDING.to_string(), | 110 | status: STATUS_PENDING.to_string(), |
| 115 | asked_at: Timestamp::now(), | 111 | asked_at: Timestamp::now(), |
| 116 | approved_by: None, | 112 | approved_by: None, |
| 117 | - image_file: None, | ||
| 118 | - image_content_type: None, | ||
| 119 | - image_size: None, | ||
| 120 | } | 113 | } |
| 121 | } | 114 | } |
| 122 | 115 | ||
| @@ -151,16 +144,5 @@ impl PoolQuestion { | |||
| 151 | pub fn get_approved_by(&self) -> Option<&UserId> { | 144 | pub fn get_approved_by(&self) -> Option<&UserId> { |
| 152 | self.approved_by.as_ref() | 145 | self.approved_by.as_ref() |
| 153 | } | 146 | } |
| 154 | - | ||
| 155 | - pub fn get_image_file(&self) -> Option<&str> { | ||
| 156 | - self.image_file.as_deref() | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - pub fn get_image_content_type(&self) -> Option<&FileContentType> { | ||
| 160 | - self.image_content_type.as_ref() | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - pub fn get_image_size(&self) -> Option<i64> { | ||
| 164 | - self.image_size | ||
| 165 | - } | ||
| 166 | } | 147 | } |
| 148 | + | ||
src/domain/pool_question_image.rsadded+42 -0
| @@ -0,0 +1,42 @@ | |||
| 1 | +//! The photo of a pool question — one optional image row per question, the | ||
| 2 | +//! single-slot spelling of [`crate::domain::question_image`]'s child-table | ||
| 3 | +//! shape. The row carries metadata only; the bytes live on disk under | ||
| 4 | +//! [`crate::config::Config::files_path`] in a file named by `file` — a fresh | ||
| 5 | +//! server-generated id per upload, so a replace never overwrites bytes in | ||
| 6 | +//! place. The question row itself carries no image columns; the child row is | ||
| 7 | +//! the whole photo. The writes ride the parent's own transactions in | ||
| 8 | +//! [`crate::db::pool_question`] (pending-only, like every content write); | ||
| 9 | +//! the reads live in [`crate::db::pool_question_image`]; the web layer owns | ||
| 10 | +//! the blob I/O and its ordering (new blob before row, row before old blob). | ||
| 11 | + | ||
| 12 | +use crate::domain::note_file::FileContentType; | ||
| 13 | +use crate::domain::pool_question::PoolQuestionId; | ||
| 14 | + | ||
| 15 | +/// One question's photo row. `question` is the primary key — one image per | ||
| 16 | +/// question by construction, and a replace is a plain upsert. | ||
| 17 | +#[derive(Debug, Clone, sqlx::FromRow)] | ||
| 18 | +pub struct PoolQuestionImage { | ||
| 19 | + pub(crate) question: PoolQuestionId, | ||
| 20 | + /// The blob's on-disk name — a fresh server-generated id every upload. | ||
| 21 | + pub(crate) file: String, | ||
| 22 | + pub(crate) content_type: FileContentType, | ||
| 23 | + pub(crate) size: i64, | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +impl PoolQuestionImage { | ||
| 27 | + pub fn get_question(&self) -> &PoolQuestionId { | ||
| 28 | + &self.question | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + pub fn get_file(&self) -> &str { | ||
| 32 | + &self.file | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + pub fn get_content_type(&self) -> &FileContentType { | ||
| 36 | + &self.content_type | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + pub fn get_size(&self) -> i64 { | ||
| 40 | + self.size | ||
| 41 | + } | ||
| 42 | +} | ||
src/domain/solution.rsmodified+0 -20
| @@ -2,7 +2,6 @@ use uuid::Uuid; | |||
| 2 | 2 | ||
| 3 | use crate::constant::MAX_SOLUTION_BODY_LEN; | 3 | use crate::constant::MAX_SOLUTION_BODY_LEN; |
| 4 | use crate::domain::monotonic_id::next_uuid; | 4 | use crate::domain::monotonic_id::next_uuid; |
| 5 | -use crate::domain::note_file::FileContentType; | ||
| 6 | use crate::domain::pool_question::PoolQuestionId; | 5 | use crate::domain::pool_question::PoolQuestionId; |
| 7 | use crate::domain::timestamp::Timestamp; | 6 | use crate::domain::timestamp::Timestamp; |
| 8 | use crate::domain::user::UserId; | 7 | use crate::domain::user::UserId; |
| @@ -66,11 +65,6 @@ pub struct Solution { | |||
| 66 | pub(crate) author: UserId, | 65 | pub(crate) author: UserId, |
| 67 | pub(crate) body: SolutionBody, | 66 | pub(crate) body: SolutionBody, |
| 68 | pub(crate) offered_at: Timestamp, | 67 | pub(crate) offered_at: Timestamp, |
| 69 | - /// The photo's on-disk blob name — a fresh server-generated id every | ||
| 70 | - /// upload; `None` when the solution carries no image. | ||
| 71 | - pub(crate) image_file: Option<String>, | ||
| 72 | - pub(crate) image_content_type: Option<FileContentType>, | ||
| 73 | - pub(crate) image_size: Option<i64>, | ||
| 74 | } | 68 | } |
| 75 | 69 | ||
| 76 | impl Solution { | 70 | impl Solution { |
| @@ -81,9 +75,6 @@ impl Solution { | |||
| 81 | author: *author, | 75 | author: *author, |
| 82 | body, | 76 | body, |
| 83 | offered_at: Timestamp::now(), | 77 | offered_at: Timestamp::now(), |
| 84 | - image_file: None, | ||
| 85 | - image_content_type: None, | ||
| 86 | - image_size: None, | ||
| 87 | } | 78 | } |
| 88 | } | 79 | } |
| 89 | 80 | ||
| @@ -107,17 +98,6 @@ impl Solution { | |||
| 107 | self.offered_at | 98 | self.offered_at |
| 108 | } | 99 | } |
| 109 | 100 | ||
| 110 | - pub fn get_image_file(&self) -> Option<&str> { | ||
| 111 | - self.image_file.as_deref() | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - pub fn get_image_content_type(&self) -> Option<&FileContentType> { | ||
| 115 | - self.image_content_type.as_ref() | ||
| 116 | - } | ||
| 117 | - | ||
| 118 | - pub fn get_image_size(&self) -> Option<i64> { | ||
| 119 | - self.image_size | ||
| 120 | - } | ||
| 121 | } | 101 | } |
| 122 | 102 | ||
| 123 | #[cfg(test)] | 103 | #[cfg(test)] |
src/domain/solution_image.rsadded+42 -0
| @@ -0,0 +1,42 @@ | |||
| 1 | +//! The photo of an offered solution — one optional image row per solution, | ||
| 2 | +//! the single-slot spelling of [`crate::domain::question_image`]'s | ||
| 3 | +//! child-table shape. The row carries metadata only; the bytes live on disk | ||
| 4 | +//! under [`crate::config::Config::files_path`] in a file named by `file` — a | ||
| 5 | +//! fresh server-generated id per upload, so a replace never overwrites bytes | ||
| 6 | +//! in place. The solution row itself carries no image columns; the child row | ||
| 7 | +//! is the whole photo. The writes ride the parent's own transactions in | ||
| 8 | +//! [`crate::db::solution`] (unconditional — solutions are unmoderated); the | ||
| 9 | +//! reads live in [`crate::db::solution_image`]; the web layer owns the blob | ||
| 10 | +//! I/O and its ordering (new blob before row, row before old blob). | ||
| 11 | + | ||
| 12 | +use crate::domain::note_file::FileContentType; | ||
| 13 | +use crate::domain::solution::SolutionId; | ||
| 14 | + | ||
| 15 | +/// One solution's photo row. `solution` is the primary key — one image per | ||
| 16 | +/// solution by construction, and a replace is a plain upsert. | ||
| 17 | +#[derive(Debug, Clone, sqlx::FromRow)] | ||
| 18 | +pub struct SolutionImage { | ||
| 19 | + pub(crate) solution: SolutionId, | ||
| 20 | + /// The blob's on-disk name — a fresh server-generated id every upload. | ||
| 21 | + pub(crate) file: String, | ||
| 22 | + pub(crate) content_type: FileContentType, | ||
| 23 | + pub(crate) size: i64, | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +impl SolutionImage { | ||
| 27 | + pub fn get_solution(&self) -> &SolutionId { | ||
| 28 | + &self.solution | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + pub fn get_file(&self) -> &str { | ||
| 32 | + &self.file | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + pub fn get_content_type(&self) -> &FileContentType { | ||
| 36 | + &self.content_type | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + pub fn get_size(&self) -> i64 { | ||
| 40 | + self.size | ||
| 41 | + } | ||
| 42 | +} | ||
src/domain/user.rsmodified+14 -10
| @@ -12,6 +12,7 @@ use uuid::Uuid; | |||
| 12 | use crate::constant::{AI_PRINCIPAL_KEY, DECOY_PASSWORD}; | 12 | use crate::constant::{AI_PRINCIPAL_KEY, DECOY_PASSWORD}; |
| 13 | use crate::domain::monotonic_id::next_uuid; | 13 | use crate::domain::monotonic_id::next_uuid; |
| 14 | use crate::domain::note_file::FileContentType; | 14 | use crate::domain::note_file::FileContentType; |
| 15 | +use crate::domain::person::PersonId; | ||
| 15 | use crate::domain::preferences::{Language, PaletteColor, Theme}; | 16 | use crate::domain::preferences::{Language, PaletteColor, Theme}; |
| 16 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; | 17 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; |
| 17 | use crate::domain::role::Role; | 18 | use crate::domain::role::Role; |
| @@ -103,7 +104,9 @@ impl Password { | |||
| 103 | fn hash(&self) -> Result<PasswordHash, AppError> { | 104 | fn hash(&self) -> Result<PasswordHash, AppError> { |
| 104 | // password-hash 0.6 generates the salt internally (its own CSPRNG); | 105 | // password-hash 0.6 generates the salt internally (its own CSPRNG); |
| 105 | // the explicit SaltString step is gone. | 106 | // the explicit SaltString step is gone. |
| 106 | - let hash = Argon2::default().hash_password(self.0.as_bytes())?.to_string(); | 107 | + let hash = Argon2::default() |
| 108 | + .hash_password(self.0.as_bytes())? | ||
| 109 | + .to_string(); | ||
| 107 | Ok(PasswordHash(hash)) | 110 | Ok(PasswordHash(hash)) |
| 108 | } | 111 | } |
| 109 | 112 | ||
| @@ -204,7 +207,10 @@ impl PasswordHash { | |||
| 204 | pub struct User { | 207 | pub struct User { |
| 205 | pub(crate) id: UserId, | 208 | pub(crate) id: UserId, |
| 206 | pub(crate) username: Username, | 209 | pub(crate) username: Username, |
| 207 | - pub(crate) password_hash: PasswordHash, | 210 | + /// The control-plane person this school row belongs to — the join key to |
| 211 | + /// the credential. No FK: the two halves are separate databases. `None` | ||
| 212 | + /// on rows minted before their person was known (boot seed order, tests). | ||
| 213 | + pub(crate) person: Option<PersonId>, | ||
| 208 | pub(crate) role: Role, | 214 | pub(crate) role: Role, |
| 209 | // Personal info, identical for every role. All optional: accounts are | 215 | // Personal info, identical for every role. All optional: accounts are |
| 210 | // created from bare credentials and filled in later, and rows from before | 216 | // created from bare credentials and filled in later, and rows from before |
| @@ -237,14 +243,14 @@ impl User { | |||
| 237 | /// | 243 | /// |
| 238 | /// Never written to the database, and never read back from one: the id is | 244 | /// Never written to the database, and never read back from one: the id is |
| 239 | /// the nil UUID, which no minted id (always a v7) can ever equal. Every | 245 | /// the nil UUID, which no minted id (always a v7) can ever equal. Every |
| 240 | - /// other field is inert — the empty password hash parses as no argon2 hash, | 246 | + /// other field is inert — `person` is `None`, and [`Role::Ai`] clears no |
| 241 | - /// so it verifies against nothing, and [`Role::Ai`] clears no `at_least` | 247 | + /// `at_least` bar and fails every exact `== Role::Student` / |
| 242 | - /// bar and fails every exact `== Role::Student` / `== Role::Parent` gate. | 248 | + /// `== Role::Parent` gate. |
| 243 | pub(crate) fn ai_principal() -> User { | 249 | pub(crate) fn ai_principal() -> User { |
| 244 | User { | 250 | User { |
| 245 | id: UserId(Uuid::nil()), | 251 | id: UserId(Uuid::nil()), |
| 246 | username: Username(AI_PRINCIPAL_KEY.to_string()), | 252 | username: Username(AI_PRINCIPAL_KEY.to_string()), |
| 247 | - password_hash: PasswordHash(String::new()), | 253 | + person: None, |
| 248 | role: Role::Ai, | 254 | role: Role::Ai, |
| 249 | name: None, | 255 | name: None, |
| 250 | surname: None, | 256 | surname: None, |
| @@ -269,9 +275,8 @@ impl User { | |||
| 269 | pub fn get_username(&self) -> &Username { | 275 | pub fn get_username(&self) -> &Username { |
| 270 | &self.username | 276 | &self.username |
| 271 | } | 277 | } |
| 272 | - | 278 | + pub fn get_person(&self) -> Option<&PersonId> { |
| 273 | - pub fn get_password_hash(&self) -> &PasswordHash { | 279 | + self.person.as_ref() |
| 274 | - &self.password_hash | ||
| 275 | } | 280 | } |
| 276 | 281 | ||
| 277 | pub fn get_role(&self) -> Role { | 282 | pub fn get_role(&self) -> Role { |
| @@ -329,7 +334,6 @@ impl User { | |||
| 329 | pub fn get_avatar_size(&self) -> Option<i64> { | 334 | pub fn get_avatar_size(&self) -> Option<i64> { |
| 330 | self.avatar_size | 335 | self.avatar_size |
| 331 | } | 336 | } |
| 332 | - | ||
| 333 | } | 337 | } |
| 334 | 338 | ||
| 335 | #[cfg(test)] | 339 | #[cfg(test)] |
src/service/appointment.rsmodified+2 -2
| @@ -405,8 +405,8 @@ mod tests { | |||
| 405 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 405 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 406 | let user = UserId::generate(); | 406 | let user = UserId::generate(); |
| 407 | sqlx::query( | 407 | sqlx::query( |
| 408 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 408 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 409 | - VALUES ($1, $2, 'x', $3)", | 409 | + VALUES ($1, $2, 0, $3)", |
| 410 | ) | 410 | ) |
| 411 | .bind(user.uuid()) | 411 | .bind(user.uuid()) |
| 412 | .bind(format!("{label}-{}", &user.key()[30..])) | 412 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/service/appointment_slot.rsmodified+2 -2
| @@ -211,8 +211,8 @@ mod tests { | |||
| 211 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 211 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 212 | let user = UserId::generate(); | 212 | let user = UserId::generate(); |
| 213 | sqlx::query( | 213 | sqlx::query( |
| 214 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 214 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 215 | - VALUES ($1, $2, 'x', $3)", | 215 | + VALUES ($1, $2, 0, $3)", |
| 216 | ) | 216 | ) |
| 217 | .bind(user.uuid()) | 217 | .bind(user.uuid()) |
| 218 | .bind(format!("{label}-{}", &user.key()[30..])) | 218 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/service/class_member.rsmodified+1 -6
| @@ -353,15 +353,10 @@ mod tests { | |||
| 353 | let (db, _leases) = crate::database::init_test_db().await; | 353 | let (db, _leases) = crate::database::init_test_db().await; |
| 354 | let manager = crate::db::class_member::tests::fixture_user(&db, "manager").await; | 354 | let manager = crate::db::class_member::tests::fixture_user(&db, "manager").await; |
| 355 | // A real row, because the sweep now rides on the role write. | 355 | // A real row, because the sweep now rides on the role write. |
| 356 | - let hash = crate::domain::user::Password::try_new("secret1") | ||
| 357 | - .unwrap() | ||
| 358 | - .hash_async() | ||
| 359 | - .await | ||
| 360 | - .unwrap(); | ||
| 361 | let account = crate::db::user::create( | 356 | let account = crate::db::user::create( |
| 362 | &db, | 357 | &db, |
| 363 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 358 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 364 | - hash, | 359 | + None, |
| 365 | ) | 360 | ) |
| 366 | .await | 361 | .await |
| 367 | .unwrap(); | 362 | .unwrap(); |
src/service/exam_attempt.rsmodified+3 -8
| @@ -446,8 +446,8 @@ mod tests { | |||
| 446 | // The creator is a foreign key now: a real `app_user` row under the | 446 | // The creator is a foreign key now: a real `app_user` row under the |
| 447 | // fixture's fixed key. | 447 | // fixture's fixed key. |
| 448 | sqlx::query( | 448 | sqlx::query( |
| 449 | - "INSERT INTO app_user (id, username, password_hash) \ | 449 | + "INSERT INTO app_user (id, username, created_at) \ |
| 450 | - VALUES ($1, 'acdc-fixture', 'x') ON CONFLICT DO NOTHING", | 450 | + VALUES ($1, 'acdc-fixture', 0) ON CONFLICT DO NOTHING", |
| 451 | ) | 451 | ) |
| 452 | .bind(creator.uuid()) | 452 | .bind(creator.uuid()) |
| 453 | .execute(db) | 453 | .execute(db) |
| @@ -513,15 +513,10 @@ mod tests { | |||
| 513 | /// A real user row: the sitting counter lives on it, and the claim that | 513 | /// A real user row: the sitting counter lives on it, and the claim that |
| 514 | /// rides the attempt's create has nothing to write to without one. | 514 | /// rides the attempt's create has nothing to write to without one. |
| 515 | async fn student(db: &Database) -> UserId { | 515 | async fn student(db: &Database) -> UserId { |
| 516 | - let hash = crate::domain::user::Password::try_new("secret1") | ||
| 517 | - .unwrap() | ||
| 518 | - .hash_async() | ||
| 519 | - .await | ||
| 520 | - .unwrap(); | ||
| 521 | *crate::db::user::create( | 516 | *crate::db::user::create( |
| 522 | db, | 517 | db, |
| 523 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 518 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 524 | - hash, | 519 | + None, |
| 525 | ) | 520 | ) |
| 526 | .await | 521 | .await |
| 527 | .unwrap() | 522 | .unwrap() |
src/service/fee_plan_assignment.rsmodified+2 -2
| @@ -221,8 +221,8 @@ mod tests { | |||
| 221 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { | 221 | async fn a_person(db: &Database, label: &str, role: &str) -> UserId { |
| 222 | let user = UserId::generate(); | 222 | let user = UserId::generate(); |
| 223 | sqlx::query( | 223 | sqlx::query( |
| 224 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 224 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 225 | - VALUES ($1, $2, 'x', $3)", | 225 | + VALUES ($1, $2, 0, $3)", |
| 226 | ) | 226 | ) |
| 227 | .bind(user.uuid()) | 227 | .bind(user.uuid()) |
| 228 | .bind(format!("{label}-{}", &user.key()[30..])) | 228 | .bind(format!("{label}-{}", &user.key()[30..])) |
src/service/meal_booking.rsmodified+2 -2
| @@ -314,8 +314,8 @@ mod tests { | |||
| 314 | // The menu's creator is a foreign key now: a real `app_user` row. | 314 | // The menu's creator is a foreign key now: a real `app_user` row. |
| 315 | let creator = UserId::generate(); | 315 | let creator = UserId::generate(); |
| 316 | sqlx::query( | 316 | sqlx::query( |
| 317 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 317 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 318 | - VALUES ($1, $2, 'x', 'teacher')", | 318 | + VALUES ($1, $2, 0, 'teacher')", |
| 319 | ) | 319 | ) |
| 320 | .bind(creator.uuid()) | 320 | .bind(creator.uuid()) |
| 321 | .bind(format!("menu-fixture-{}", &creator.key()[30..])) | 321 | .bind(format!("menu-fixture-{}", &creator.key()[30..])) |
src/service/mod.rsmodified+2 -0
| @@ -46,6 +46,7 @@ pub mod payment_ledger; | |||
| 46 | pub mod person; | 46 | pub mod person; |
| 47 | pub mod pomodoro; | 47 | pub mod pomodoro; |
| 48 | pub mod pool_question; | 48 | pub mod pool_question; |
| 49 | +pub mod pool_question_image; | ||
| 49 | pub mod profile; | 50 | pub mod profile; |
| 50 | pub mod question_image; | 51 | pub mod question_image; |
| 51 | pub mod rag_output; | 52 | pub mod rag_output; |
| @@ -54,6 +55,7 @@ pub mod session; | |||
| 54 | pub mod session_attendance; | 55 | pub mod session_attendance; |
| 55 | pub mod settings; | 56 | pub mod settings; |
| 56 | pub mod solution; | 57 | pub mod solution; |
| 58 | +pub mod solution_image; | ||
| 57 | pub mod subject; | 59 | pub mod subject; |
| 58 | pub mod term; | 60 | pub mod term; |
| 59 | pub mod user; | 61 | pub mod user; |
src/service/person.rsmodified+2 -3
| @@ -100,9 +100,8 @@ pub async fn delete_sessions_by_person( | |||
| 100 | person::delete_sessions_by_person(control, person).await | 100 | person::delete_sessions_by_person(control, person).await |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | -/// The school-user password writes mirror the person credential: login reads | 103 | +/// Move the credential — the one login reads. The school-side row carries no |
| 104 | -/// `person.password_hash` and nothing else, so a reset that moved only the | 104 | +/// password at all, so this is the whole credential move. |
| 105 | -/// school row would reset nothing. | ||
| 106 | pub async fn set_password_hash( | 105 | pub async fn set_password_hash( |
| 107 | control: &Database, | 106 | control: &Database, |
| 108 | username: &Username, | 107 | username: &Username, |
src/service/pool_question.rsmodified+14 -11
| @@ -1,14 +1,14 @@ | |||
| 1 | //! Pool-question funnels: ask, the two listings, the approve with its | 1 | //! Pool-question funnels: ask, the two listings, the approve with its |
| 2 | //! 409-vs-404 split, the pending-only image writes, and the delete whose | 2 | //! 409-vs-404 split, the pending-only image writes, and the delete whose |
| 3 | -//! swept solutions ride back for the web layer's blob cleanup. The queries | 3 | +//! swept solutions and collected image blob keys ride back for the web |
| 4 | -//! and their transactions live in [`crate::db::pool_question`]; the pure | 4 | +//! layer's blob cleanup. The queries and their transactions live in |
| 5 | -//! entity and newtypes in [`crate::domain::pool_question`]. | 5 | +//! [`crate::db::pool_question`]; the pure entity and newtypes in |
| 6 | +//! [`crate::domain::pool_question`]. | ||
| 6 | 7 | ||
| 7 | use crate::database::Database; | 8 | use crate::database::Database; |
| 8 | use crate::db::pool_question; | 9 | use crate::db::pool_question; |
| 9 | use crate::domain::note_file::FileContentType; | 10 | use crate::domain::note_file::FileContentType; |
| 10 | use crate::domain::pool_question::{PoolQuestion, PoolQuestionId}; | 11 | use crate::domain::pool_question::{PoolQuestion, PoolQuestionId}; |
| 11 | -use crate::domain::solution::Solution; | ||
| 12 | use crate::domain::user::UserId; | 12 | use crate::domain::user::UserId; |
| 13 | use crate::error::AppError; | 13 | use crate::error::AppError; |
| 14 | 14 | ||
| @@ -56,31 +56,34 @@ pub async fn approve( | |||
| 56 | 56 | ||
| 57 | /// Point the question at a freshly written image blob; `None` means the | 57 | /// Point the question at a freshly written image blob; `None` means the |
| 58 | /// question was approved or deleted mid-upload (the fresh blob is the | 58 | /// question was approved or deleted mid-upload (the fresh blob is the |
| 59 | -/// caller's orphan to take back off disk). | 59 | +/// caller's orphan to take back off disk). `Some(replaced)` names the blob |
| 60 | +/// this upload displaced — the caller's to remove. | ||
| 60 | pub async fn set_image( | 61 | pub async fn set_image( |
| 61 | db: &Database, | 62 | db: &Database, |
| 62 | id: &PoolQuestionId, | 63 | id: &PoolQuestionId, |
| 63 | file: &str, | 64 | file: &str, |
| 64 | content_type: &FileContentType, | 65 | content_type: &FileContentType, |
| 65 | size: i64, | 66 | size: i64, |
| 66 | -) -> Result<Option<PoolQuestion>, AppError> { | 67 | +) -> Result<Option<Option<String>>, AppError> { |
| 67 | pool_question::set_image(db, id, file, content_type, size).await | 68 | pool_question::set_image(db, id, file, content_type, size).await |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | /// Detach the question's image (pending only, like [`set_image`]); `None` | 71 | /// Detach the question's image (pending only, like [`set_image`]); `None` |
| 71 | -/// means the question is no longer pending. | 72 | +/// means the question is no longer pending. `Some(detached)` names the |
| 73 | +/// removed blob — `None` inside when there was no image. | ||
| 72 | pub async fn clear_image( | 74 | pub async fn clear_image( |
| 73 | db: &Database, | 75 | db: &Database, |
| 74 | id: &PoolQuestionId, | 76 | id: &PoolQuestionId, |
| 75 | -) -> Result<Option<PoolQuestion>, AppError> { | 77 | +) -> Result<Option<Option<String>>, AppError> { |
| 76 | pool_question::clear_image(db, id).await | 78 | pool_question::clear_image(db, id).await |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | -/// Delete the question and cascade its solutions; the removed rows come back | 81 | +/// Delete the question and cascade its solutions; the removed rows and the |
| 80 | -/// so the web layer can take every image blob off disk. | 82 | +/// image blob keys they named come back so the web layer can take every |
| 83 | +/// blob off disk. | ||
| 81 | pub async fn delete( | 84 | pub async fn delete( |
| 82 | db: &Database, | 85 | db: &Database, |
| 83 | id: &PoolQuestionId, | 86 | id: &PoolQuestionId, |
| 84 | -) -> Result<Option<(PoolQuestion, Vec<Solution>)>, AppError> { | 87 | +) -> Result<Option<pool_question::Deleted>, AppError> { |
| 85 | pool_question::delete(db, id).await | 88 | pool_question::delete(db, id).await |
| 86 | } | 89 | } |
src/service/pool_question_image.rsadded+26 -0
| @@ -0,0 +1,26 @@ | |||
| 1 | +//! Pool-question-photo funnels: the read doors the web layer takes for the | ||
| 2 | +//! blob endpoints and the page bucketing. The writes do not pass through | ||
| 3 | +//! here — they are the question's own guarded transactions in | ||
| 4 | +//! [`crate::service::pool_question`] (`set_image`/`clear_image`/`delete`). | ||
| 5 | + | ||
| 6 | +use crate::database::Database; | ||
| 7 | +use crate::db; | ||
| 8 | +use crate::domain::pool_question::PoolQuestionId; | ||
| 9 | +use crate::domain::pool_question_image::PoolQuestionImage; | ||
| 10 | +use crate::error::AppError; | ||
| 11 | + | ||
| 12 | +/// The question's photo row, if any. | ||
| 13 | +pub async fn read( | ||
| 14 | + db: &Database, | ||
| 15 | + question: &PoolQuestionId, | ||
| 16 | +) -> Result<Option<PoolQuestionImage>, AppError> { | ||
| 17 | + db::pool_question_image::read(db, question).await | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +/// The photo rows of a page of questions, in one query. | ||
| 21 | +pub async fn list_for_questions( | ||
| 22 | + db: &Database, | ||
| 23 | + questions: &[&PoolQuestionId], | ||
| 24 | +) -> Result<Vec<PoolQuestionImage>, AppError> { | ||
| 25 | + db::pool_question_image::list_for_questions(db, questions).await | ||
| 26 | +} | ||
src/service/solution.rsmodified+18 -7
| @@ -57,24 +57,35 @@ pub async fn set_body( | |||
| 57 | solution::set_body(db, id, body).await | 57 | solution::set_body(db, id, body).await |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | -/// Point the solution at a freshly written image blob; the *before* row names | 60 | +/// Point the solution at a freshly written image blob; `None` means the row |
| 61 | -/// the replaced blob the caller must remove. | 61 | +/// was deleted mid-flight (the fresh blob is the caller's orphan to take |
| 62 | +/// back off disk). `Some(replaced)` names the blob this upload displaced — | ||
| 63 | +/// the caller's to remove. | ||
| 62 | pub async fn set_image( | 64 | pub async fn set_image( |
| 63 | db: &Database, | 65 | db: &Database, |
| 64 | id: &SolutionId, | 66 | id: &SolutionId, |
| 65 | file: &str, | 67 | file: &str, |
| 66 | content_type: &FileContentType, | 68 | content_type: &FileContentType, |
| 67 | size: i64, | 69 | size: i64, |
| 68 | -) -> Result<Option<Solution>, AppError> { | 70 | +) -> Result<Option<Option<String>>, AppError> { |
| 69 | solution::set_image(db, id, file, content_type, size).await | 71 | solution::set_image(db, id, file, content_type, size).await |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 72 | -/// Detach the solution's image; the *before* row names the blob the caller | 74 | +/// Detach the solution's image; `None` means the row was deleted mid-flight. |
| 73 | -/// must remove. | 75 | +/// `Some(detached)` names the removed blob — `None` inside when there was no |
| 74 | -pub async fn clear_image(db: &Database, id: &SolutionId) -> Result<Option<Solution>, AppError> { | 76 | +/// image. |
| 77 | +pub async fn clear_image( | ||
| 78 | + db: &Database, | ||
| 79 | + id: &SolutionId, | ||
| 80 | +) -> Result<Option<Option<String>>, AppError> { | ||
| 75 | solution::clear_image(db, id).await | 81 | solution::clear_image(db, id).await |
| 76 | } | 82 | } |
| 77 | 83 | ||
| 78 | -pub async fn delete(db: &Database, target: Solution) -> Result<Solution, AppError> { | 84 | +/// Delete a solution; the pair carries the row and the blob name of the |
| 85 | +/// photo it carried (the caller's disk-GC list). `None` = already gone. | ||
| 86 | +pub async fn delete( | ||
| 87 | + db: &Database, | ||
| 88 | + target: Solution, | ||
| 89 | +) -> Result<Option<(Solution, Option<String>)>, AppError> { | ||
| 79 | solution::delete(db, target).await | 90 | solution::delete(db, target).await |
| 80 | } | 91 | } |
src/service/solution_image.rsadded+23 -0
| @@ -0,0 +1,23 @@ | |||
| 1 | +//! Solution-photo funnels: the read doors the web layer takes for the blob | ||
| 2 | +//! endpoints and the page bucketing. The writes do not pass through here — | ||
| 3 | +//! they are the solution's own transactions in | ||
| 4 | +//! [`crate::service::solution`] (`set_image`/`clear_image`/`delete`). | ||
| 5 | + | ||
| 6 | +use crate::database::Database; | ||
| 7 | +use crate::db; | ||
| 8 | +use crate::domain::solution::SolutionId; | ||
| 9 | +use crate::domain::solution_image::SolutionImage; | ||
| 10 | +use crate::error::AppError; | ||
| 11 | + | ||
| 12 | +/// The solution's photo row, if any. | ||
| 13 | +pub async fn read(db: &Database, solution: &SolutionId) -> Result<Option<SolutionImage>, AppError> { | ||
| 14 | + db::solution_image::read(db, solution).await | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +/// The photo rows of a page of solutions, in one query. | ||
| 18 | +pub async fn list_for_solutions( | ||
| 19 | + db: &Database, | ||
| 20 | + solutions: &[&SolutionId], | ||
| 21 | +) -> Result<Vec<SolutionImage>, AppError> { | ||
| 22 | + db::solution_image::list_for_solutions(db, solutions).await | ||
| 23 | +} | ||
src/service/user.rsmodified+33 -54
| @@ -8,10 +8,11 @@ use crate::tenant::{Slug, Tenants}; | |||
| 8 | use crate::db::user; | 8 | use crate::db::user; |
| 9 | use crate::domain::board::Board; | 9 | use crate::domain::board::Board; |
| 10 | use crate::domain::note_file::FileContentType; | 10 | use crate::domain::note_file::FileContentType; |
| 11 | +use crate::domain::person::PersonId; | ||
| 11 | use crate::domain::preferences::{Language, PaletteColor, Theme}; | 12 | use crate::domain::preferences::{Language, PaletteColor, Theme}; |
| 12 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; | 13 | use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; |
| 13 | use crate::domain::role::Role; | 14 | use crate::domain::role::Role; |
| 14 | -use crate::domain::user::{Password, PasswordHash, User, UserId, Username}; | 15 | +use crate::domain::user::{Password, User, UserId, Username}; |
| 15 | use crate::error::AppError; | 16 | use crate::error::AppError; |
| 16 | 17 | ||
| 17 | /// Idempotent startup seed: guarantee an admin account with this username. | 18 | /// Idempotent startup seed: guarantee an admin account with this username. |
| @@ -27,6 +28,19 @@ pub async fn ensure_admin( | |||
| 27 | password: Password, | 28 | password: Password, |
| 28 | ) -> Result<(), AppError> { | 29 | ) -> Result<(), AppError> { |
| 29 | let db = tenants.get(slug).await?; | 30 | let db = tenants.get(slug).await?; |
| 31 | + // The person half runs first, so the school row can carry the person id | ||
| 32 | + // it is the join key to. Login reads the control-plane credential, so the | ||
| 33 | + // seeded admin needs their `person` row and the membership too. Both | ||
| 34 | + // writes are idempotent (create-or-load never re-keys an existing | ||
| 35 | + // person's password; the membership insert is `ON CONFLICT DO NOTHING`), | ||
| 36 | + // so every boot re-runs them — and a school whose seed predates the | ||
| 37 | + // person half heals on the next boot instead of stranding an admin who | ||
| 38 | + // cannot log in. | ||
| 39 | + let password_hash = password.hash_async().await?; | ||
| 40 | + let person = | ||
| 41 | + crate::service::person::create_or_load(tenants.control(), username.clone(), password_hash) | ||
| 42 | + .await?; | ||
| 43 | + crate::service::person::link_school(tenants.control(), person.get_id(), slug).await?; | ||
| 30 | match user::find_by_username(&db, username.as_str()).await? { | 44 | match user::find_by_username(&db, username.as_str()).await? { |
| 31 | Some(user) if user.role == Role::Admin => {} | 45 | Some(user) if user.role == Role::Admin => {} |
| 32 | Some(_) => { | 46 | Some(_) => { |
| @@ -36,37 +50,20 @@ pub async fn ensure_admin( | |||
| 36 | ); | 50 | ); |
| 37 | return Ok(()); | 51 | return Ok(()); |
| 38 | } | 52 | } |
| 53 | + // One statement, admin from birth. Never create-then-promote: | ||
| 54 | + // an interruption between those two writes leaves a student row | ||
| 55 | + // holding ADMIN_USERNAME, which the `Some(_)` arm above then | ||
| 56 | + // refuses to promote — forever, on every subsequent boot. There | ||
| 57 | + // is no marker that could tell such a row apart from a stranger | ||
| 58 | + // who registered the name first, so the hole cannot be healed | ||
| 59 | + // later; it has to be impossible to open. | ||
| 39 | None => { | 60 | None => { |
| 40 | - // One statement, admin from birth. Never create-then-promote: | 61 | + user::create_with_role(&db, username, Some(*person.get_id()), Role::Admin).await?; |
| 41 | - // an interruption between those two writes leaves a student row | ||
| 42 | - // holding ADMIN_USERNAME, which the `Some(_)` arm above then | ||
| 43 | - // refuses to promote — forever, on every subsequent boot. There | ||
| 44 | - // is no marker that could tell such a row apart from a stranger | ||
| 45 | - // who registered the name first, so the hole cannot be healed | ||
| 46 | - // later; it has to be impossible to open. | ||
| 47 | - user::create_with_role( | ||
| 48 | - &db, | ||
| 49 | - username.clone(), | ||
| 50 | - password.hash_async().await?, | ||
| 51 | - Role::Admin, | ||
| 52 | - ) | ||
| 53 | - .await?; | ||
| 54 | // No `username` field: with OTLP on every event is exported as a | 62 | // No `username` field: with OTLP on every event is exported as a |
| 55 | // log record, so an account name here leaves the process. | 63 | // log record, so an account name here leaves the process. |
| 56 | tracing::info!("seeded the admin account named by ADMIN_USERNAME"); | 64 | tracing::info!("seeded the admin account named by ADMIN_USERNAME"); |
| 57 | } | 65 | } |
| 58 | } | 66 | } |
| 59 | - // The person half: login reads the control-plane credential, so the | ||
| 60 | - // seeded admin needs their `person` row and the membership too. Both | ||
| 61 | - // writes are idempotent (create-or-load never re-keys an existing | ||
| 62 | - // person's password; the membership insert is `ON CONFLICT DO NOTHING`), | ||
| 63 | - // so every boot re-runs them — and a school whose seed predates the | ||
| 64 | - // person half heals on the next boot instead of stranding an admin who | ||
| 65 | - // cannot log in. | ||
| 66 | - let password_hash = password.hash_async().await?; | ||
| 67 | - let person = | ||
| 68 | - crate::service::person::create_or_load(tenants.control(), username, password_hash).await?; | ||
| 69 | - crate::service::person::link_school(tenants.control(), person.get_id(), slug).await?; | ||
| 70 | Ok(()) | 67 | Ok(()) |
| 71 | } | 68 | } |
| 72 | 69 | ||
| @@ -101,15 +98,15 @@ pub async fn set_role( | |||
| 101 | user::set_role_cascade(db, target, role).await | 98 | user::set_role_cascade(db, target, role).await |
| 102 | } | 99 | } |
| 103 | 100 | ||
| 104 | -/// Register a new account — the web layer's row mint. New users always start | 101 | +/// Register a new school account for `person` — the web layer's row mint. |
| 105 | -/// as [`Role::Student`]; elevation is a separate, admin-only action | 102 | +/// New users always start as [`Role::Student`]; elevation is a separate, |
| 106 | -/// (see [`set_role`]). | 103 | +/// admin-only action (see [`set_role`]). |
| 107 | pub async fn create( | 104 | pub async fn create( |
| 108 | db: &Database, | 105 | db: &Database, |
| 109 | username: Username, | 106 | username: Username, |
| 110 | - password_hash: PasswordHash, | 107 | + person: Option<PersonId>, |
| 111 | ) -> Result<User, AppError> { | 108 | ) -> Result<User, AppError> { |
| 112 | - user::create(db, username, password_hash).await | 109 | + user::create(db, username, person).await |
| 113 | } | 110 | } |
| 114 | 111 | ||
| 115 | /// Mint a row holding `role` outright — the school-creation path, whose | 112 | /// Mint a row holding `role` outright — the school-creation path, whose |
| @@ -117,10 +114,10 @@ pub async fn create( | |||
| 117 | pub async fn create_with_role( | 114 | pub async fn create_with_role( |
| 118 | db: &Database, | 115 | db: &Database, |
| 119 | username: Username, | 116 | username: Username, |
| 120 | - password_hash: PasswordHash, | 117 | + person: Option<PersonId>, |
| 121 | role: Role, | 118 | role: Role, |
| 122 | ) -> Result<User, AppError> { | 119 | ) -> Result<User, AppError> { |
| 123 | - user::create_with_role(db, username, password_hash, role).await | 120 | + user::create_with_role(db, username, person, role).await |
| 124 | } | 121 | } |
| 125 | 122 | ||
| 126 | /// One user row, for callers that only inspect it — the web layer's reads go | 123 | /// One user row, for callers that only inspect it — the web layer's reads go |
| @@ -207,15 +204,6 @@ pub async fn clear_avatar(db: &Database, id: &UserId) -> Result<Option<User>, Ap | |||
| 207 | user::clear_avatar(db, id).await | 204 | user::clear_avatar(db, id).await |
| 208 | } | 205 | } |
| 209 | 206 | ||
| 210 | -/// Rewrite the credential — the admin-password reset's store half. | ||
| 211 | -pub async fn set_password_hash( | ||
| 212 | - db: &Database, | ||
| 213 | - id: &UserId, | ||
| 214 | - password_hash: PasswordHash, | ||
| 215 | -) -> Result<Option<User>, AppError> { | ||
| 216 | - user::set_password_hash(db, id, password_hash).await | ||
| 217 | -} | ||
| 218 | - | ||
| 219 | /// Persist the UI-preference fields a PATCH carried. | 207 | /// Persist the UI-preference fields a PATCH carried. |
| 220 | pub async fn set_preferences( | 208 | pub async fn set_preferences( |
| 221 | db: &Database, | 209 | db: &Database, |
| @@ -231,20 +219,11 @@ pub async fn set_preferences( | |||
| 231 | mod tests { | 219 | mod tests { |
| 232 | use super::*; | 220 | use super::*; |
| 233 | use crate::database::{Database, init_test_db}; | 221 | use crate::database::{Database, init_test_db}; |
| 234 | - use crate::domain::user::Password; | ||
| 235 | 222 | ||
| 236 | async fn a_user(username: &str, db: &Database) -> User { | 223 | async fn a_user(username: &str, db: &Database) -> User { |
| 237 | - user::create( | 224 | + user::create(db, Username::try_new(username).unwrap(), None) |
| 238 | - db, | 225 | + .await |
| 239 | - Username::try_new(username).unwrap(), | 226 | + .unwrap() |
| 240 | - Password::try_new("secret1") | ||
| 241 | - .unwrap() | ||
| 242 | - .hash_async() | ||
| 243 | - .await | ||
| 244 | - .unwrap(), | ||
| 245 | - ) | ||
| 246 | - .await | ||
| 247 | - .unwrap() | ||
| 248 | } | 227 | } |
| 249 | 228 | ||
| 250 | /// The board result slot is an *index* into a batch whose length depends on | 229 | /// The board result slot is an *index* into a batch whose length depends on |
src/web/appointments.rsmodified+2 -7
| @@ -902,16 +902,11 @@ async fn ensure_requester( | |||
| 902 | mod tests { | 902 | mod tests { |
| 903 | use super::*; | 903 | use super::*; |
| 904 | use crate::database::init_test_db; | 904 | use crate::database::init_test_db; |
| 905 | - use crate::domain::user::{Password, Username}; | 905 | + use crate::domain::user::Username; |
| 906 | 906 | ||
| 907 | /// A user at `role`, minted through the real create path. | 907 | /// A user at `role`, minted through the real create path. |
| 908 | async fn user(username: &str, role: Role, db: &Database) -> User { | 908 | async fn user(username: &str, role: Role, db: &Database) -> User { |
| 909 | - let hash = Password::try_new("secret1") | 909 | + let user = crate::service::user::create(db, Username::try_new(username).unwrap(), None) |
| 910 | - .unwrap() | ||
| 911 | - .hash_async() | ||
| 912 | - .await | ||
| 913 | - .unwrap(); | ||
| 914 | - let user = crate::service::user::create(db, Username::try_new(username).unwrap(), hash) | ||
| 915 | .await | 910 | .await |
| 916 | .unwrap(); | 911 | .unwrap(); |
| 917 | crate::service::user::set_role(db, user.get_id(), role).await.unwrap().0 | 912 | crate::service::user::set_role(db, user.get_id(), role).await.unwrap().0 |
src/web/auth.rsmodified+1 -1
| @@ -200,7 +200,7 @@ async fn register( | |||
| 200 | // each half is idempotent and a retry after a torn pair completes | 200 | // each half is idempotent and a retry after a torn pair completes |
| 201 | // it). A taken school username means the person is already a member | 201 | // it). A taken school username means the person is already a member |
| 202 | // — the same 201. | 202 | // — the same 201. |
| 203 | - match service::user::create(&db, username, password_hash).await { | 203 | + match service::user::create(&db, username, Some(*person.get_id())).await { |
| 204 | Ok(_) => {} | 204 | Ok(_) => {} |
| 205 | Err(AppError::Conflict(_)) => { | 205 | Err(AppError::Conflict(_)) => { |
| 206 | tracing::info!("register: school username already taken, answering 201"); | 206 | tracing::info!("register: school username already taken, answering 201"); |
src/web/bank_questions.rsmodified+2 -7
| @@ -923,16 +923,11 @@ mod tests { | |||
| 923 | use super::*; | 923 | use super::*; |
| 924 | use crate::database::{Database, init_test_db}; | 924 | use crate::database::{Database, init_test_db}; |
| 925 | use crate::domain::role::Role; | 925 | use crate::domain::role::Role; |
| 926 | - use crate::domain::user::{Password, Username}; | 926 | + use crate::domain::user::Username; |
| 927 | 927 | ||
| 928 | /// A user at `role`, minted through the real create path. | 928 | /// A user at `role`, minted through the real create path. |
| 929 | async fn user(username: &str, role: Role, db: &Database) -> User { | 929 | async fn user(username: &str, role: Role, db: &Database) -> User { |
| 930 | - let hash = Password::try_new("secret1") | 930 | + let user = crate::service::user::create(db, Username::try_new(username).unwrap(), None) |
| 931 | - .unwrap() | ||
| 932 | - .hash_async() | ||
| 933 | - .await | ||
| 934 | - .unwrap(); | ||
| 935 | - let user = crate::service::user::create(db, Username::try_new(username).unwrap(), hash) | ||
| 936 | .await | 931 | .await |
| 937 | .unwrap(); | 932 | .unwrap(); |
| 938 | crate::service::user::set_role(db, user.get_id(), role) | 933 | crate::service::user::set_role(db, user.get_id(), role) |
src/web/board_ws.rsmodified+7 -16
| @@ -672,24 +672,15 @@ mod tests { | |||
| 672 | #[tokio::test] | 672 | #[tokio::test] |
| 673 | async fn a_demotion_bars_the_open_socket_from_every_write() { | 673 | async fn a_demotion_bars_the_open_socket_from_every_write() { |
| 674 | use crate::domain::board::BoardTitle; | 674 | use crate::domain::board::BoardTitle; |
| 675 | - use crate::domain::user::{Password, Username}; | 675 | + use crate::domain::user::Username; |
| 676 | 676 | ||
| 677 | let (db, _leases) = crate::database::init_test_db().await; | 677 | let (db, _leases) = crate::database::init_test_db().await; |
| 678 | - let password = Password::try_new("secret1").unwrap(); | 678 | + let creator = crate::service::user::create(&db, Username::try_new("ogretmen").unwrap(), None) |
| 679 | - let creator = crate::service::user::create( | 679 | + .await |
| 680 | - &db, | 680 | + .unwrap(); |
| 681 | - Username::try_new("ogretmen").unwrap(), | 681 | + let mate = crate::service::user::create(&db, Username::try_new("ogrenci").unwrap(), None) |
| 682 | - password.hash_async().await.unwrap(), | 682 | + .await |
| 683 | - ) | 683 | + .unwrap(); |
| 684 | - .await | ||
| 685 | - .unwrap(); | ||
| 686 | - let mate = crate::service::user::create( | ||
| 687 | - &db, | ||
| 688 | - Username::try_new("ogrenci").unwrap(), | ||
| 689 | - password.hash_async().await.unwrap(), | ||
| 690 | - ) | ||
| 691 | - .await | ||
| 692 | - .unwrap(); | ||
| 693 | let mate_id = *mate.get_id(); | 684 | let mate_id = *mate.get_id(); |
| 694 | let board = board::create( | 685 | let board = board::create( |
| 695 | &db, | 686 | &db, |
src/web/builder.rsmodified+4 -7
| @@ -371,7 +371,8 @@ async fn create_school( | |||
| 371 | 371 | ||
| 372 | let db = st.tenants.create(&slug, &name, modules).await?; | 372 | let db = st.tenants.create(&slug, &name, modules).await?; |
| 373 | let seeded = async { | 373 | let seeded = async { |
| 374 | - crate::service::user::create_with_role(&db, username, password_hash, Role::Admin).await?; | 374 | + crate::service::user::create_with_role(&db, username, Some(*person.get_id()), Role::Admin) |
| 375 | + .await?; | ||
| 375 | // The admin's person gets the membership the school row answers for — | 376 | // The admin's person gets the membership the school row answers for — |
| 376 | // idempotent, so a retried create after a torn pair completes it. | 377 | // idempotent, so a retried create after a torn pair completes it. |
| 377 | service::person::link_school(&st.db, person.get_id(), &slug).await?; | 378 | service::person::link_school(&st.db, person.get_id(), &slug).await?; |
| @@ -774,12 +775,8 @@ async fn reset_admin_password( | |||
| 774 | let user = school_admin(&req.username, &db).await?; | 775 | let user = school_admin(&req.username, &db).await?; |
| 775 | let password_hash = Password::try_new(&req.password)?.hash_async().await?; | 776 | let password_hash = Password::try_new(&req.password)?.hash_async().await?; |
| 776 | 777 | ||
| 777 | - crate::service::user::set_password_hash(&db, user.get_id(), password_hash.clone()) | 778 | + // The credential is the control person's — the one login reads. The |
| 778 | - .await? | 779 | + // school row carries no password at all. |
| 779 | - .ok_or(AppError::NotFound)?; | ||
| 780 | - // The person credential is the one login reads; the school row's copy | ||
| 781 | - // exists so school-side queries keep compiling. Both move together, or a | ||
| 782 | - // reset would leave the old password working everywhere. | ||
| 783 | service::person::set_password_hash(&st.db, user.get_username(), &password_hash).await?; | 780 | service::person::set_password_hash(&st.db, user.get_username(), &password_hash).await?; |
| 784 | // The other half: the new password means nothing while a cookie minted | 781 | // The other half: the new password means nothing while a cookie minted |
| 785 | // under the old one still authenticates — school sessions *and* any | 782 | // under the old one still authenticates — school sessions *and* any |
src/web/chatbot.rsmodified+2 -2
| @@ -907,8 +907,8 @@ mod tests { | |||
| 907 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cafe"); | 907 | let user = UserId::from_key("019732e3-7b00-7000-8000-00000000cafe"); |
| 908 | let thread = ChatbotThreadId::from_key("019732e3-7b00-7000-8000-00000000beef"); | 908 | let thread = ChatbotThreadId::from_key("019732e3-7b00-7000-8000-00000000beef"); |
| 909 | sqlx::query( | 909 | sqlx::query( |
| 910 | - "INSERT INTO app_user (id, username, password_hash) \ | 910 | + "INSERT INTO app_user (id, username, created_at) \ |
| 911 | - VALUES ($1, 'chat-web-fixture', 'x')", | 911 | + VALUES ($1, 'chat-web-fixture', 0)", |
| 912 | ) | 912 | ) |
| 913 | .bind(user.uuid()) | 913 | .bind(user.uuid()) |
| 914 | .execute(&db) | 914 | .execute(&db) |
src/web/classes.rsmodified+4 -12
| @@ -1494,24 +1494,16 @@ mod tests { | |||
| 1494 | #[tokio::test] | 1494 | #[tokio::test] |
| 1495 | async fn an_empty_teacher_is_no_teacher_and_a_student_is_never_one() { | 1495 | async fn an_empty_teacher_is_no_teacher_and_a_student_is_never_one() { |
| 1496 | use crate::domain::role::Role; | 1496 | use crate::domain::role::Role; |
| 1497 | - use crate::domain::user::{Password, Username}; | 1497 | + use crate::domain::user::Username; |
| 1498 | 1498 | ||
| 1499 | let (db, _leases) = crate::database::init_test_db().await; | 1499 | let (db, _leases) = crate::database::init_test_db().await; |
| 1500 | assert!(teacher_or_none(None, &db).await.unwrap().is_none()); | 1500 | assert!(teacher_or_none(None, &db).await.unwrap().is_none()); |
| 1501 | assert!(teacher_or_none(Some(""), &db).await.unwrap().is_none()); | 1501 | assert!(teacher_or_none(Some(""), &db).await.unwrap().is_none()); |
| 1502 | 1502 | ||
| 1503 | let make = async |name: &str, role: Role| { | 1503 | let make = async |name: &str, role: Role| { |
| 1504 | - let user = crate::service::user::create( | 1504 | + let user = crate::service::user::create(&db, Username::try_new(name).unwrap(), None) |
| 1505 | - &db, | 1505 | + .await |
| 1506 | - Username::try_new(name).unwrap(), | 1506 | + .unwrap(); |
| 1507 | - Password::try_new("secret1") | ||
| 1508 | - .unwrap() | ||
| 1509 | - .hash_async() | ||
| 1510 | - .await | ||
| 1511 | - .unwrap(), | ||
| 1512 | - ) | ||
| 1513 | - .await | ||
| 1514 | - .unwrap(); | ||
| 1515 | crate::service::user::set_role(&db, user.get_id(), role) | 1507 | crate::service::user::set_role(&db, user.get_id(), role) |
| 1516 | .await | 1508 | .await |
| 1517 | .unwrap() | 1509 | .unwrap() |
src/web/courses.rsmodified+2 -7
| @@ -1283,16 +1283,11 @@ async fn list_course_sessions( | |||
| 1283 | mod tests { | 1283 | mod tests { |
| 1284 | use super::*; | 1284 | use super::*; |
| 1285 | use crate::database::init_test_db; | 1285 | use crate::database::init_test_db; |
| 1286 | - use crate::domain::user::{Password, Username}; | 1286 | + use crate::domain::user::Username; |
| 1287 | 1287 | ||
| 1288 | /// A user at `role`, minted through the real create path. | 1288 | /// A user at `role`, minted through the real create path. |
| 1289 | async fn user(username: &str, role: Role, db: &Database) -> User { | 1289 | async fn user(username: &str, role: Role, db: &Database) -> User { |
| 1290 | - let hash = Password::try_new("secret1") | 1290 | + let user = crate::service::user::create(db, Username::try_new(username).unwrap(), None) |
| 1291 | - .unwrap() | ||
| 1292 | - .hash_async() | ||
| 1293 | - .await | ||
| 1294 | - .unwrap(); | ||
| 1295 | - let user = crate::service::user::create(db, Username::try_new(username).unwrap(), hash) | ||
| 1296 | .await | 1291 | .await |
| 1297 | .unwrap(); | 1292 | .unwrap(); |
| 1298 | crate::service::user::set_role(db, user.get_id(), role) | 1293 | crate::service::user::set_role(db, user.get_id(), role) |
src/web/events.rsmodified+2 -7
| @@ -913,16 +913,11 @@ async fn unregister( | |||
| 913 | mod tests { | 913 | mod tests { |
| 914 | use super::*; | 914 | use super::*; |
| 915 | use crate::database::init_test_db; | 915 | use crate::database::init_test_db; |
| 916 | - use crate::domain::user::{Password, Username}; | 916 | + use crate::domain::user::Username; |
| 917 | 917 | ||
| 918 | /// A user at `role`, minted through the real create path. | 918 | /// A user at `role`, minted through the real create path. |
| 919 | async fn user(username: &str, role: Role, db: &Database) -> User { | 919 | async fn user(username: &str, role: Role, db: &Database) -> User { |
| 920 | - let hash = Password::try_new("secret1") | 920 | + let user = crate::service::user::create(db, Username::try_new(username).unwrap(), None) |
| 921 | - .unwrap() | ||
| 922 | - .hash_async() | ||
| 923 | - .await | ||
| 924 | - .unwrap(); | ||
| 925 | - let user = crate::service::user::create(db, Username::try_new(username).unwrap(), hash) | ||
| 926 | .await | 921 | .await |
| 927 | .unwrap(); | 922 | .unwrap(); |
| 928 | crate::service::user::set_role(db, user.get_id(), role) | 923 | crate::service::user::set_role(db, user.get_id(), role) |
src/web/mod.rsmodified+4 -12
| @@ -378,21 +378,13 @@ mod tests { | |||
| 378 | async fn undo_if_demoted_repairs_both_assignments_or_neither() { | 378 | async fn undo_if_demoted_repairs_both_assignments_or_neither() { |
| 379 | use crate::domain::class_group::ClassName; | 379 | use crate::domain::class_group::ClassName; |
| 380 | use crate::domain::course::{CourseDescription, CourseKind, CourseTitle}; | 380 | use crate::domain::course::{CourseDescription, CourseKind, CourseTitle}; |
| 381 | - use crate::domain::user::{Password, Username}; | 381 | + use crate::domain::user::Username; |
| 382 | 382 | ||
| 383 | let (db, _leases) = crate::database::init_test_db().await; | 383 | let (db, _leases) = crate::database::init_test_db().await; |
| 384 | let office = crate::db::class_member::tests::fixture_user(&db, "office").await; | 384 | let office = crate::db::class_member::tests::fixture_user(&db, "office").await; |
| 385 | - let teacher = crate::service::user::create( | 385 | + let teacher = crate::service::user::create(&db, Username::try_new("ada").unwrap(), None) |
| 386 | - &db, | 386 | + .await |
| 387 | - Username::try_new("ada").unwrap(), | 387 | + .unwrap(); |
| 388 | - Password::try_new("secret1") | ||
| 389 | - .unwrap() | ||
| 390 | - .hash_async() | ||
| 391 | - .await | ||
| 392 | - .unwrap(), | ||
| 393 | - ) | ||
| 394 | - .await | ||
| 395 | - .unwrap(); | ||
| 396 | crate::service::user::set_role(&db, teacher.get_id(), Role::Teacher) | 388 | crate::service::user::set_role(&db, teacher.get_id(), Role::Teacher) |
| 397 | .await | 389 | .await |
| 398 | .unwrap(); | 390 | .unwrap(); |
src/web/questions.rsmodified+86 -63
| @@ -8,7 +8,8 @@ | |||
| 8 | //! opposite: unmoderated, so their author may edit the body and attach, | 8 | //! opposite: unmoderated, so their author may edit the body and attach, |
| 9 | //! replace, or drop one photo at any time — moderation there is delete-only. | 9 | //! replace, or drop one photo at any time — moderation there is delete-only. |
| 10 | 10 | ||
| 11 | -use crate::web::tenant_state::State; | 11 | +use std::collections::HashMap; |
| 12 | + | ||
| 12 | use axum::Json; | 13 | use axum::Json; |
| 13 | use axum::extract::{DefaultBodyLimit, Multipart, Path, Query}; | 14 | use axum::extract::{DefaultBodyLimit, Multipart, Path, Query}; |
| 14 | use axum::http::StatusCode; | 15 | use axum::http::StatusCode; |
| @@ -22,13 +23,18 @@ use crate::constant::{MAX_MAX_FILE_BYTES, POOL_QUESTION_STATUSES, UPLOAD_BODY_OV | |||
| 22 | use crate::domain::pool_question::{ | 23 | use crate::domain::pool_question::{ |
| 23 | PoolQuestion, PoolQuestionBody, PoolQuestionId, PoolQuestionTitle, | 24 | PoolQuestion, PoolQuestionBody, PoolQuestionId, PoolQuestionTitle, |
| 24 | }; | 25 | }; |
| 26 | +use crate::domain::pool_question_image::PoolQuestionImage; | ||
| 25 | use crate::domain::role::Role; | 27 | use crate::domain::role::Role; |
| 26 | use crate::domain::solution::{Solution, SolutionBody, SolutionId}; | 28 | use crate::domain::solution::{Solution, SolutionBody, SolutionId}; |
| 29 | +use crate::domain::solution_image::SolutionImage; | ||
| 27 | use crate::domain::user::User; | 30 | use crate::domain::user::User; |
| 28 | use crate::error::{AppError, ErrorResponse, ValidationError}; | 31 | use crate::error::{AppError, ErrorResponse, ValidationError}; |
| 29 | use crate::service::pool_question; | 32 | use crate::service::pool_question; |
| 33 | +use crate::service::pool_question_image; | ||
| 30 | use crate::service::solution; | 34 | use crate::service::solution; |
| 35 | +use crate::service::solution_image; | ||
| 31 | use crate::state::AppState; | 36 | use crate::state::AppState; |
| 37 | +use crate::web::tenant_state::State; | ||
| 32 | 38 | ||
| 33 | use super::{ | 39 | use super::{ |
| 34 | CurrentUser, Page, PageParams, PersonRef, RequireStudent, RequireTeacher, UploadFileForm, | 40 | CurrentUser, Page, PageParams, PersonRef, RequireStudent, RequireTeacher, UploadFileForm, |
| @@ -157,6 +163,7 @@ impl PoolQuestionResponse { | |||
| 157 | question: &PoolQuestion, | 163 | question: &PoolQuestion, |
| 158 | people: &std::collections::HashMap<String, PersonRef>, | 164 | people: &std::collections::HashMap<String, PersonRef>, |
| 159 | solution_count: i64, | 165 | solution_count: i64, |
| 166 | + image: Option<&PoolQuestionImage>, | ||
| 160 | ) -> Self { | 167 | ) -> Self { |
| 161 | Self { | 168 | Self { |
| 162 | id: question.get_id().key().to_string(), | 169 | id: question.get_id().key().to_string(), |
| @@ -168,12 +175,10 @@ impl PoolQuestionResponse { | |||
| 168 | approved_by: question | 175 | approved_by: question |
| 169 | .get_approved_by() | 176 | .get_approved_by() |
| 170 | .map(|approver| PersonRef::resolve(people, approver)), | 177 | .map(|approver| PersonRef::resolve(people, approver)), |
| 171 | - image: question | 178 | + image: image.map(|image| PoolImageMeta { |
| 172 | - .get_image_content_type() | 179 | + content_type: image.get_content_type().as_str().to_string(), |
| 173 | - .map(|content_type| PoolImageMeta { | 180 | + size: image.get_size(), |
| 174 | - content_type: content_type.as_str().to_string(), | 181 | + }), |
| 175 | - size: question.get_image_size().unwrap_or(0), | ||
| 176 | - }), | ||
| 177 | solution_count, | 182 | solution_count, |
| 178 | } | 183 | } |
| 179 | } | 184 | } |
| @@ -196,19 +201,21 @@ struct SolutionResponse { | |||
| 196 | } | 201 | } |
| 197 | 202 | ||
| 198 | impl SolutionResponse { | 203 | impl SolutionResponse { |
| 199 | - fn new(solution: &Solution, people: &std::collections::HashMap<String, PersonRef>) -> Self { | 204 | + fn new( |
| 205 | + solution: &Solution, | ||
| 206 | + people: &std::collections::HashMap<String, PersonRef>, | ||
| 207 | + image: Option<&SolutionImage>, | ||
| 208 | + ) -> Self { | ||
| 200 | Self { | 209 | Self { |
| 201 | id: solution.get_id().key().to_string(), | 210 | id: solution.get_id().key().to_string(), |
| 202 | question: solution.get_question().key().to_string(), | 211 | question: solution.get_question().key().to_string(), |
| 203 | author: PersonRef::resolve(people, solution.get_author()), | 212 | author: PersonRef::resolve(people, solution.get_author()), |
| 204 | body: solution.get_body().as_str().to_string(), | 213 | body: solution.get_body().as_str().to_string(), |
| 205 | offered_at: solution.get_offered_at().as_millis(), | 214 | offered_at: solution.get_offered_at().as_millis(), |
| 206 | - image: solution | 215 | + image: image.map(|image| PoolImageMeta { |
| 207 | - .get_image_content_type() | 216 | + content_type: image.get_content_type().as_str().to_string(), |
| 208 | - .map(|content_type| PoolImageMeta { | 217 | + size: image.get_size(), |
| 209 | - content_type: content_type.as_str().to_string(), | 218 | + }), |
| 210 | - size: solution.get_image_size().unwrap_or(0), | ||
| 211 | - }), | ||
| 212 | } | 219 | } |
| 213 | } | 220 | } |
| 214 | } | 221 | } |
| @@ -229,11 +236,19 @@ async fn question_responses( | |||
| 229 | .map(|question| *question.get_id()) | 236 | .map(|question| *question.get_id()) |
| 230 | .collect(); | 237 | .collect(); |
| 231 | let counts = solution::counts_for(&st.db, &question_ids).await?; | 238 | let counts = solution::counts_for(&st.db, &question_ids).await?; |
| 239 | + // The photos bucket onto the page in one query, exactly like the | ||
| 240 | + // solution tallies — never an image read per row. | ||
| 241 | + let image_refs: Vec<&PoolQuestionId> = questions.iter().map(|q| q.get_id()).collect(); | ||
| 242 | + let mut images: HashMap<String, PoolQuestionImage> = HashMap::new(); | ||
| 243 | + for image in pool_question_image::list_for_questions(&st.db, &image_refs).await? { | ||
| 244 | + images.insert(image.get_question().key(), image); | ||
| 245 | + } | ||
| 232 | Ok(questions | 246 | Ok(questions |
| 233 | .iter() | 247 | .iter() |
| 234 | .map(|question| { | 248 | .map(|question| { |
| 235 | let count = counts.get(&question.get_id().key()).copied().unwrap_or(0); | 249 | let count = counts.get(&question.get_id().key()).copied().unwrap_or(0); |
| 236 | - PoolQuestionResponse::new(question, &people, count) | 250 | + let image = images.get(question.get_id().key().as_str()); |
| 251 | + PoolQuestionResponse::new(question, &people, count, image) | ||
| 237 | }) | 252 | }) |
| 238 | .collect()) | 253 | .collect()) |
| 239 | } | 254 | } |
| @@ -426,19 +441,14 @@ async fn delete_question( | |||
| 426 | "only the asker or a teacher+ may delete a question", | 441 | "only the asker or a teacher+ may delete a question", |
| 427 | )); | 442 | )); |
| 428 | } | 443 | } |
| 429 | - let (removed, swept) = pool_question::delete(&st.db, question.get_id()) | 444 | + let removed = pool_question::delete(&st.db, question.get_id()) |
| 430 | .await? | 445 | .await? |
| 431 | .ok_or(AppError::NotFound)?; | 446 | .ok_or(AppError::NotFound)?; |
| 432 | - // Rows went first (in one transaction); now every blob they pointed at — | 447 | + // Rows went first (in one transaction); now every blob they named — the |
| 433 | - // the question's photo and each swept solution's — comes off disk. | 448 | + // question's photo and each swept solution's — comes off disk. |
| 434 | - if let Some(file) = removed.get_image_file() { | 449 | + for file in &removed.image_files { |
| 435 | remove_blob(&st.files_path, file).await; | 450 | remove_blob(&st.files_path, file).await; |
| 436 | } | 451 | } |
| 437 | - for solution in &swept { | ||
| 438 | - if let Some(file) = solution.get_image_file() { | ||
| 439 | - remove_blob(&st.files_path, file).await; | ||
| 440 | - } | ||
| 441 | - } | ||
| 442 | Ok(StatusCode::NO_CONTENT) | 452 | Ok(StatusCode::NO_CONTENT) |
| 443 | } | 453 | } |
| 444 | 454 | ||
| @@ -489,7 +499,7 @@ async fn upload_image( | |||
| 489 | { | 499 | { |
| 490 | // The guarded UPDATE found the question still pending: point-of-truth | 500 | // The guarded UPDATE found the question still pending: point-of-truth |
| 491 | // write done; the replaced blob (if any) comes off disk. | 501 | // write done; the replaced blob (if any) comes off disk. |
| 492 | - Some(before) => Ok(((), before.get_image_file().map(str::to_string))), | 502 | + Some(replaced) => Ok(((), replaced)), |
| 493 | // Approved or deleted mid-upload — the fresh blob is an orphan. | 503 | // Approved or deleted mid-upload — the fresh blob is an orphan. |
| 494 | None => Err(AppError::Conflict("the question is no longer pending")), | 504 | None => Err(AppError::Conflict("the question is no longer pending")), |
| 495 | } | 505 | } |
| @@ -526,11 +536,12 @@ async fn get_image( | |||
| 526 | ) -> Result<Response, AppError> { | 536 | ) -> Result<Response, AppError> { |
| 527 | let question = question_or_404(&st, &id).await?; | 537 | let question = question_or_404(&st, &id).await?; |
| 528 | ensure_visible(&question, &user)?; | 538 | ensure_visible(&question, &user)?; |
| 529 | - match (question.get_image_file(), question.get_image_content_type()) { | 539 | + let image = pool_question_image::read(&st.db, question.get_id()).await?; |
| 530 | - (Some(file), Some(content_type)) => { | 540 | + match image { |
| 531 | - serve_inline_blob(&st.files_path, file, content_type).await | 541 | + Some(image) => { |
| 542 | + serve_inline_blob(&st.files_path, image.get_file(), image.get_content_type()).await | ||
| 532 | } | 543 | } |
| 533 | - _ => Err(AppError::NotFound), | 544 | + None => Err(AppError::NotFound), |
| 534 | } | 545 | } |
| 535 | } | 546 | } |
| 536 | 547 | ||
| @@ -557,16 +568,17 @@ async fn delete_image( | |||
| 557 | ) -> Result<StatusCode, AppError> { | 568 | ) -> Result<StatusCode, AppError> { |
| 558 | let question = question_or_404(&st, &id).await?; | 569 | let question = question_or_404(&st, &id).await?; |
| 559 | ensure_asker_editable(&question, &user)?; | 570 | ensure_asker_editable(&question, &user)?; |
| 560 | - if question.get_image_file().is_none() { | 571 | + match pool_question::clear_image(&st.db, question.get_id()).await? { |
| 561 | - return Err(AppError::NotFound); | 572 | + // Detached: the blob comes off disk. |
| 562 | - } | 573 | + Some(Some(file)) => { |
| 563 | - let before = pool_question::clear_image(&st.db, question.get_id()) | 574 | + remove_blob(&st.files_path, &file).await; |
| 564 | - .await? | 575 | + Ok(StatusCode::NO_CONTENT) |
| 565 | - .ok_or(AppError::Conflict("the question is no longer pending"))?; | 576 | + } |
| 566 | - if let Some(file) = before.get_image_file() { | 577 | + // Still pending, but there was no image to remove. |
| 567 | - remove_blob(&st.files_path, file).await; | 578 | + Some(None) => Err(AppError::NotFound), |
| 579 | + // Approved or deleted mid-flight — content is frozen or gone. | ||
| 580 | + None => Err(AppError::Conflict("the question is no longer pending")), | ||
| 568 | } | 581 | } |
| 569 | - Ok(StatusCode::NO_CONTENT) | ||
| 570 | } | 582 | } |
| 571 | 583 | ||
| 572 | // ---- solutions -------------------------------------------------------------- | 584 | // ---- solutions -------------------------------------------------------------- |
| @@ -647,7 +659,7 @@ async fn offer_solution( | |||
| 647 | let people = person_map([*user.get_id()], &st.db).await?; | 659 | let people = person_map([*user.get_id()], &st.db).await?; |
| 648 | Ok(( | 660 | Ok(( |
| 649 | StatusCode::CREATED, | 661 | StatusCode::CREATED, |
| 650 | - Json(SolutionResponse::new(&solution, &people)), | 662 | + Json(SolutionResponse::new(&solution, &people, None)), |
| 651 | )) | 663 | )) |
| 652 | } | 664 | } |
| 653 | 665 | ||
| @@ -678,14 +690,18 @@ async fn list_solutions( | |||
| 678 | ensure_visible(&question, &user)?; | 690 | ensure_visible(&question, &user)?; |
| 679 | let (solutions, total) = solution::list_for(&st.db, question.get_id(), limit, offset).await?; | 691 | let (solutions, total) = solution::list_for(&st.db, question.get_id(), limit, offset).await?; |
| 680 | let slice = solutions.as_slice(); | 692 | let slice = solutions.as_slice(); |
| 681 | - let people = person_map( | 693 | + let people = person_map(slice.iter().map(|solution| *solution.get_author()), &st.db).await?; |
| 682 | - slice.iter().map(|solution| *solution.get_author()), | 694 | + let solution_refs: Vec<&SolutionId> = slice.iter().map(|s| s.get_id()).collect(); |
| 683 | - &st.db, | 695 | + let mut images: HashMap<String, SolutionImage> = HashMap::new(); |
| 684 | - ) | 696 | + for image in solution_image::list_for_solutions(&st.db, &solution_refs).await? { |
| 685 | - .await?; | 697 | + images.insert(image.get_solution().key(), image); |
| 698 | + } | ||
| 686 | let items = slice | 699 | let items = slice |
| 687 | .iter() | 700 | .iter() |
| 688 | - .map(|solution| SolutionResponse::new(solution, &people)) | 701 | + .map(|solution| { |
| 702 | + let image = images.get(solution.get_id().key().as_str()); | ||
| 703 | + SolutionResponse::new(solution, &people, image) | ||
| 704 | + }) | ||
| 689 | .collect(); | 705 | .collect(); |
| 690 | Ok(Json(Page::new(items, total, limit, offset))) | 706 | Ok(Json(Page::new(items, total, limit, offset))) |
| 691 | } | 707 | } |
| @@ -721,9 +737,11 @@ async fn delete_solution( | |||
| 721 | } | 737 | } |
| 722 | // Row first, blob after — a crash in between strands at worst an | 738 | // Row first, blob after — a crash in between strands at worst an |
| 723 | // unreachable file. | 739 | // unreachable file. |
| 724 | - let deleted = solution::delete(&st.db, solution).await?; | 740 | + let (_, image) = solution::delete(&st.db, solution) |
| 725 | - if let Some(file) = deleted.get_image_file() { | 741 | + .await? |
| 726 | - remove_blob(&st.files_path, file).await; | 742 | + .ok_or(AppError::NotFound)?; |
| 743 | + if let Some(file) = image { | ||
| 744 | + remove_blob(&st.files_path, &file).await; | ||
| 727 | } | 745 | } |
| 728 | Ok(StatusCode::NO_CONTENT) | 746 | Ok(StatusCode::NO_CONTENT) |
| 729 | } | 747 | } |
| @@ -764,7 +782,12 @@ async fn edit_solution( | |||
| 764 | .await? | 782 | .await? |
| 765 | .ok_or(AppError::NotFound)?; | 783 | .ok_or(AppError::NotFound)?; |
| 766 | let people = person_map([*user.get_id()], &st.db).await?; | 784 | let people = person_map([*user.get_id()], &st.db).await?; |
| 767 | - Ok(Json(SolutionResponse::new(&updated, &people))) | 785 | + let image = solution_image::read(&st.db, updated.get_id()).await?; |
| 786 | + Ok(Json(SolutionResponse::new( | ||
| 787 | + &updated, | ||
| 788 | + &people, | ||
| 789 | + image.as_ref(), | ||
| 790 | + ))) | ||
| 768 | } | 791 | } |
| 769 | 792 | ||
| 770 | // ---- the solution's photo --------------------------------------------------- | 793 | // ---- the solution's photo --------------------------------------------------- |
| @@ -814,7 +837,7 @@ async fn upload_solution_image( | |||
| 814 | .await? | 837 | .await? |
| 815 | { | 838 | { |
| 816 | // Row write done; the replaced blob (if any) comes off disk. | 839 | // Row write done; the replaced blob (if any) comes off disk. |
| 817 | - Some(before) => Ok(((), before.get_image_file().map(str::to_string))), | 840 | + Some(replaced) => Ok(((), replaced)), |
| 818 | // Deleted mid-upload — the fresh blob is an orphan. | 841 | // Deleted mid-upload — the fresh blob is an orphan. |
| 819 | None => Err(AppError::NotFound), | 842 | None => Err(AppError::NotFound), |
| 820 | } | 843 | } |
| @@ -854,11 +877,12 @@ async fn get_solution_image( | |||
| 854 | Path((id, sid)): Path<(String, String)>, | 877 | Path((id, sid)): Path<(String, String)>, |
| 855 | ) -> Result<Response, AppError> { | 878 | ) -> Result<Response, AppError> { |
| 856 | let solution = visible_solution(&st, &user, &id, &sid).await?; | 879 | let solution = visible_solution(&st, &user, &id, &sid).await?; |
| 857 | - match (solution.get_image_file(), solution.get_image_content_type()) { | 880 | + let image = solution_image::read(&st.db, solution.get_id()).await?; |
| 858 | - (Some(file), Some(content_type)) => { | 881 | + match image { |
| 859 | - serve_inline_blob(&st.files_path, file, content_type).await | 882 | + Some(image) => { |
| 883 | + serve_inline_blob(&st.files_path, image.get_file(), image.get_content_type()).await | ||
| 860 | } | 884 | } |
| 861 | - _ => Err(AppError::NotFound), | 885 | + None => Err(AppError::NotFound), |
| 862 | } | 886 | } |
| 863 | } | 887 | } |
| 864 | 888 | ||
| @@ -886,14 +910,13 @@ async fn delete_solution_image( | |||
| 886 | Path((id, sid)): Path<(String, String)>, | 910 | Path((id, sid)): Path<(String, String)>, |
| 887 | ) -> Result<StatusCode, AppError> { | 911 | ) -> Result<StatusCode, AppError> { |
| 888 | let solution = author_solution(&st, &user, &id, &sid).await?; | 912 | let solution = author_solution(&st, &user, &id, &sid).await?; |
| 889 | - if solution.get_image_file().is_none() { | 913 | + match solution::clear_image(&st.db, solution.get_id()).await? { |
| 890 | - return Err(AppError::NotFound); | 914 | + // Detached: the blob comes off disk. |
| 891 | - } | 915 | + Some(Some(file)) => { |
| 892 | - let before = solution::clear_image(&st.db, solution.get_id()) | 916 | + remove_blob(&st.files_path, &file).await; |
| 893 | - .await? | 917 | + Ok(StatusCode::NO_CONTENT) |
| 894 | - .ok_or(AppError::NotFound)?; | 918 | + } |
| 895 | - if let Some(file) = before.get_image_file() { | 919 | + // Gone, or there was no image to remove. |
| 896 | - remove_blob(&st.files_path, file).await; | 920 | + _ => Err(AppError::NotFound), |
| 897 | } | 921 | } |
| 898 | - Ok(StatusCode::NO_CONTENT) | ||
| 899 | } | 922 | } |
src/web/tenant_state.rsmodified+3 -11
| @@ -203,17 +203,9 @@ mod tests { | |||
| 203 | .await | 203 | .await |
| 204 | .expect("the demo school"); | 204 | .expect("the demo school"); |
| 205 | 205 | ||
| 206 | - let user = crate::service::user::create( | 206 | + let user = crate::service::user::create(&school, Username::try_new("ada").unwrap(), None) |
| 207 | - &school, | 207 | + .await |
| 208 | - Username::try_new("ada").unwrap(), | 208 | + .unwrap(); |
| 209 | - Password::try_new("secret1") | ||
| 210 | - .unwrap() | ||
| 211 | - .hash_async() | ||
| 212 | - .await | ||
| 213 | - .unwrap(), | ||
| 214 | - ) | ||
| 215 | - .await | ||
| 216 | - .unwrap(); | ||
| 217 | let session = session::create(&school, user.get_id()).await.unwrap(); | 209 | let session = session::create(&school, user.get_id()).await.unwrap(); |
| 218 | let school_cookie = format!("session={DEMO_SLUG}.{}", session.token().as_str()); | 210 | let school_cookie = format!("session={DEMO_SLUG}.{}", session.token().as_str()); |
| 219 | 211 | ||
tests/builder_api.rsmodified+3 -11
| @@ -425,17 +425,9 @@ async fn resetting_an_admin_password_revokes_the_old_credential_and_its_sessions | |||
| 425 | .get(&hezarfen_backend::tenant::Slug::try_new("gamma").unwrap()) | 425 | .get(&hezarfen_backend::tenant::Slug::try_new("gamma").unwrap()) |
| 426 | .await | 426 | .await |
| 427 | .unwrap(); | 427 | .unwrap(); |
| 428 | - hezarfen_backend::db::user::create( | 428 | + hezarfen_backend::db::user::create(&gamma_db, Username::try_new("veli").unwrap(), None) |
| 429 | - &gamma_db, | 429 | + .await |
| 430 | - Username::try_new("veli").unwrap(), | 430 | + .unwrap(); |
| 431 | - Password::try_new("secret1") | ||
| 432 | - .unwrap() | ||
| 433 | - .hash_async() | ||
| 434 | - .await | ||
| 435 | - .unwrap(), | ||
| 436 | - ) | ||
| 437 | - .await | ||
| 438 | - .unwrap(); | ||
| 439 | assert_eq!( | 431 | assert_eq!( |
| 440 | send( | 432 | send( |
| 441 | &app, | 433 | &app, |
tests/regress_classes.rsmodified+2 -2
| @@ -35,8 +35,8 @@ async fn rows(sql: &'static str, db: &Database) -> i64 { | |||
| 35 | /// hash is a stub. | 35 | /// hash is a stub. |
| 36 | async fn fixture_user(db: &Database, username: &str) -> UserId { | 36 | async fn fixture_user(db: &Database, username: &str) -> UserId { |
| 37 | sqlx::query( | 37 | sqlx::query( |
| 38 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 38 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 39 | - VALUES ($1, $2, 'x', 'student') ON CONFLICT DO NOTHING", | 39 | + VALUES ($1, $2, 0, 'student') ON CONFLICT DO NOTHING", |
| 40 | ) | 40 | ) |
| 41 | .bind(UserId::generate().uuid()) | 41 | .bind(UserId::generate().uuid()) |
| 42 | .bind(username) | 42 | .bind(username) |
tests/regress_course_child_orphans.rsmodified+2 -2
| @@ -60,8 +60,8 @@ async fn teacher(db: &Database) -> UserId { | |||
| 60 | // Creator columns are foreign keys now, so the fixture teacher is a row, | 60 | // Creator columns are foreign keys now, so the fixture teacher is a row, |
| 61 | // not a fabricated id. It never logs in, so the hash is a stub. | 61 | // not a fabricated id. It never logs in, so the hash is a stub. |
| 62 | sqlx::query( | 62 | sqlx::query( |
| 63 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 63 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 64 | - VALUES ($1, 'doktor', 'x', 'teacher') ON CONFLICT DO NOTHING", | 64 | + VALUES ($1, 'doktor', 0, 'teacher') ON CONFLICT DO NOTHING", |
| 65 | ) | 65 | ) |
| 66 | .bind(UserId::generate().uuid()) | 66 | .bind(UserId::generate().uuid()) |
| 67 | .execute(db) | 67 | .execute(db) |
tests/regress_payments.rsmodified+2 -2
| @@ -61,8 +61,8 @@ async fn ledger(app: &axum::Router, mgr: &str, student: &str) -> Vec<Value> { | |||
| 61 | /// hash is a stub. | 61 | /// hash is a stub. |
| 62 | async fn fixture_user(db: &Database, username: &str) -> UserId { | 62 | async fn fixture_user(db: &Database, username: &str) -> UserId { |
| 63 | sqlx::query( | 63 | sqlx::query( |
| 64 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 64 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 65 | - VALUES ($1, $2, 'x', 'student') ON CONFLICT DO NOTHING", | 65 | + VALUES ($1, $2, 0, 'student') ON CONFLICT DO NOTHING", |
| 66 | ) | 66 | ) |
| 67 | .bind(UserId::generate().uuid()) | 67 | .bind(UserId::generate().uuid()) |
| 68 | .bind(username) | 68 | .bind(username) |
tests/regress_role_sweep.rsmodified+2 -2
| @@ -61,8 +61,8 @@ async fn counter(column: &str, table: &str, db: &Database) -> i64 { | |||
| 61 | /// whichever call minted it. These actors never log in, so the hash is a stub. | 61 | /// whichever call minted it. These actors never log in, so the hash is a stub. |
| 62 | async fn fixture_actor(db: &Database, username: &str) -> UserId { | 62 | async fn fixture_actor(db: &Database, username: &str) -> UserId { |
| 63 | sqlx::query( | 63 | sqlx::query( |
| 64 | - "INSERT INTO app_user (id, username, password_hash, role) \ | 64 | + "INSERT INTO app_user (id, username, created_at, role) \ |
| 65 | - VALUES ($1, $2, 'x', 'student') ON CONFLICT DO NOTHING", | 65 | + VALUES ($1, $2, 0, 'student') ON CONFLICT DO NOTHING", |
| 66 | ) | 66 | ) |
| 67 | .bind(UserId::generate().uuid()) | 67 | .bind(UserId::generate().uuid()) |
| 68 | .bind(username) | 68 | .bind(username) |