@studious-lms/server 1.2.45 → 1.2.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/.env.example +45 -0
  2. package/.env.test.example +37 -0
  3. package/README.md +34 -7
  4. package/coverage/base.css +224 -0
  5. package/coverage/block-navigation.js +87 -0
  6. package/coverage/clover.xml +12110 -0
  7. package/coverage/coverage-final.json +44 -0
  8. package/coverage/favicon.png +0 -0
  9. package/coverage/index.html +221 -0
  10. package/coverage/prettify.css +1 -0
  11. package/coverage/prettify.js +2 -0
  12. package/coverage/server/index.html +116 -0
  13. package/coverage/server/src/exportType.ts.html +109 -0
  14. package/coverage/server/src/index.html +161 -0
  15. package/coverage/server/src/index.ts.html +1702 -0
  16. package/coverage/server/src/instrument.ts.html +130 -0
  17. package/coverage/server/src/lib/config/env.ts.html +448 -0
  18. package/coverage/server/src/lib/config/index.html +116 -0
  19. package/coverage/server/src/lib/fileUpload.ts.html +1138 -0
  20. package/coverage/server/src/lib/googleCloudStorage.ts.html +334 -0
  21. package/coverage/server/src/lib/index.html +206 -0
  22. package/coverage/server/src/lib/jsonConversion.ts.html +2323 -0
  23. package/coverage/server/src/lib/jsonStyles.ts.html +193 -0
  24. package/coverage/server/src/lib/notificationHandler.ts.html +193 -0
  25. package/coverage/server/src/lib/pusher.ts.html +121 -0
  26. package/coverage/server/src/lib/thumbnailGenerator.ts.html +592 -0
  27. package/coverage/server/src/middleware/auth.ts.html +646 -0
  28. package/coverage/server/src/middleware/index.html +146 -0
  29. package/coverage/server/src/middleware/logging.ts.html +244 -0
  30. package/coverage/server/src/middleware/security.ts.html +271 -0
  31. package/coverage/server/src/routers/_app.ts.html +232 -0
  32. package/coverage/server/src/routers/agenda.ts.html +319 -0
  33. package/coverage/server/src/routers/announcement.ts.html +3481 -0
  34. package/coverage/server/src/routers/assignment.ts.html +7633 -0
  35. package/coverage/server/src/routers/attendance.ts.html +1030 -0
  36. package/coverage/server/src/routers/auth.ts.html +1081 -0
  37. package/coverage/server/src/routers/class.ts.html +3535 -0
  38. package/coverage/server/src/routers/comment.ts.html +991 -0
  39. package/coverage/server/src/routers/conversation.ts.html +982 -0
  40. package/coverage/server/src/routers/event.ts.html +1609 -0
  41. package/coverage/server/src/routers/file.ts.html +1144 -0
  42. package/coverage/server/src/routers/folder.ts.html +2797 -0
  43. package/coverage/server/src/routers/index.html +386 -0
  44. package/coverage/server/src/routers/labChat.ts.html +3073 -0
  45. package/coverage/server/src/routers/marketing.ts.html +340 -0
  46. package/coverage/server/src/routers/message.ts.html +1912 -0
  47. package/coverage/server/src/routers/notifications.ts.html +364 -0
  48. package/coverage/server/src/routers/section.ts.html +1120 -0
  49. package/coverage/server/src/routers/user.ts.html +862 -0
  50. package/coverage/server/src/routers/worksheet.ts.html +1729 -0
  51. package/coverage/server/src/trpc.ts.html +397 -0
  52. package/coverage/server/src/types/index.html +116 -0
  53. package/coverage/server/src/types/trpc.ts.html +127 -0
  54. package/coverage/server/src/utils/aiUser.ts.html +280 -0
  55. package/coverage/server/src/utils/email.ts.html +121 -0
  56. package/coverage/server/src/utils/generateInviteCode.ts.html +106 -0
  57. package/coverage/server/src/utils/index.html +206 -0
  58. package/coverage/server/src/utils/inference.ts.html +709 -0
  59. package/coverage/server/src/utils/logger.ts.html +664 -0
  60. package/coverage/server/src/utils/prismaErrorHandler.ts.html +907 -0
  61. package/coverage/server/src/utils/prismaWrapper.ts.html +355 -0
  62. package/coverage/server/vitest.config.ts.html +196 -0
  63. package/coverage/sort-arrow-sprite.png +0 -0
  64. package/coverage/sorter.js +210 -0
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +83 -52
  67. package/dist/index.js.map +1 -1
  68. package/dist/instrument.js +15 -8
  69. package/dist/instrument.js.map +1 -1
  70. package/dist/lib/config/env.d.ts +169 -0
  71. package/dist/lib/config/env.d.ts.map +1 -0
  72. package/dist/lib/config/env.js +115 -0
  73. package/dist/lib/config/env.js.map +1 -0
  74. package/dist/lib/fileUpload.d.ts.map +1 -1
  75. package/dist/lib/fileUpload.js +5 -4
  76. package/dist/lib/fileUpload.js.map +1 -1
  77. package/dist/lib/googleCloudStorage.d.ts.map +1 -1
  78. package/dist/lib/googleCloudStorage.js +7 -8
  79. package/dist/lib/googleCloudStorage.js.map +1 -1
  80. package/dist/lib/jsonConversion.d.ts.map +1 -1
  81. package/dist/lib/jsonConversion.js +14 -16
  82. package/dist/lib/jsonConversion.js.map +1 -1
  83. package/dist/lib/notificationHandler.d.ts +2 -2
  84. package/dist/lib/prisma.d.ts +2 -2
  85. package/dist/lib/prisma.d.ts.map +1 -1
  86. package/dist/lib/prisma.js +22 -3
  87. package/dist/lib/prisma.js.map +1 -1
  88. package/dist/lib/pusher.d.ts.map +1 -1
  89. package/dist/lib/pusher.js +8 -7
  90. package/dist/lib/pusher.js.map +1 -1
  91. package/dist/middleware/auth.d.ts.map +1 -1
  92. package/dist/middleware/auth.js +6 -5
  93. package/dist/middleware/auth.js.map +1 -1
  94. package/dist/middleware/security.d.ts +5 -0
  95. package/dist/middleware/security.d.ts.map +1 -0
  96. package/dist/middleware/security.js +77 -0
  97. package/dist/middleware/security.js.map +1 -0
  98. package/dist/routers/_app.d.ts +294 -98
  99. package/dist/routers/_app.d.ts.map +1 -1
  100. package/dist/routers/_app.js +4 -2
  101. package/dist/routers/_app.js.map +1 -1
  102. package/dist/routers/agenda.d.ts.map +1 -1
  103. package/dist/routers/agenda.js +12 -9
  104. package/dist/routers/agenda.js.map +1 -1
  105. package/dist/routers/announcement.d.ts +8 -0
  106. package/dist/routers/announcement.d.ts.map +1 -1
  107. package/dist/routers/announcement.js +6 -4
  108. package/dist/routers/announcement.js.map +1 -1
  109. package/dist/routers/assignment.d.ts +7 -4
  110. package/dist/routers/assignment.d.ts.map +1 -1
  111. package/dist/routers/assignment.js +35 -18
  112. package/dist/routers/assignment.js.map +1 -1
  113. package/dist/routers/attendance.d.ts +1 -0
  114. package/dist/routers/attendance.d.ts.map +1 -1
  115. package/dist/routers/attendance.js +4 -4
  116. package/dist/routers/attendance.js.map +1 -1
  117. package/dist/routers/auth.d.ts +20 -0
  118. package/dist/routers/auth.d.ts.map +1 -1
  119. package/dist/routers/auth.js +132 -15
  120. package/dist/routers/auth.js.map +1 -1
  121. package/dist/routers/class.d.ts +10 -0
  122. package/dist/routers/class.d.ts.map +1 -1
  123. package/dist/routers/class.js +49 -5
  124. package/dist/routers/class.js.map +1 -1
  125. package/dist/routers/comment.d.ts +2 -0
  126. package/dist/routers/comment.d.ts.map +1 -1
  127. package/dist/routers/conversation.d.ts +1 -0
  128. package/dist/routers/conversation.d.ts.map +1 -1
  129. package/dist/routers/conversation.js +46 -31
  130. package/dist/routers/conversation.js.map +1 -1
  131. package/dist/routers/file.d.ts.map +1 -1
  132. package/dist/routers/file.js +30 -7
  133. package/dist/routers/file.js.map +1 -1
  134. package/dist/routers/labChat.d.ts +1 -0
  135. package/dist/routers/labChat.d.ts.map +1 -1
  136. package/dist/routers/labChat.js +2 -3
  137. package/dist/routers/labChat.js.map +1 -1
  138. package/dist/routers/marketing.d.ts +1 -1
  139. package/dist/routers/newtonChat.d.ts +55 -0
  140. package/dist/routers/newtonChat.d.ts.map +1 -0
  141. package/dist/routers/newtonChat.js +438 -0
  142. package/dist/routers/newtonChat.js.map +1 -0
  143. package/dist/routers/notifications.d.ts +4 -4
  144. package/dist/routers/section.d.ts +9 -4
  145. package/dist/routers/section.d.ts.map +1 -1
  146. package/dist/routers/section.js +8 -8
  147. package/dist/routers/section.js.map +1 -1
  148. package/dist/routers/user.d.ts.map +1 -1
  149. package/dist/routers/user.js +5 -4
  150. package/dist/routers/user.js.map +1 -1
  151. package/dist/routers/worksheet.d.ts +30 -36
  152. package/dist/routers/worksheet.d.ts.map +1 -1
  153. package/dist/routers/worksheet.js +11 -33
  154. package/dist/routers/worksheet.js.map +1 -1
  155. package/dist/seedDatabase.d.ts +1 -1
  156. package/dist/seedDatabase.js +275 -284
  157. package/dist/seedDatabase.js.map +1 -1
  158. package/dist/server/pipelines/aiLabChat.d.ts +10 -0
  159. package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
  160. package/dist/server/pipelines/aiLabChat.js +83 -0
  161. package/dist/server/pipelines/aiLabChat.js.map +1 -0
  162. package/dist/server/pipelines/gradeWorksheet.d.ts +2 -0
  163. package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
  164. package/dist/server/pipelines/gradeWorksheet.js +138 -0
  165. package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
  166. package/dist/trpc.d.ts.map +1 -1
  167. package/dist/trpc.js +2 -2
  168. package/dist/trpc.js.map +1 -1
  169. package/dist/utils/email.d.ts +9 -1
  170. package/dist/utils/email.d.ts.map +1 -1
  171. package/dist/utils/email.js +20 -5
  172. package/dist/utils/email.js.map +1 -1
  173. package/dist/utils/inference.d.ts +3 -0
  174. package/dist/utils/inference.d.ts.map +1 -1
  175. package/dist/utils/inference.js +41 -7
  176. package/dist/utils/inference.js.map +1 -1
  177. package/dist/utils/logger.d.ts.map +1 -1
  178. package/dist/utils/logger.js +3 -3
  179. package/dist/utils/logger.js.map +1 -1
  180. package/docker-compose.yml +14 -0
  181. package/package.json +13 -4
  182. package/prisma/schema.prisma +32 -5
  183. package/scripts/test-pre-push.ts +14 -0
  184. package/src/index.ts +98 -54
  185. package/src/instrument.ts +13 -6
  186. package/src/lib/config/env.ts +126 -0
  187. package/src/lib/fileUpload.ts +3 -2
  188. package/src/lib/googleCloudStorage.ts +6 -6
  189. package/src/lib/jsonConversion.ts +12 -14
  190. package/src/lib/prisma.ts +23 -2
  191. package/src/lib/pusher.ts +6 -5
  192. package/src/middleware/auth.ts +4 -3
  193. package/src/middleware/security.ts +80 -0
  194. package/src/routers/_app.ts +2 -0
  195. package/src/routers/agenda.ts +10 -7
  196. package/src/routers/announcement.ts +4 -2
  197. package/src/routers/assignment.ts +58 -40
  198. package/src/routers/attendance.ts +2 -2
  199. package/src/routers/auth.ts +143 -14
  200. package/src/routers/class.ts +52 -3
  201. package/src/routers/conversation.ts +49 -29
  202. package/src/routers/file.ts +29 -5
  203. package/src/routers/labChat.ts +0 -1
  204. package/src/routers/newtonChat.ts +520 -0
  205. package/src/routers/section.ts +6 -6
  206. package/src/routers/user.ts +3 -2
  207. package/src/routers/worksheet.ts +9 -37
  208. package/src/seedDatabase.ts +290 -283
  209. package/src/server/pipelines/aiLabChat.ts +92 -0
  210. package/src/server/pipelines/gradeWorksheet.ts +152 -0
  211. package/src/trpc.ts +2 -0
  212. package/src/utils/email.ts +30 -3
  213. package/src/utils/inference.ts +50 -5
  214. package/src/utils/logger.ts +2 -1
  215. package/tests/announcement.test.ts +164 -0
  216. package/tests/assignment.test.ts +296 -0
  217. package/tests/attendance.test.ts +168 -0
  218. package/tests/auth.test.ts +33 -10
  219. package/tests/class.test.ts +34 -9
  220. package/tests/event.test.ts +228 -0
  221. package/tests/section.test.ts +216 -0
  222. package/tests/setup.ts +70 -16
  223. package/tests/user.test.ts +158 -0
  224. package/vitest.config.ts +26 -0
  225. package/API_SPECIFICATION.md +0 -1597
  226. package/BASE64_REMOVAL_SUMMARY.md +0 -164
  227. package/CHAT_API_SPEC.md +0 -579
  228. package/LAB_CHAT_API_SPEC.md +0 -518
  229. package/dist/routers/school.d.ts +0 -208
  230. package/dist/routers/school.d.ts.map +0 -1
  231. package/dist/routers/school.js +0 -483
