Overview
Quality Hub GINEZ uses Supabase as its Backend-as-a-Service (BaaS) provider, leveraging:- PostgreSQL 15 for data storage
- Row Level Security (RLS) for access control
- Supabase Auth for user authentication
- Realtime subscriptions for live updates
Prerequisites
Create Supabase Account
Sign up at supabase.com if you haven’t already.
Create New Project
- Click “New Project” from your Supabase dashboard
- Enter project name:
quality-hub-ginez - Set a strong database password (save this securely)
- Choose a region close to your users
- Wait for project to initialize (~2 minutes)
Get API Credentials
Navigate to Settings → API and note:
- Project URL
anonpublic keyservice_rolekey (keep secure)
.env.local file (see Environment Variables).Database Schema
1. Production Log Table
The main table for storing production batch records and quality measurements.The table stores both quality measurements (pH, solids) and organoleptic properties (appearance, color, aroma) for comprehensive quality control.
2. User Profiles Table
Extends Supabase Auth with additional user metadata and role management.Profiles are automatically created when users sign up. The trigger ensures every authenticated user has a corresponding profile entry.
Row Level Security (RLS) Policies
RLS ensures users can only access data they’re authorized to see.Policies for bitacora_produccion
Policies for profiles
Complete Setup Script
Run this complete SQL script in the Supabase SQL Editor:Authentication Configuration
1. Enable Email Authentication
Configure Email Provider
- Enable “Email” provider
- Set “Confirm email” to ON (recommended for production)
- Configure email templates if needed
2. Create First Admin User
After setup, manually promote your first user to admin:Verification
Verify your setup is working correctly:Check Tables
In Supabase Dashboard → Table Editor, confirm:
- ✅
bitacora_producciontable exists - ✅
profilestable exists
Troubleshooting
Error: relation does not exist
Error: relation does not exist
Cause: Table not created or wrong schemaSolution: Verify tables exist in
public schema:Error: permission denied for table
Error: permission denied for table
Cause: RLS blocking accessSolution:
- Verify RLS policies are created:
SELECT * FROM pg_policies; - Check user is authenticated:
SELECT auth.uid(); - For admins, verify
is_administruein profiles table
Profile not auto-created on signup
Profile not auto-created on signup
Cause: Trigger not workingSolution:
- Verify trigger exists:
SELECT * FROM pg_trigger WHERE tgname = 'on_auth_user_created'; - Manually create profile for existing users:
Can't delete own profile
Can't delete own profile
Expected behavior: Self-deletion is prevented by policyThis safety measure prevents admins from accidentally locking themselves out.
Backup and Maintenance
Automatic Backups
Supabase Pro plans include automatic daily backups. Free tier allows manual backups via dashboard.
Manual Backup
Monitoring
Monitor database performance in Supabase Dashboard → Database → Query Performance
Index Optimization
Review slow queries and add indexes as needed:
Next Steps
Environment Variables
Configure Supabase credentials in your application
Multi-Location Setup
Learn about the 40+ branch locations in the system
