Add lessons Phase 2: schedule slots with conflict detection
Recurring weekly time slots linking instructors to lesson types. Includes day/time overlap detection, instructor and day-of-week filtering, and 17 new integration tests (40 total lessons tests).
This commit is contained in:
14
packages/backend/src/db/migrations/0029_schedule_slots.sql
Normal file
14
packages/backend/src/db/migrations/0029_schedule_slots.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Phase 2: Schedule slots — recurring weekly time slots
|
||||
|
||||
CREATE TABLE "schedule_slot" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"instructor_id" uuid NOT NULL REFERENCES "instructor"("id"),
|
||||
"lesson_type_id" uuid NOT NULL REFERENCES "lesson_type"("id"),
|
||||
"day_of_week" integer NOT NULL,
|
||||
"start_time" time NOT NULL,
|
||||
"room" varchar(100),
|
||||
"max_students" integer NOT NULL DEFAULT 1,
|
||||
"is_active" boolean NOT NULL DEFAULT true,
|
||||
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||
"updated_at" timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
@@ -204,6 +204,13 @@
|
||||
"when": 1774880000000,
|
||||
"tag": "0028_lessons_foundation",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 29,
|
||||
"version": "7",
|
||||
"when": 1774890000000,
|
||||
"tag": "0029_schedule_slots",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
uuid,
|
||||
varchar,
|
||||
text,
|
||||
time,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
@@ -39,9 +40,28 @@ export const lessonTypes = pgTable('lesson_type', {
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export const scheduleSlots = pgTable('schedule_slot', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
instructorId: uuid('instructor_id')
|
||||
.notNull()
|
||||
.references(() => instructors.id),
|
||||
lessonTypeId: uuid('lesson_type_id')
|
||||
.notNull()
|
||||
.references(() => lessonTypes.id),
|
||||
dayOfWeek: integer('day_of_week').notNull(), // 0=Sunday, 6=Saturday
|
||||
startTime: time('start_time').notNull(),
|
||||
room: varchar('room', { length: 100 }),
|
||||
maxStudents: integer('max_students').notNull().default(1),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
// --- Type exports ---
|
||||
|
||||
export type Instructor = typeof instructors.$inferSelect
|
||||
export type InstructorInsert = typeof instructors.$inferInsert
|
||||
export type LessonType = typeof lessonTypes.$inferSelect
|
||||
export type LessonTypeInsert = typeof lessonTypes.$inferInsert
|
||||
export type ScheduleSlot = typeof scheduleSlots.$inferSelect
|
||||
export type ScheduleSlotInsert = typeof scheduleSlots.$inferInsert
|
||||
|
||||
Reference in New Issue
Block a user