Prerequisites
- A Supabase account (free tier works fine)
- Basic understanding of PostgreSQL
Setup Process
Create a Supabase Project
- Log in to your Supabase Dashboard
- Click New Project
- Fill in the project details:
- Name:
procurement-calendar(or your preferred name) - Database Password: Generate a strong password and save it securely
- Region: Choose the region closest to your users
- Name:
- Click Create new project
Project creation takes 1-2 minutes. Wait for it to complete before proceeding.
Run the Database Schema
- In your Supabase dashboard, navigate to SQL Editor from the left sidebar
- Click New Query
- Copy the entire contents of
supabase/schema.sqlfrom your project repository - Paste it into the SQL Editor
- Click Run to execute the script
The schema creates all necessary tables, including:
- Catalog tables (proveedores, productos, presentaciones, destinos, estatus, unidades)
- Core tables (profiles, requisiciones)
- Audit tables (requisiciones_historial)
Configure Authentication Settings
Navigate to Authentication → Providers in your Supabase dashboard.Email Configuration:
- Ensure Email provider is enabled (it’s on by default)
- Configure email templates under Email Templates:
- Customize confirmation email
- Customize password reset email
- Under Auth Settings:
- Set Site URL to your production domain (e.g.,
https://procurement.clorodehidalgo.com) - Add redirect URLs for local development:
http://localhost:3000/**
- Set Site URL to your production domain (e.g.,
Verify Row Level Security
The schema automatically enables Row Level Security (RLS) on all tables. Verify the policies:
- Go to Authentication → Policies
- Confirm policies are active for:
profiles- Users can view their own profile; admins can view allrequisiciones- All authenticated users can view; admin and coordinadora can create/update- Catalog tables - All authenticated users can read; only admins can modify
- admin: Full access to all tables and user management
- coordinadora: Can create and edit requisiciones
- consulta: Read-only access
Get Your API Keys
- Navigate to Project Settings (gear icon in sidebar)
- Go to API section
- Copy the following values:
- Project URL: Your
NEXT_PUBLIC_SUPABASE_URL - anon/public key: Your
NEXT_PUBLIC_SUPABASE_ANON_KEY - service_role key: Your
SUPABASE_SERVICE_ROLE_KEY(for admin operations)
- Project URL: Your
Verify Your Setup
After completing the setup, verify everything is working:- Check Tables: Go to Table Editor and confirm all tables are created
-
Check Seed Data: Verify the following tables have initial data:
estatus(6 status types)unidades(8 unit types)destinos(7 sample destinations)presentaciones(8 presentation types)proveedores(5 sample suppliers)productos(8 sample products)
- Test Authentication: Try creating a test user through the Auth interface
Database Indexes
The schema includes performance-optimized indexes:Automatic Triggers
The schema includes several triggers that run automatically:- Auto-create profile: When a user signs up, a profile is automatically created in the
profilestable - Auto-update timestamp: The
updated_atfield is automatically updated on requisiciones changes
Next Steps
Environment Variables
Configure your application’s environment variables
Schema Reference
Learn about the database schema in detail
