Overview
Sistema Financiero uses Supabase as its backend database and authentication provider. Supabase is an open-source Firebase alternative built on PostgreSQL.Why Supabase?
- Free tier with 500MB database storage
- Built-in authentication and Row Level Security (RLS)
- Real-time subscriptions
- RESTful API auto-generated from your schema
- No server management required
Creating a Supabase Project
Sign Up for Supabase
Go to supabase.com and create a free account:
- Click Start your project
- Sign in with GitHub, Google, or email
- Verify your email address (if using email signup)
The free tier includes 500MB database, 1GB file storage, and 2GB bandwidth - perfect for personal finance tracking.
Create New Project
From the Supabase dashboard:
- Click New Project
- Select your organization (or create one)
- Fill in project details:
- Name:
sistema-financiero(or your preferred name) - Database Password: Generate a strong password (save this securely!)
- Region: Choose closest to your users (e.g.,
us-east-1,eu-central-1) - Pricing Plan: Free (sufficient for personal use)
- Name:
- Click Create new project
Get API Credentials
Once your project is ready:Keep these values for the Environment Variables setup step.
- Go to Settings (gear icon) → API
- Copy these two values:
- Project URL (e.g.,
https://abcdefgh.supabase.co) - anon public key (starts with
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...)
- Project URL (e.g.,
The
anon key is safe to expose in your frontend code. It’s read-only and respects Row Level Security policies.Database Schema Setup
Sistema Financiero requires one table:transacciones (transactions).
Create Transactions Table
Copy and paste this SQL schema into the editor:Click Run (or press
SQL Schema
Ctrl+Enter) to execute the SQL.You should see “Success. No rows returned” - this is expected for schema creation.
Verify Table Creation
Confirm the table was created:
- Go to Table Editor in the left sidebar
- You should see the
transaccionestable listed - Click on it to view the column structure
id(uuid)fecha(timestamp)tipo(text)monto(numeric)categoria(text)concepto(text)descripcion(text)metodo_pago(text)registrado_por(text)foto_url(text)usuario_id(uuid)created_at(timestamp)
Schema Explanation
Column Definitions
| Column | Type | Constraints | Description |
|---|---|---|---|
id | UUID | PRIMARY KEY | Unique identifier (auto-generated) |
fecha | TIMESTAMP | NOT NULL | Transaction date (defaults to now) |
tipo | TEXT | CHECK, NOT NULL | Transaction type: 'ingreso' or 'gasto' |
monto | NUMERIC(10,2) | CHECK > 0, NOT NULL | Amount in currency (e.g., 1500.50) |
categoria | TEXT | NOT NULL | Category (e.g., ‘Alimentación’, ‘Salario’) |
concepto | TEXT | DEFAULT | Brief description (e.g., ‘Gasolina’) |
descripcion | TEXT | NULLABLE | Detailed notes |
metodo_pago | TEXT | CHECK | Payment method: 'Efectivo', 'Tarjeta', 'Transferencia' |
registrado_por | TEXT | NULLABLE | How it was recorded (e.g., ‘AI’, ‘Manual’) |
foto_url | TEXT | NULLABLE | URL to receipt/invoice image |
usuario_id | UUID | FOREIGN KEY | References auth.users(id) |
created_at | TIMESTAMP | DEFAULT | Record creation timestamp |
Valid Categories (Hardcoded in App)
Categories are not stored in a separate table - they’re hardcoded in the application code for simplicity.
tipo = 'gasto'):
- Alimentación (Food)
- Transporte (Transportation)
- Vivienda (Housing)
- Salud (Health)
- Entretenimiento (Entertainment)
- Educación (Education)
- Otros Gastos (Other Expenses)
tipo = 'ingreso'):
- Salario (Salary)
- Ventas (Sales)
- Servicios (Services)
- Inversiones (Investments)
- Otros Ingresos (Other Income)
Indexes
Three indexes optimize query performance:Row Level Security (RLS)
What is RLS?
Row Level Security ensures users can only access their own transactions. Even if someone gets youranon API key, they can’t read other users’ data.
RLS Policies
Four policies are created:Storage Setup (Optional)
If you want to enable receipt/invoice uploads:Create Storage Bucket
In Supabase dashboard:
- Go to Storage in the left sidebar
- Click New bucket
- Bucket name:
facturas - Public bucket: ✅ (check this box)
- Click Create bucket
Testing the Setup
Query Test Data
Retrieve the test transaction:You should see your test transaction with all fields populated.
SQL
Troubleshooting
Error: uuid_generate_v4() does not exist
Error: uuid_generate_v4() does not exist
Problem: Missing UUID extension.Solution: Enable the extension:
Error: relation 'auth.users' does not exist
Error: relation 'auth.users' does not exist
Problem: Auth schema not initialized (very rare).Solution: This should auto-exist in Supabase. Try refreshing the page or contact Supabase support.
Can't see inserted data in Table Editor
Can't see inserted data in Table Editor
Problem: Row Level Security is blocking access.Solution: Either:
- Insert with a valid
usuario_idfromauth.users - Temporarily disable RLS for testing (remember to re-enable!)
- Use the Service Role Key (found in API settings) which bypasses RLS
Slow queries after inserting 10,000+ rows
Slow queries after inserting 10,000+ rows
Problem: Missing indexes or need to vacuum.Solution:
Next Steps
Database configured! Now set up your environment variables:Environment Variables
Configure
.env.local with your Supabase credentials