@@ -883,10 +883,29 @@ export const seedDatabase = async () => {
883
883
  }
884
884
  }
885
885
 
886
- // Create all submissions
887
- await Promise.all(submissionsToCreate.map(submission =>
888
- prisma.submission.create({ data: submission })
889
- ));
886
+ // Create all submissions in batches to avoid connection pool exhaustion
887
+ const BATCH_SIZE = 15; // Create 15 at a time to avoid overwhelming Supabase connection pool
888
+
889
+ logger.info(`Creating ${submissionsToCreate.length} submissions in batches of ${BATCH_SIZE}`);
890
+
891
+ for (let i = 0; i < submissionsToCreate.length; i += BATCH_SIZE) {
892
+ const batch = submissionsToCreate.slice(i, i + BATCH_SIZE);
893
+ await Promise.all(batch.map(submission =>
894
+ prisma.submission.create({ data: submission })
895
+ ));
896
+
897
+ // Small delay between batches to avoid overwhelming the connection pool
898
+ if (i + BATCH_SIZE < submissionsToCreate.length) {
899
+ await new Promise(resolve => setTimeout(resolve, 100)); // 100ms delay
900
+ }
901
+
902
+ // Log progress every 30 submissions or at the end
903
+ if ((i + BATCH_SIZE) % 30 === 0 || i + BATCH_SIZE >= submissionsToCreate.length) {
904
+ logger.info(`Created ${Math.min(i + BATCH_SIZE, submissionsToCreate.length)}/${submissionsToCreate.length} submissions`);
905
+ }
906
+ }
907
+
908
+ logger.info(`Successfully created all ${submissionsToCreate.length} submissions`);
890
909
 
