Prerequisites
Before you begin, make sure you have:- A Supabase account (free tier works perfectly)
- Basic understanding of SQL
- Your EaseLMS repository cloned locally
Create a Supabase Project
Sign up for Supabase
Go to supabase.com and sign up or log in to your account.
Create a new project
- Click “New Project”
- Choose your organization
- Enter a project name (e.g., “easelms-production”)
- Set a strong database password (save this securely)
- Select a region close to your users
- Click “Create new project”
Get Your Supabase Credentials
Copy your credentials
You’ll need three values:
- Project URL - This is your
NEXT_PUBLIC_SUPABASE_URL - anon public key - This is your
NEXT_PUBLIC_SUPABASE_ANON_KEY - service_role secret key - This is your
SUPABASE_SERVICE_ROLE_KEY
Run Database Migration
The database migration file creates all necessary tables, indexes, and security policies for EaseLMS.Copy migration script
Open the file
apps/lms/supabase/migrations/database_setup.sql from your EaseLMS repository and copy the entire contents.Verify Database Setup
After running the migration, verify that all tables were created correctly.Verify tables exist
You should see the following tables:
profiles- User profile informationcourses- Course datalessons- Individual lesson contentenrollments- Course enrollment recordsprogress- Student progress trackingpayments- Payment transactionscertificates- Generated certificatesinstructors- Instructor informationresources- Downloadable resourcesquiz_questions- Quiz questionsquiz_settings- Quiz configurationquiz_attempts- Quiz attempt trackingquiz_results- Quiz resultscourse_instructors- Course-instructor relationshipscourse_prerequisites- Course prerequisiteslesson_resources- Lesson-resource relationshipsplatform_settings- Platform-wide settings
Database Schema Overview
Core Tables
profiles
Stores user profile information, linked to Supabase Auth users.courses
Stores course information with pricing, enrollment modes, and certificate settings.lessons
Stores individual lesson content (video, text, or mixed).Security Features
The migration includes:- Row Level Security (RLS) - Enabled on all tables
- Security Policies - Restrict data access based on user roles
- Automatic Triggers - Update timestamps and create profiles automatically
- Indexes - Optimize query performance
The database uses PostgreSQL extensions
uuid-ossp for UUID generation and pgcrypto for password hashing.User Roles and Permissions
User Types
- user - Regular learner with access to enrolled courses
- admin - Full access to all platform features and data
Automatic Profile Creation
When a user signs up through Supabase Auth, a profile is automatically created via thehandle_new_user() trigger function:
Create Your First Admin User
After setting up the database, you’ll need to create an admin user.Sign up through the app
Go to your EaseLMS application at
http://localhost:3000 and sign up for a new account.Update user_type in Supabase
- Go to Table Editor in Supabase
- Open the
profilestable - Find your user record
- Change
user_typefromlearnertoadmin - Save the changes
Troubleshooting
Migration Fails with “relation already exists”
This means you’ve already run the migration. If you need to reset:- Go to SQL Editor in Supabase
- Run:
DROP SCHEMA public CASCADE; CREATE SCHEMA public; - Re-run the migration script
”permission denied for table” errors
Check that Row Level Security policies are correctly applied. The migration script includes all necessary policies.Cannot insert into profiles table
Ensure theon_auth_user_created trigger is active. Check in SQL Editor:
Next Steps
After setting up your database:- Configure your environment variables
- Set up AWS S3 for file storage
- Configure payment gateways
- Start the development server with
npm run dev