@@ -73,6 +73,32 @@ export const seedAll = internalMutation({
7373 programUrl : v . string ( ) ,
7474 } ) ,
7575 ) ,
76+ students : v . array (
77+ v . object ( {
78+ userId : v . string ( ) ,
79+ programs : v . array ( v . string ( ) ) ,
80+ school : schoolName ,
81+ schoolLevel : v . union ( v . literal ( "undergraduate" ) , v . literal ( "graduate" ) ) ,
82+ startingDate : v . object ( {
83+ year : v . number ( ) ,
84+ term : v . union (
85+ v . literal ( "spring" ) ,
86+ v . literal ( "summer" ) ,
87+ v . literal ( "fall" ) ,
88+ v . literal ( "j-term" ) ,
89+ ) ,
90+ } ) ,
91+ expectedGraduationDate : v . object ( {
92+ year : v . number ( ) ,
93+ term : v . union (
94+ v . literal ( "spring" ) ,
95+ v . literal ( "summer" ) ,
96+ v . literal ( "fall" ) ,
97+ v . literal ( "j-term" ) ,
98+ ) ,
99+ } ) ,
100+ } ) ,
101+ ) ,
76102 courses : v . array (
77103 v . object ( {
78104 code : v . string ( ) ,
@@ -363,7 +389,55 @@ export const seedAll = internalMutation({
363389 }
364390 }
365391
366- // 7. Seed user courses
392+ // 7. Seed students
393+ console . log ( "👨 Seeding students..." ) ;
394+ for ( const student of args . students ) {
395+ // Get school ID by both name and level
396+ const school = await ctx . db
397+ . query ( "schools" )
398+ . withIndex ( "by_name_level" , ( q ) =>
399+ q . eq ( "name" , student . school ) . eq ( "level" , student . schoolLevel ) ,
400+ )
401+ . unique ( ) ;
402+ if ( ! school ) {
403+ console . warn (
404+ `School not found: ${ student . school } (${ student . schoolLevel } )` ,
405+ ) ;
406+ continue ;
407+ }
408+
409+ // Convert program names to IDs
410+ const programIds : Id < "programs" > [ ] = [ ] ;
411+ for ( const programName of student . programs ) {
412+ const programId = programMap . get ( programName ) ;
413+ if ( programId ) {
414+ programIds . push ( programId ) ;
415+ } else {
416+ console . warn ( `Program not found: ${ programName } ` ) ;
417+ }
418+ }
419+
420+ const existing = await ctx . db
421+ . query ( "students" )
422+ . withIndex ( "by_user_id" , ( q ) => q . eq ( "userId" , student . userId ) )
423+ . first ( ) ;
424+
425+ const studentData = {
426+ userId : student . userId ,
427+ programs : programIds ,
428+ school : school . _id ,
429+ startingDate : student . startingDate ,
430+ expectedGraduationDate : student . expectedGraduationDate ,
431+ } ;
432+
433+ if ( existing ) {
434+ await ctx . db . patch ( existing . _id , studentData ) ;
435+ } else {
436+ await ctx . db . insert ( "students" , studentData ) ;
437+ }
438+ }
439+
440+ // 8. Seed user courses
367441 console . log ( "📚 Seeding user courses..." ) ;
368442 for ( const userCourse of args . userCourses ) {
369443 const existing = await ctx . db
0 commit comments