891
910
  // 11. Create announcements
892
911
  await Promise.all([
@@ -923,290 +942,262 @@ export const seedDatabase = async () => {
923
942
  const oct10 = new Date('2025-10-10T08:00:00');
924
943
  const oct11 = new Date('2025-10-11T08:00:00');
925
944
 
926
- await Promise.all([
945
+ // Build events array first, then batch create them
946
+ const eventsToCreate = [
927
947
  // Monday Oct 7 - Michael Chen's busy day
928
- prisma.event.create({
929
- data: {
930
- name: 'AP Calculus BC - Period 2',
931
- startTime: new Date('2025-10-07T09:15:00'),
932
- endTime: new Date('2025-10-07T10:05:00'),
933
- location: 'Room 156',
934
- remarks: 'Derivatives unit test review',
935
- userId: teachers[1].id,
936
- classId: mathClass.id,
937
- color: '#3B82F6',
938
- }
939
- }),
940
- prisma.event.create({
941
- data: {
942
- name: 'Department Head Meeting',
943
- startTime: new Date('2025-10-07T10:30:00'),
944
- endTime: new Date('2025-10-07T11:30:00'),
945
- location: 'Conference Room A',
946
- remarks: 'Monthly math department meeting - curriculum planning',
947
- userId: teachers[1].id,
948
- color: '#8B5CF6',
949
- }
950
- }),
951
- prisma.event.create({
952
- data: {
953
- name: 'AP Statistics - Period 5',
954
- startTime: new Date('2025-10-07T13:45:00'),
955
- endTime: new Date('2025-10-07T14:35:00'),
956
- location: 'Room 156',
957
- remarks: 'Hypothesis testing introduction',
958
- userId: teachers[1].id,
959
- color: '#3B82F6',
960
- }
961
- }),
962
- prisma.event.create({
963
- data: {
964
- name: 'Parent Conference - Williams Family',
965
- startTime: new Date('2025-10-07T15:00:00'),
966
- endTime: new Date('2025-10-07T15:30:00'),
967
- location: 'Room 156',
968
- remarks: 'Discuss Sophia\'s progress in AP Calculus',
969
- userId: teachers[1].id,
970
- color: '#F59E0B',
971
- }
972
- }),
973
- prisma.event.create({
974
- data: {
975
- name: 'Math Tutoring Session',
976
- startTime: new Date('2025-10-07T15:45:00'),
977
- endTime: new Date('2025-10-07T16:45:00'),
978
- location: 'Room 156',
979
- remarks: 'Extra help for struggling students',
980
- userId: teachers[1].id,
981
- color: '#10B981',
982
- }
983
- }),
948
+ {
949
+ name: 'AP Calculus BC - Period 2',
950
+ startTime: new Date('2025-10-07T09:15:00'),
951
+ endTime: new Date('2025-10-07T10:05:00'),
952
+ location: 'Room 156',
953
+ remarks: 'Derivatives unit test review',
954
+ userId: teachers[1].id,
955
+ classId: mathClass.id,
956
+ color: '#3B82F6',
957
+ },
958
+ {
959
+ name: 'Department Head Meeting',
960
+ startTime: new Date('2025-10-07T10:30:00'),
961
+ endTime: new Date('2025-10-07T11:30:00'),
962
+ location: 'Conference Room A',
963
+ remarks: 'Monthly math department meeting - curriculum planning',
964
+ userId: teachers[1].id,
965
+ color: '#8B5CF6',
966
+ },
967
+ {
968
+ name: 'AP Statistics - Period 5',
969
+ startTime: new Date('2025-10-07T13:45:00'),
970
+ endTime: new Date('2025-10-07T14:35:00'),
971
+ location: 'Room 156',
972
+ remarks: 'Hypothesis testing introduction',
973
+ userId: teachers[1].id,
974
+ color: '#3B82F6',
975
+ },
976
+ {
977
+ name: 'Parent Conference - Williams Family',
978
+ startTime: new Date('2025-10-07T15:00:00'),
979
+ endTime: new Date('2025-10-07T15:30:00'),
980
+ location: 'Room 156',
981
+ remarks: 'Discuss Sophia\'s progress in AP Calculus',
982
+ userId: teachers[1].id,
983
+ color: '#F59E0B',
984
+ },
985
+ {
986
+ name: 'Math Tutoring Session',
987
+ startTime: new Date('2025-10-07T15:45:00'),
988
+ endTime: new Date('2025-10-07T16:45:00'),
989
+ location: 'Room 156',
990
+ remarks: 'Extra help for struggling students',
991
+ userId: teachers[1].id,
992
+ color: '#10B981',
993
+ },
984
994
 
985
995
  // Tuesday Oct 8
986
- prisma.event.create({
987
- data: {
988
- name: 'AP Calculus BC - Period 2',
989
- startTime: new Date('2025-10-08T09:15:00'),
990
- endTime: new Date('2025-10-08T10:05:00'),
991
- location: 'Room 156',
992
- remarks: 'Derivatives unit test',
993
- userId: teachers[1].id,
994
- classId: mathClass.id,
995
- color: '#3B82F6',
996
- }
997
- }),
998
- prisma.event.create({
999
- data: {
1000
- name: 'Faculty Meeting',
1001
- startTime: new Date('2025-10-08T12:00:00'),
1002
- endTime: new Date('2025-10-08T13:00:00'),
1003
- location: 'Main Auditorium',
1004
- remarks: 'All-school faculty meeting',
1005
- userId: teachers[1].id,
1006
- color: '#6B7280',
1007
- }
1008
- }),
1009
- prisma.event.create({
1010
- data: {
1011
- name: 'AP Statistics - Period 5',
1012
- startTime: new Date('2025-10-08T13:45:00'),
1013
- endTime: new Date('2025-10-08T14:35:00'),
1014
- location: 'Room 156',
1015
- remarks: 'Hypothesis testing practice problems',
1016
- userId: teachers[1].id,
1017
- color: '#3B82F6',
1018
- }
1019
- }),
1020
- prisma.event.create({
1021
- data: {
1022
- name: 'Grade Level Team Meeting',
1023
- startTime: new Date('2025-10-08T15:00:00'),
1024
- endTime: new Date('2025-10-08T16:00:00'),
1025
- location: 'Room 201',
1026
- remarks: '11th grade team coordination',
1027
- userId: teachers[1].id,
1028
- color: '#8B5CF6',
1029
- }
1030
- }),
996
+ {
997
+ name: 'AP Calculus BC - Period 2',
998
+ startTime: new Date('2025-10-08T09:15:00'),
999
+ endTime: new Date('2025-10-08T10:05:00'),
1000
+ location: 'Room 156',
1001
+ remarks: 'Derivatives unit test',
1002
+ userId: teachers[1].id,
1003
+ classId: mathClass.id,
1004
+ color: '#3B82F6',
1005
+ },
1006
+ {
1007
+ name: 'Faculty Meeting',
1008
+ startTime: new Date('2025-10-08T12:00:00'),
1009
+ endTime: new Date('2025-10-08T13:00:00'),
1010
+ location: 'Main Auditorium',
1011
+ remarks: 'All-school faculty meeting',
1012
+ userId: teachers[1].id,
1013
+ color: '#6B7280',
1014
+ },
1015
+ {
1016
+ name: 'AP Statistics - Period 5',
1017
+ startTime: new Date('2025-10-08T13:45:00'),
1018
+ endTime: new Date('2025-10-08T14:35:00'),
1019
+ location: 'Room 156',
1020
+ remarks: 'Hypothesis testing practice problems',
1021
+ userId: teachers[1].id,
1022
+ color: '#3B82F6',
1023
+ },
1024
+ {
1025
+ name: 'Grade Level Team Meeting',
1026
+ startTime: new Date('2025-10-08T15:00:00'),
1027
+ endTime: new Date('2025-10-08T16:00:00'),
1028
+ location: 'Room 201',
1029
+ remarks: '11th grade team coordination',
1030
+ userId: teachers[1].id,
1031
+ color: '#8B5CF6',
1032
+ },
1031
1033
 
1032
1034
  // Wednesday Oct 9
1033
- prisma.event.create({
1034
- data: {
1035
- name: 'AP Calculus BC - Period 2',
1036
- startTime: new Date('2025-10-09T09:15:00'),
1037
- endTime: new Date('2025-10-09T10:05:00'),
1038
- location: 'Room 156',
1039
- remarks: 'Integration introduction',
1040
- userId: teachers[1].id,
1041
- classId: mathClass.id,
1042
- color: '#3B82F6',
1043
- }
1044
- }),
1045
- prisma.event.create({
1046
- data: {
1047
- name: 'Professional Development',
1048
- startTime: new Date('2025-10-09T11:00:00'),
1049
- endTime: new Date('2025-10-09T12:30:00'),
1050
- location: 'Library Conference Room',
1051
- remarks: 'Technology in Mathematics Education workshop',
1052
- userId: teachers[1].id,
1053
- color: '#059669',
1054
- }
1055
- }),
1056
- prisma.event.create({
1057
- data: {
1058
- name: 'AP Statistics - Period 5',
1059
- startTime: new Date('2025-10-09T13:45:00'),
1060
- endTime: new Date('2025-10-09T14:35:00'),
1061
- location: 'Room 156',
1062
- remarks: 'Chi-square tests',
1063
- userId: teachers[1].id,
1064
- color: '#3B82F6',
1065
- }
1066
- }),
1067
- prisma.event.create({
1068
- data: {
1069
- name: 'Student Council Advisory',
1070
- startTime: new Date('2025-10-09T15:00:00'),
1071
- endTime: new Date('2025-10-09T16:00:00'),
1072
- location: 'Room 105',
1073
- remarks: 'Advisor meeting for student council',
1074
- userId: teachers[1].id,
1075
- color: '#DC2626',
1076
- }
1077
- }),
1035
+ {
1036
+ name: 'AP Calculus BC - Period 2',
1037
+ startTime: new Date('2025-10-09T09:15:00'),
1038
+ endTime: new Date('2025-10-09T10:05:00'),
1039
+ location: 'Room 156',
1040
+ remarks: 'Integration introduction',
1041
+ userId: teachers[1].id,
1042
+ classId: mathClass.id,
1043
+ color: '#3B82F6',
1044
+ },
1045
+ {
1046
+ name: 'Professional Development',
1047
+ startTime: new Date('2025-10-09T11:00:00'),
1048
+ endTime: new Date('2025-10-09T12:30:00'),
1049
+ location: 'Library Conference Room',
1050
+ remarks: 'Technology in Mathematics Education workshop',
1051
+ userId: teachers[1].id,
1052
+ color: '#059669',
1053
+ },
1054
+ {
1055
+ name: 'AP Statistics - Period 5',
1056
+ startTime: new Date('2025-10-09T13:45:00'),
1057
+ endTime: new Date('2025-10-09T14:35:00'),
1058
+ location: 'Room 156',
1059
+ remarks: 'Chi-square tests',
1060
+ userId: teachers[1].id,
1061
+ color: '#3B82F6',
1062
+ },
1063
+ {
1064
+ name: 'Student Council Advisory',
1065
+ startTime: new Date('2025-10-09T15:00:00'),
1066
+ endTime: new Date('2025-10-09T16:00:00'),
1067
+ location: 'Room 105',
1068
+ remarks: 'Advisor meeting for student council',
1069
+ userId: teachers[1].id,
1070
+ color: '#DC2626',
1071
+ },
1078
1072
 
1079
1073
  // Thursday Oct 10
1080
- prisma.event.create({
1081
- data: {
1082
- name: 'AP Calculus BC - Period 2',
1083
- startTime: new Date('2025-10-10T09:15:00'),
1084
- endTime: new Date('2025-10-10T10:05:00'),
1085
- location: 'Room 156',
1086
- remarks: 'Integration by substitution',
1087
- userId: teachers[1].id,
1088
- classId: mathClass.id,
1089
- color: '#3B82F6',
1090
- }
1091
- }),
1092
- prisma.event.create({
1093
- data: {
1094
- name: 'Curriculum Committee',
1095
- startTime: new Date('2025-10-10T11:00:00'),
1096
- endTime: new Date('2025-10-10T12:00:00'),
1097
- location: 'Principal\'s Office',
1098
- remarks: 'Review new AP curriculum standards',
1099
- userId: teachers[1].id,
1100
- color: '#8B5CF6',
1101
- }
1102
- }),
1103
- prisma.event.create({
1104
- data: {
1105
- name: 'AP Statistics - Period 5',
1106
- startTime: new Date('2025-10-10T13:45:00'),
1107
- endTime: new Date('2025-10-10T14:35:00'),
1108
- location: 'Room 156',
1109
- remarks: 'ANOVA introduction',
1110
- userId: teachers[1].id,
1111
- color: '#3B82F6',
1112
- }
1113
- }),
1114
- prisma.event.create({
1115
- data: {
1116
- name: 'Parent Conference - Anderson Family',
1117
- startTime: new Date('2025-10-10T15:00:00'),
1118
- endTime: new Date('2025-10-10T15:30:00'),
1119
- location: 'Room 156',
1120
- remarks: 'Discuss Ethan\'s improvement strategies',
1121
- userId: teachers[1].id,
1122
- color: '#F59E0B',
1123
- }
1124
- }),
1125
- prisma.event.create({
1126
- data: {
1127
- name: 'Math Club Meeting',
1128
- startTime: new Date('2025-10-10T15:45:00'),
1129
- endTime: new Date('2025-10-10T16:45:00'),
1130
- location: 'Room 156',
1131
- remarks: 'Preparing for state math competition',
1132
- userId: teachers[1].id,
1133
- color: '#10B981',
1134
- }
1135
- }),
1074
+ {
1075
+ name: 'AP Calculus BC - Period 2',
1076
+ startTime: new Date('2025-10-10T09:15:00'),
1077
+ endTime: new Date('2025-10-10T10:05:00'),
1078
+ location: 'Room 156',
1079
+ remarks: 'Integration by substitution',
1080
+ userId: teachers[1].id,
1081
+ classId: mathClass.id,
1082
+ color: '#3B82F6',
1083
+ },
1084
+ {
1085
+ name: 'Curriculum Committee',
1086
+ startTime: new Date('2025-10-10T11:00:00'),
1087
+ endTime: new Date('2025-10-10T12:00:00'),
1088
+ location: 'Principal\'s Office',
1089
+ remarks: 'Review new AP curriculum standards',
1090
+ userId: teachers[1].id,
1091
+ color: '#8B5CF6',
1092
+ },
1093
+ {
1094
+ name: 'AP Statistics - Period 5',
1095
+ startTime: new Date('2025-10-10T13:45:00'),
1096
+ endTime: new Date('2025-10-10T14:35:00'),
1097
+ location: 'Room 156',
1098
+ remarks: 'ANOVA introduction',
1099
+ userId: teachers[1].id,
1100
+ color: '#3B82F6',
1101
+ },
1102
+ {
1103
+ name: 'Parent Conference - Anderson Family',
1104
+ startTime: new Date('2025-10-10T15:00:00'),
1105
+ endTime: new Date('2025-10-10T15:30:00'),
1106
+ location: 'Room 156',
1107
+ remarks: 'Discuss Ethan\'s improvement strategies',
1108
+ userId: teachers[1].id,
1109
+ color: '#F59E0B',
1110
+ },
1111
+ {
1112
+ name: 'Math Club Meeting',
1113
+ startTime: new Date('2025-10-10T15:45:00'),
1114
+ endTime: new Date('2025-10-10T16:45:00'),
1115
+ location: 'Room 156',
1116
+ remarks: 'Preparing for state math competition',
1117
+ userId: teachers[1].id,
1118
+ color: '#10B981',
1119
+ },
1136
1120
 
1137
1121
  // Friday Oct 11
1138
- prisma.event.create({
1139
- data: {
1140
- name: 'AP Calculus BC - Period 2',
1141
- startTime: new Date('2025-10-11T09:15:00'),
1142
- endTime: new Date('2025-10-11T10:05:00'),
1143
- location: 'Room 156',
1144
- remarks: 'Integration by parts',
1145
- userId: teachers[1].id,
1146
- classId: mathClass.id,
1147
- color: '#3B82F6',
1148
- }
1149
- }),
1150
- prisma.event.create({
1151
- data: {
1152
- name: 'IEP Meeting - Student Support',
1153
- startTime: new Date('2025-10-11T10:30:00'),
1154
- endTime: new Date('2025-10-11T11:30:00'),
1155
- location: 'Special Services Office',
1156
- remarks: 'Individualized Education Plan review',
1157
- userId: teachers[1].id,
1158
- color: '#F59E0B',
1159
- }
1160
- }),
1161
- prisma.event.create({
1162
- data: {
1163
- name: 'AP Statistics - Period 5',
1164
- startTime: new Date('2025-10-11T13:45:00'),
1165
- endTime: new Date('2025-10-11T14:35:00'),
1166
- location: 'Room 156',
1167
- remarks: 'ANOVA practice and review',
1168
- userId: teachers[1].id,
1169
- color: '#3B82F6',
1170
- }
1171
- }),
1172
- prisma.event.create({
1173
- data: {
1174
- name: 'Weekend Prep Session',
1175
- startTime: new Date('2025-10-11T15:00:00'),
1176
- endTime: new Date('2025-10-11T17:00:00'),
1177
- location: 'Room 156',
1178
- remarks: 'Voluntary AP exam prep session',
1179
- userId: teachers[1].id,
1180
- color: '#059669',
1181
- }
1182
- }),
1122
+ {
1123
+ name: 'AP Calculus BC - Period 2',
1124
+ startTime: new Date('2025-10-11T09:15:00'),
1125
+ endTime: new Date('2025-10-11T10:05:00'),
1126
+ location: 'Room 156',
1127
+ remarks: 'Integration by parts',
1128
+ userId: teachers[1].id,
1129
+ classId: mathClass.id,
1130
+ color: '#3B82F6',
1131
+ },
1132
+ {
1133
+ name: 'IEP Meeting - Student Support',
1134
+ startTime: new Date('2025-10-11T10:30:00'),
1135
+ endTime: new Date('2025-10-11T11:30:00'),
1136
+ location: 'Special Services Office',
1137
+ remarks: 'Individualized Education Plan review',
1138
+ userId: teachers[1].id,
1139
+ color: '#F59E0B',
1140
+ },
1141
+ {
1142
+ name: 'AP Statistics - Period 5',
1143
+ startTime: new Date('2025-10-11T13:45:00'),
1144
+ endTime: new Date('2025-10-11T14:35:00'),
1145
+ location: 'Room 156',
1146
+ remarks: 'ANOVA practice and review',
1147
+ userId: teachers[1].id,
1148
+ color: '#3B82F6',
1149
+ },
1150
+ {
1151
+ name: 'Weekend Prep Session',
1152
+ startTime: new Date('2025-10-11T15:00:00'),
1153
+ endTime: new Date('2025-10-11T17:00:00'),
1154
+ location: 'Room 156',
1155
+ remarks: 'Voluntary AP exam prep session',
1156
+ userId: teachers[1].id,
1157
+ color: '#059669',
1158
+ },
1183
1159
 
1184
1160
  // Some events for other teachers too
1185
- prisma.event.create({
1186
- data: {
1187
- name: 'Cell Biology Lab',
1188
- startTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000),
1189
- endTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000 + 90 * 60 * 1000), // 90 minutes
1190
- location: 'Science Lab Room 204',
1191
- remarks: 'Bring lab notebooks and safety goggles',
1192
- userId: teachers[0].id,
1193
- classId: biologyClass.id,
1194
- color: '#10B981',
1195
- }
1196
- }),
1197
- prisma.event.create({
1198
- data: {
1199
- name: 'Poetry Reading',
1200
- startTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000),
1201
- endTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000),
1202
- location: 'Library',
1203
- remarks: 'Students will present their original poetry',
1204
- userId: teachers[2].id,
1205
- classId: englishClass.id,
1206
- color: '#8B5CF6',
1207
- }
1208
- }),
1209
- ]);
1161
+ {
1162
+ name: 'Cell Biology Lab',
1163
+ startTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000),
1164
+ endTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000 + 90 * 60 * 1000), // 90 minutes
1165
+ location: 'Science Lab Room 204',
1166
+ remarks: 'Bring lab notebooks and safety goggles',
1167
+ userId: teachers[0].id,
1168
+ classId: biologyClass.id,
1169
+ color: '#10B981',
1170
+ },
1171
+ {
1172
+ name: 'Poetry Reading',
1173
+ startTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000),
1174
+ endTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000),
1175
+ location: 'Library',
1176
+ remarks: 'Students will present their original poetry',
1177
+ userId: teachers[2].id,
1178
+ classId: englishClass.id,
1179
+ color: '#8B5CF6',
1180
+ },
1181
+ ];
1182
+
1183
+ // Create events in batches to avoid connection pool exhaustion
1184
+ const EVENT_BATCH_SIZE = 10;
1185
+
1186
+ logger.info(`Creating ${eventsToCreate.length} events in batches of ${EVENT_BATCH_SIZE}`);
1187
+
1188
+ for (let i = 0; i < eventsToCreate.length; i += EVENT_BATCH_SIZE) {
1189
+ const batch = eventsToCreate.slice(i, i + EVENT_BATCH_SIZE);
1190
+ await Promise.all(batch.map(event =>
1191
+ prisma.event.create({ data: event })
1192
+ ));
1193
+
1194
+ // Small delay between batches
1195
+ if (i + EVENT_BATCH_SIZE < eventsToCreate.length) {
1196
+ await new Promise(resolve => setTimeout(resolve, 100));
1197
+ }
1198
+ }
1199
+
1200
+ logger.info(`Successfully created all ${eventsToCreate.length} events`);
1210
1201
 
