StudySet Table
Container for collections of study materials.Schema Definition
Primary key - auto-generated UUID
Foreign key to
user.id (cascade delete)Study set title or topic
Study set creation timestamp
Relationships
- Belongs to
user(cascade delete when user is removed) - Has many
studySetItemrecords (cascade delete)
StudySetItem Table
Individual study items (flashcards or questions) within a study set.Schema Definition
Primary key - auto-generated UUID
Foreign key to
studySet.id (cascade delete)Relationships
- Belongs to
studySet(cascade delete when study set is removed)
Relationships Overview
Cascade Deletion
The schema uses cascade deletion to maintain referential integrity:-
When a
useris deleted:- All associated
studySetrecords are deleted - All associated
studySetItemrecords are deleted (via studySet cascade)
- All associated
-
When a
studySetis deleted:- All associated
studySetItemrecords are deleted
- All associated
Usage Examples
Creating a Study Set
Adding Flashcard Items
Querying a Study Set with Items
Type Definitions
AI Integration
Study sets are typically created via thecreateStudySet AI tool, which:
- Generates flashcards from source material (lectures, notes, readings)
- Creates the study set with appropriate title
- Populates items with term/definition or question/answer pairs
- Returns the complete study set for review
Database Configuration
Source:apps/web/src/db/schema/study.ts
All foreign keys use { onDelete: "cascade" } to automatically remove dependent records:
- Study sets are deleted when the owning user is deleted
- Study items are deleted when the parent study set is deleted