This guide will help you set up Supabase as the database backend for the Aushadham Medical Healthcare Platform.
Supabase provides a modern, scalable PostgreSQL database with:
- Real-time capabilities
- Built-in authentication
- Row Level Security (RLS)
- Automatic API generation
- Easy scaling and backups
- Free tier available
- A Supabase account (sign up at https://supabase.com)
- Python 3.8 or higher
- The Aushadham application code
- Go to https://supabase.com and sign in
- Click "New Project"
- Enter a project name (e.g., "aushadham")
- Set a secure database password (save this!)
- Choose a region close to your users
- Click "Create new project"
- Wait for the project to be ready (1-2 minutes)
- In your Supabase project dashboard, click on "SQL Editor" in the left sidebar
- Click "New Query"
- Copy the entire contents of
supabase_schema.sqlfrom this repository - Paste it into the SQL editor
- Click "Run" to execute the SQL script
This will create three tables:
users- User accounts and authenticationsaved_questionnaires- Saved medical questionnairesuser_feedback- User feedback on questionnaires
The script also sets up:
- Indexes for better query performance
- Row Level Security policies
- Foreign key relationships
- In your Supabase project dashboard, click on "Settings" (gear icon)
- Go to "API" section
- You'll need two keys:
- Project URL: Found under "Project URL" (e.g.,
https://xxxxx.supabase.co) - Anon/Public Key: Found under "Project API keys" → "anon public"
- Project URL: Found under "Project URL" (e.g.,
-
Copy the
.env.examplefile to create a.envfile:cp .env.example .env
-
Edit the
.envfile and add your Supabase credentials:# Enable Supabase USE_SUPABASE=true # Supabase Configuration SUPABASE_URL=https://your-project.supabase.co SUPABASE_KEY=your-anon-key-here # Flask Configuration (keep your existing values or generate new ones) SECRET_KEY=your-secret-key-here JWT_SECRET_KEY=your-jwt-secret-key-here
-
Important: Never commit your
.envfile to version control! It contains sensitive credentials.
Install the required Python packages:
pip install -r requirements.txtThis will install:
supabase- Supabase Python clientpostgrest- PostgreSQL REST client- All other existing dependencies
Start the Flask application:
python app.pyYou should see a message indicating:
Using Supabase for database operations
If you see this message, congratulations! Your application is now using Supabase.
Run the test suite to verify everything is working:
python test_api.pyOr test manually using curl:
# Register a new user
curl -X POST http://localhost:5000/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "testpass123",
"full_name": "Test User"
}'The application supports both SQLAlchemy (local SQLite/PostgreSQL) and Supabase. To switch:
Set in .env:
USE_SUPABASE=true
SUPABASE_URL=your-url
SUPABASE_KEY=your-keySet in .env:
USE_SUPABASE=false
DATABASE_URL=sqlite:///aushadham.dbOr remove/comment out the USE_SUPABASE variable entirely.
- Go to your Supabase project dashboard
- Click "Table Editor" to view and manage your data
- You can see all users, questionnaires, and feedback
- Click "Database" → "Query Performance"
- Monitor slow queries and optimize as needed
Supabase automatically backs up your database. You can also:
- Go to "Database" → "Backups"
- Create manual backups anytime
- Download backups for local storage
- Never expose your service_role key - Only use the anon/public key in your application
- Use environment variables - Never hardcode credentials
- Enable RLS policies - Already set up in the schema
- Rotate keys regularly - Generate new API keys periodically
- Monitor usage - Check the Supabase dashboard for unusual activity
- Verify your
SUPABASE_URLandSUPABASE_KEYare correct - Check that your Supabase project is running
- Ensure you have internet connectivity
- Check the Flask application logs for detailed error messages
- Verify the database schema was created correctly
- Check Supabase logs in the dashboard under "Logs" → "Postgres Logs"
- Ensure JWT secrets are set correctly in
.env - Verify users are being created in the Supabase dashboard
If Supabase initialization fails, the application will automatically fall back to SQLAlchemy. Check the logs:
Supabase configuration found but initialization failed. Falling back to SQLAlchemy.
If you have existing data in SQLite or another database:
- Export your existing data to JSON or CSV
- Use Supabase's data import feature:
- Go to "Table Editor"
- Select a table
- Click "Insert" → "Import data from CSV"
- Or write a migration script using both database connections
For issues specific to:
- Aushadham application: Open an issue in this repository
- Supabase platform: Visit Supabase Support
- Python client: Check supabase-py GitHub
Supabase offers a free tier that includes:
- 500 MB database space
- 1 GB file storage
- 2 GB bandwidth
- 50,000 monthly active users
For production use with higher traffic, consider upgrading to a paid plan. See Supabase Pricing for details.