Language learning database schema
Courses by language, units of lessons and exercises, learner attempts and streaks.
7 tables, 7 relationships
Opens as a new diagram you can change. Free.
Tables
languages
- iduuid not null
- codetext not null
- nametext not null
- created_attimestamptz not null
units
- iduuid not null
- language_id> languagesuuid not null
- titletext not null
- positioninteger not null
- created_attimestamptz not null
lessons
- iduuid not null
- unit_id> unitsuuid not null
- titletext not null
- positioninteger not null
- created_attimestamptz not null
exercises
- iduuid not null
- lesson_id> lessonsuuid not null
- kindtext not null
- prompttext not null
- answertext not null
- created_attimestamptz not null
learners
- iduuid not null
- emailtext not null
- native_language_id> languagesuuid
- created_attimestamptz not null
exercise_attempts
- iduuid not null
- learner_id> learnersuuid not null
- exercise_id> exercisesuuid not null
- correctboolean not null
- created_attimestamptz not null
learner_streaks
- iduuid not null
- learner_id> learnersuuid not null
- daysinteger not null
- last_practised_ondate 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 "exercise_attempts" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"learner_id" UUID NOT NULL,
"exercise_id" UUID NOT NULL,
"correct" BOOLEAN NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "exercises" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"lesson_id" UUID NOT NULL,
"kind" TEXT NOT NULL,
"prompt" TEXT NOT NULL,
"answer" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "languages" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"code" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "learner_streaks" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"learner_id" UUID NOT NULL UNIQUE,
"days" INTEGER DEFAULT 0 NOT NULL,
"last_practised_on" DATE NOT NULL,
"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,
"native_language_id" UUID,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "lessons" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"unit_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "units" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"language_id" UUID NOT NULL,
"title" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "units" ADD CONSTRAINT "fk_units_language_id" FOREIGN KEY ("language_id") REFERENCES "languages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "lessons" ADD CONSTRAINT "fk_lessons_unit_id" FOREIGN KEY ("unit_id") REFERENCES "units" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "exercises" ADD CONSTRAINT "fk_exercises_lesson_id" FOREIGN KEY ("lesson_id") REFERENCES "lessons" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "learners" ADD CONSTRAINT "fk_learners_native_language_id" FOREIGN KEY ("native_language_id") REFERENCES "languages" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "exercise_attempts" ADD CONSTRAINT "fk_exercise_attempts_learner_id" FOREIGN KEY ("learner_id") REFERENCES "learners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "exercise_attempts" ADD CONSTRAINT "fk_exercise_attempts_exercise_id" FOREIGN KEY ("exercise_id") REFERENCES "exercises" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "learner_streaks" ADD CONSTRAINT "fk_learner_streaks_learner_id" FOREIGN KEY ("learner_id") REFERENCES "learners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More Education templates
- Online coursesCourses of modules and lessons, enrolments, lesson progress and quizzes.
- 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.
- 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.