Add lessons domain Phase 1: instructor and lesson type entities
Foundation tables for the lessons module with full CRUD, pagination, search, and sorting. Includes migration, Drizzle schema, Zod validation, services, routes, and 23 integration tests.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
-- Phase 1: Lessons foundation — instructor + lesson_type tables
|
||||
|
||||
CREATE TYPE "lesson_format" AS ENUM ('private', 'group');
|
||||
|
||||
CREATE TABLE "instructor" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"user_id" uuid REFERENCES "user"("id"),
|
||||
"display_name" varchar(255) NOT NULL,
|
||||
"bio" text,
|
||||
"instruments" text[],
|
||||
"is_active" boolean NOT NULL DEFAULT true,
|
||||
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||
"updated_at" timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE "lesson_type" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"name" varchar(255) NOT NULL,
|
||||
"instrument" varchar(100),
|
||||
"duration_minutes" integer NOT NULL,
|
||||
"lesson_format" lesson_format NOT NULL DEFAULT 'private',
|
||||
"base_rate_monthly" varchar(20),
|
||||
"is_active" boolean NOT NULL DEFAULT true,
|
||||
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||
"updated_at" timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
@@ -197,6 +197,13 @@
|
||||
"when": 1774870000000,
|
||||
"tag": "0027_generalize_terminology",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 28,
|
||||
"version": "7",
|
||||
"when": 1774880000000,
|
||||
"tag": "0028_lessons_foundation",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
47
packages/backend/src/db/schema/lessons.ts
Normal file
47
packages/backend/src/db/schema/lessons.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
varchar,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core'
|
||||
import { users } from './users.js'
|
||||
|
||||
// --- Enums ---
|
||||
|
||||
export const lessonFormatEnum = pgEnum('lesson_format', ['private', 'group'])
|
||||
|
||||
// --- Tables ---
|
||||
|
||||
export const instructors = pgTable('instructor', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id),
|
||||
displayName: varchar('display_name', { length: 255 }).notNull(),
|
||||
bio: text('bio'),
|
||||
instruments: text('instruments').array(),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export const lessonTypes = pgTable('lesson_type', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
instrument: varchar('instrument', { length: 100 }),
|
||||
durationMinutes: integer('duration_minutes').notNull(),
|
||||
lessonFormat: lessonFormatEnum('lesson_format').notNull().default('private'),
|
||||
baseRateMonthly: varchar('base_rate_monthly', { length: 20 }),
|
||||
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
|
||||
Reference in New Issue
Block a user