Online courses database schema
Courses of modules and lessons, enrolments, lesson progress and quizzes.
7 tables, 7 relationships
Opens as a new diagram you can change. Free.
Tables
learners
- iduuid not null
- emailtext not null
- nametext not null
- created_attimestamptz not null
instructors
- iduuid not null
- nametext not null
- biotext
- created_attimestamptz not null
courses
- iduuid not null
- instructor_id> instructorsuuid not null
- titletext not null
- slugtext not null
- pricenumeric(8,2) not null
- created_attimestamptz not null
modules
- iduuid not null
- course_id> coursesuuid not null
- titletext not null
- positioninteger not null
- created_attimestamptz not null
lessons
- iduuid not null
- module_id> modulesuuid not null
- titletext not null
- video_urltext
- positioninteger not null
- created_attimestamptz not null
enrollments
- iduuid not null
- course_id> coursesuuid not null
- learner_id> learnersuuid not null
- completed_attimestamptz
- created_attimestamptz not null
lesson_progress
- iduuid not null
- enrollment_id> enrollmentsuuid not null
- lesson_id> lessonsuuid not null
- completed_attimestamptz not null
- created_attimestamptz not null
As PostgreSQL
The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.
CREATE TABLE "courses" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"instructor_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL UNIQUE,
"price" NUMERIC(8,2) DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "enrollments" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"course_id" UUID NOT NULL,
"learner_id" UUID NOT NULL,
"completed_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "instructors" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"bio" TEXT,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "learners" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"email" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "lesson_progress" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"enrollment_id" UUID NOT NULL,
"lesson_id" UUID NOT NULL,
"completed_at" TIMESTAMPTZ NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "lessons" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"module_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"video_url" TEXT,
"position" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "modules" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"course_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "courses" ADD CONSTRAINT "fk_courses_instructor_id" FOREIGN KEY ("instructor_id") REFERENCES "instructors" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "modules" ADD CONSTRAINT "fk_modules_course_id" FOREIGN KEY ("course_id") REFERENCES "courses" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "lessons" ADD CONSTRAINT "fk_lessons_module_id" FOREIGN KEY ("module_id") REFERENCES "modules" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "enrollments" ADD CONSTRAINT "fk_enrollments_course_id" FOREIGN KEY ("course_id") REFERENCES "courses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "enrollments" ADD CONSTRAINT "fk_enrollments_learner_id" FOREIGN KEY ("learner_id") REFERENCES "learners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "lesson_progress" ADD CONSTRAINT "fk_lesson_progress_enrollment_id" FOREIGN KEY ("enrollment_id") REFERENCES "enrollments" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "lesson_progress" ADD CONSTRAINT "fk_lesson_progress_lesson_id" FOREIGN KEY ("lesson_id") REFERENCES "lessons" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More Education templates
- School managementStudents and guardians, classes taught by teachers, grades and attendance.
- University registrarDepartments, courses offered as sections each term, instructors and registrations.
- Quizzes & assessmentsQuizzes of multiple-choice questions, attempts and recorded answers.
- LibraryBooks with authors, physical copies, members, loans and holds.
- Tutoring marketplaceTutors teaching subjects, bookable lessons with students, and reviews.
- CertificationsCertification programmes with exams, candidate attempts and issued certificates.
- Language learningCourses by language, units of lessons and exercises, learner attempts and streaks.
- FlashcardsDecks of cards with spaced-repetition review history per learner.
- Nursery / childcareChildren in rooms with key staff, guardians, daily attendance and incident reports.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.