Templates/Education

Flashcards database schema

Decks of cards with spaced-repetition review history per learner.

5 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

users

  • iduuid not null
  • emailtext not null
  • created_attimestamptz not null

decks

  • iduuid not null
  • owner_id> usersuuid not null
  • nametext not null
  • publicboolean not null
  • created_attimestamptz not null

flashcards

  • iduuid not null
  • deck_id> decksuuid not null
  • fronttext not null
  • backtext not null
  • created_attimestamptz not null

card_states

  • iduuid not null
  • card_id> flashcardsuuid not null
  • user_id> usersuuid not null
  • easenumeric(4,2) not null
  • interval_daysinteger not null
  • due_ondate not null
  • created_attimestamptz not null

card_reviews

  • iduuid not null
  • card_id> flashcardsuuid not null
  • user_id> usersuuid not null
  • gradeinteger 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 "card_reviews" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "card_id" UUID NOT NULL,
  "user_id" UUID NOT NULL,
  "grade" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "card_states" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "card_id" UUID NOT NULL,
  "user_id" UUID NOT NULL,
  "ease" NUMERIC(4,2) DEFAULT 2.5 NOT NULL,
  "interval_days" INTEGER DEFAULT 0 NOT NULL,
  "due_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "decks" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "owner_id" UUID NOT NULL,
  "name" TEXT NOT NULL,
  "public" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "flashcards" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "deck_id" UUID NOT NULL,
  "front" TEXT NOT NULL,
  "back" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "users" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "decks" ADD CONSTRAINT "fk_decks_owner_id" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "flashcards" ADD CONSTRAINT "fk_flashcards_deck_id" FOREIGN KEY ("deck_id") REFERENCES "decks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "card_states" ADD CONSTRAINT "fk_card_states_card_id" FOREIGN KEY ("card_id") REFERENCES "flashcards" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "card_states" ADD CONSTRAINT "fk_card_states_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "card_reviews" ADD CONSTRAINT "fk_card_reviews_card_id" FOREIGN KEY ("card_id") REFERENCES "flashcards" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "card_reviews" ADD CONSTRAINT "fk_card_reviews_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

More Education templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.