This document summarizes all the schema fixes and test data creation completed on 2026-02-08.
Created comprehensive schema discovery tools to find actual column names in the database:
Scripts Created:
scripts/discover-schemas.js- Discovers all table schemasscripts/discover-exam-submissions.js- Specific exam_submissions discoveryscripts/check-users.js- User verification utilityscripts/check-schema.js- Quick schema check utility
Documentation Created:
docs/ACTUAL_SCHEMA.md- Complete reference of verified column names
File: app/dashboard/student/courses/page.tsx
Changes Made:
- Line 45: Removed
image_urlcolumn (doesn't exist), keptthumbnail_url - Line 73: Changed
student_idto use correct field for exam submissions - Line 73: Changed
submitted_attosubmission_date - Lines 77-83: Removed
exam_scoresquery (score is directly in exam_submissions) - Lines 116-124: Simplified exam data structure (removed nested exam_scores)
Key Schema Corrections:
exam_submissionsusesstudent_id(NOTuser_id)exam_submissionsusessubmission_date(NOTsubmitted_at)- Score is directly in
exam_submissions.score(no separate exam_scores table) lesson_completionsusesuser_id(correct)
File: scripts/seed-complete-test-data.js
What It Does:
- Creates a product for Course 1 (JavaScript) - Lifetime Access
- Creates a plan and links it to Course 3 (Inglés)
- Creates a transaction (required for subscriptions)
- Creates an active subscription for the student
- Creates 2 enrollments:
- Course 1: Product-based (lifetime access via one-time purchase)
- Course 3: Subscription-based (active monthly subscription)
- Adds 3 lesson completions:
- Lessons 1 & 2 in Course 1 (2/3 complete = 66.67%)
- Lesson 8 in Course 3 (1/24 complete = 4.17%)
- Adds 1 exam submission:
- Course 1, Exam 1: 60% score (not passing)
Run It:
node scripts/seed-complete-test-data.jsStudent User: student@test.com (password: password123) User ID: 712c392f-689d-4075-9e5e-8008a9e1a999
Created Data:
- ✅ 2 Enrollments (Course 1 & Course 3)
- ✅ 1 Product linked to Course 1
- ✅ 1 Plan linked to Course 3
- ✅ 1 Active Subscription
- ✅ 1 Transaction (for subscription)
- ✅ 3 Lesson Completions
- ✅ 1 Exam Submission (60% score)
Expected Behavior on My Courses Page:
-
Course 1 (JavaScript):
- Badge: "Lifetime Access"
- Progress: ~33% ((66.67% lessons + 0% exams) / 2)
- Status: In Progress
- Button: "Continue Learning"
-
Course 3 (Inglés):
- Badge: "Subscription"
- Progress: ~2% ((4.17% lessons + 0% exams) / 2)
- Status: In Progress
- Button: "Continue Learning"
Files Modified/Created:
docs/ACTUAL_SCHEMA.md- NEW: Verified column names referencedocs/DATABASE_SCHEMA.md- UPDATED: Added warning banner pointing to ACTUAL_SCHEMA.md
Key Schema Differences Documented:
| Documented | Actual | Table |
|---|---|---|
| id | enrollment_id | enrollments |
| enrolled_at | enrollment_date | enrollments |
| id | product_id | products |
| id | plan_id | plans |
| id | exam_id | exams |
| id | course_id | courses |
| user_id | student_id | exam_submissions |
| submitted_at | submission_date | exam_submissions |
The dev server may need restarting to pick up changes:
# In your terminal where npm run dev is running:
# Press Ctrl+C to stop
npm run dev- Navigate to http://localhost:3000/auth/login
- Login with: student@test.com / password123
- Go to http://localhost:3000/dashboard/student/courses
- Expected Results:
- See 2 courses (JavaScript & Inglés)
- JavaScript shows 66% lesson progress, 1 exam attempt
- Inglés shows 4% lesson progress, 0 exams
- Progress bars and badges display correctly
- "Continue Learning" buttons work
- Try searching for "JavaScript" or "Inglés"
- Try status filters (In Progress, Completed, Not Started)
- Try sorting (Recent, Title, Progress)
- Click "Continue Learning" on JavaScript course
- Should take you to Lesson 3 (next incomplete lesson)
- Click "Continue Learning" on Inglés course
- Should take you to Lesson 2 (next incomplete lesson)
scripts/discover-schemas.jsscripts/discover-exam-submissions.jsscripts/check-users.jsscripts/check-schema.jsscripts/seed-complete-test-data.js⭐ MAIN SCRIPTscripts/seed-test-enrollments.js(older version)scripts/seed-test-enrollments.sql(SQL version)
app/dashboard/student/courses/page.tsx- Fixed schema queriesdocs/DATABASE_SCHEMA.md- Added warning bannerdocs/ACTUAL_SCHEMA.md- NEW: Verified schema reference
-
Verify data exists:
node -e "const { createClient } = require('@supabase/supabase-js'); require('dotenv').config({ path: '.env.local' }); const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY); (async () => { const {data} = await supabase.from('enrollments').select('*').eq('user_id', '712c392f-689d-4075-9e5e-8008a9e1a999'); console.log('Enrollments:', data); })()" -
Check browser console for errors (F12)
-
Re-run seed script:
node scripts/seed-complete-test-data.js
- Files exist:
components/student/enrolled-course-card.tsxandcourse-filters.tsx - Restart dev server
- Clear
.nextcache:rm -rf .nextthennpm run dev
- Check
docs/ACTUAL_SCHEMA.mdfor correct column names - All queries now use verified column names
All requested tasks completed:
- ✅ My Courses query fixed with correct schema
- ✅ Lesson completions added with correct schema
- ✅ Exam submissions added with correct schema
- ✅ Subscription & plan created for Course 3
- ✅ Schema documentation updated
Test data is ready! Just restart the dev server and test the My Courses page.
Key Achievement: Discovered and documented the actual database schema, fixing all mismatches between documentation and reality.