Spaces:
Sleeping
Sleeping
Setting Up Persistent Database for AI Learning Path Generator
This guide explains how to set up a free PostgreSQL database so users can:
- Login from any device
- Sync their learning paths across devices
- Keep their progress saved permanently
Quick Setup (5 minutes)
Step 1: Create a Free Neon Database
- Go to Neon and sign up (free)
- Create a new project (e.g., "ai-learning-paths")
- Copy the connection string (looks like:
postgresql://user:pass@host/db?sslmode=require)
Step 2: Add to HuggingFace Spaces Secrets
- Go to your HuggingFace Space settings
- Click on "Settings" → "Repository secrets"
- Add a new secret:
- Name:
DATABASE_URL - Value: Your Neon connection string
- Name:
Step 3: Restart Your Space
The app will automatically create all needed tables on startup.
Free Database Options
| Provider | Free Tier | Best For |
|---|---|---|
| Neon | 0.5GB, auto-suspend | Recommended - fastest |
| Supabase | 500MB, 50K requests | Good alternative |
| CockroachDB | 5GB | Distributed |
Local Development
For local testing, you can either:
- Use SQLite (default): Just leave
DATABASE_URLempty - Use PostgreSQL: Set
DATABASE_URLin your.envfile
Verify Setup
After deployment, check the logs for:
DATABASE_URL is configured (using PostgreSQL for persistent storage)
✅ Database initialized
Mobile App Configuration
The mobile app automatically syncs with the backend when users are logged in. Data is stored:
- Logged-in users: Server database (synced across devices)
- Guest users: Local device storage only
Troubleshooting
"Connection refused" errors
- Check if the connection string is correct
- Ensure
?sslmode=requireis at the end for Neon
"Table doesn't exist" errors
- The app auto-creates tables on startup
- Restart the Space to re-run initialization
Data not syncing
- Ensure user is logged in (not guest mode)
- Check network connectivity to the API