1211
1202
  // 13. Create attendance records
1212
1203
  const attendanceDate = new Date(now.getTime() - 24 * 60 * 60 * 1000);
@@ -1511,10 +1502,19 @@ export const seedDatabase = async () => {
1511
1502
  },
1512
1503
  ];
1513
1504
 
1514
- // Create all messages
1515
- await Promise.all(chatMessages.map(message =>
1516
- prisma.message.create({ data: message })
1517
- ));
1505
+ // Create all messages in batches to avoid connection pool exhaustion
1506
+ const MESSAGE_BATCH_SIZE = 10;
1507
+
1508
+ logger.info(`Creating ${chatMessages.length} chat messages in batches of ${MESSAGE_BATCH_SIZE}`);
1509
+
1510
+ for (let i = 0; i < chatMessages.length; i += MESSAGE_BATCH_SIZE) {
1511
+ const batch = chatMessages.slice(i, i + MESSAGE_BATCH_SIZE);
1512
+ await Promise.all(batch.map(message =>
1513
+ prisma.message.create({ data: message })
1514
+ ));
1515
+ }
1516
+
1517
+ logger.info(`Successfully created all ${chatMessages.length} chat messages`);
1518
1518
 
1519
1519
  // 16. Create file structure for classes
1520
1520
  await Promise.all([
@@ -1573,8 +1573,15 @@ export const seedDatabase = async () => {
1573
1573
  logger.info(' Student: alex.martinez@student.riverside.edu / student123');
1574
1574
  };
1575
1575
 
1576
- (async () => {
1576
+ // Only run seedDatabase when executed directly (npm run seed)
1577
+ // Not when imported by other modules
1578
+ const isSeedScript = process.argv[1]?.includes('seedDatabase') ||
1579
+ process.argv.includes('seed');
1580
+
1581
+ if (isSeedScript) {
1582
+ (async () => {
1577
1583
  logger.info('Seeding database');
1578
1584
  await seedDatabase();
1579
1585
  logger.info('Database seeded');
1580
- })();
1586
+ })();
1587
+ }