3.0 KiB
3.0 KiB
Supabase Database Setup
The blog editor uses Supabase PostgreSQL for storing blog posts. The auth service uses its own separate database.
Connection String Format
Your Supabase connection string should look like:
postgresql://postgres.ekqfmpvebntssdgwtioj:[YOUR-PASSWORD]@aws-1-ap-south-1.pooler.supabase.com:5432/postgres
Setup Steps
1. Get Your Supabase Connection String
- Go to your Supabase project dashboard
- Navigate to Settings → Database
- Find the Connection string section
- Copy the Connection pooling connection string (recommended)
- Replace
[YOUR-PASSWORD]with your actual database password
2. Update Backend .env
Add to blog-editor/backend/.env:
DATABASE_URL=postgresql://postgres.ekqfmpvebntssdgwtioj:your_actual_password@aws-1-ap-south-1.pooler.supabase.com:5432/postgres
3. Create Database Schema
Run the migrations to create the required tables:
cd blog-editor/backend
npm run migrate
This will create:
userstable (if not exists - though auth service has its own users table)poststable for blog posts- Required indexes
4. Verify Connection
Test the database connection:
# The backend has a test endpoint
curl http://localhost:5001/api/test-db
Database Schema
The blog editor creates these tables in Supabase:
posts table
id(UUID, Primary Key)user_id(UUID, Foreign Key - references auth service user ID)title(VARCHAR)content_json(JSONB) - TipTap editor contentslug(VARCHAR, Unique)status(VARCHAR: 'draft' or 'published')created_at(TIMESTAMP)updated_at(TIMESTAMP)
Indexes
idx_posts_user_id- For fast user queriesidx_posts_slug- For fast slug lookupsidx_posts_status- For filtering by status
Important Notes
-
Separate Databases:
- Blog editor uses Supabase PostgreSQL
- Auth service uses its own separate database
- User IDs from auth service are stored as
user_idin posts table
-
Connection Pooling:
- Supabase connection string uses their pooler
- This is more efficient for serverless/server applications
- SSL is automatically handled
-
User IDs:
- The
user_idin posts table references the user ID from your auth service - Make sure the auth service user IDs are UUIDs (which they should be)
- The
-
Database Name:
- Default Supabase database is
postgres - You can create a separate database if needed, just update the connection string
- Default Supabase database is
Troubleshooting
Connection Issues
- Verify your password is correct
- Check that your IP is allowed in Supabase (Settings → Database → Connection Pooling)
- Ensure you're using the connection pooling URL (not direct connection)
Migration Issues
- Make sure you have proper permissions on the database
- Check that the database exists
- Verify the connection string format is correct
SSL Issues
- Supabase requires SSL connections
- The code automatically sets
rejectUnauthorized: falsefor Supabase - This is safe because Supabase uses valid SSL certificates