Prerequisites
- A Supabase account (free tier available)
- The
supabase/schema.sqlfile from the project
Creating a Supabase Project
Sign up for Supabase
Go to supabase.com and create a free account
Create new project
- Click “New Project”
- Choose your organization
- Enter a project name (e.g., “estudio-three”)
- Set a strong database password (save this securely)
- Select a region close to your users
- Click “Create new project”
Running the Database Schema
Theschema.sql file creates all necessary tables, enums, policies, and triggers.
Execute the schema
Click Run or press
Ctrl/Cmd + EnterThe schema includes safety checks for existing objects. It’s safe to run multiple times.
Database Structure
The schema creates a comprehensive academic optimization system:Core Tables
| Table | Purpose |
|---|---|
profiles | User profiles and settings |
subjects | Academic subjects with difficulty ratings |
tasks | To-do items with Pomodoro tracking |
subtasks | Checklist items within tasks |
events | Calendar events (exams, matches, appointments) |
weekly_schedule | Recurring weekly commitments |
grades | Academic grades and scores |
goals | Long-term objectives |
focus_sessions | Pomodoro timer sessions |
routines | Daily routine plans |
routine_blocks | Time blocks within routines |
daily_feedback | Daily reflection and metrics |
chat_history | AI coach conversation history |
habits | Habit tracking |
habit_logs | Daily habit completion logs |
achievements | Gamification achievements |
user_achievements | Unlocked achievements per user |
translations | Dynamic i18n translations |
Enums (Type Safety)
The schema defines several enum types for data integrity:Row Level Security (RLS)
All tables have Row Level Security enabled to protect user data.Example Policy (Tasks Table)
auth.uid() = user_id.
Authentication Setup
Configure email authentication
Email authentication is enabled by default. You can customize:
- Email templates
- Confirmation requirements
- Password policies
Enable OAuth providers (optional)
Go to Authentication → Providers:For Google OAuth:
- Enable Google provider
- Add your Google OAuth credentials
- Set authorized redirect URLs to your
VITE_APP_URL
The schema includes a trigger that automatically creates a profile with default subjects when a user signs up
Automatic User Initialization
When a new user signs up, thehandle_new_user() trigger automatically:
- Creates a profile with user metadata
- Adds default subjects:
- Matemáticas (Difficulty: 4)
- Lengua y Literatura (Difficulty: 3)
- Historia (Difficulty: 3)
- Inglés (Difficulty: 3)
- Ciencias / Física (Difficulty: 5)
- Creates an initial goal: “Completar mi primera semana de rutina”
Getting API Credentials
Seeding Achievement Data
The schema includes anachievements table for gamification. You may want to seed it with initial achievements:
Database Functions (RPCs)
The schema includes several PostgreSQL functions:increment_task_pomodoros()
pomodoros_completed counter without race conditions.
get_weekly_summary()
- Total focus minutes
- Session count
- Tasks completed
- Top subject by time spent
Monitoring and Logs
Troubleshooting
”violación de clave foránea” (Foreign Key Violation)
Problem: Trying to create tasks before profile exists Solution: Ensure the user completes onboarding. Check if profile exists:“Type event_type does not exist”
Problem: Schema not fully executed Solution: Re-run the entireschema.sql file in SQL Editor
”RLS policy prevents access”
Problem: Accessing data without authentication Solution: Ensure user is logged in andauth.uid() returns a valid UUID
Schema updates not applying
Problem: Cached schema or migration conflicts Solution:Backup and Recovery
Performance Optimization
The schema includes indexes on frequently queried columns:Next Steps
After setting up Supabase:- Configure environment variables
- Deploy to Vercel or Docker
- Test authentication and data access
Keep your database password and service_role key in a secure password manager