This guide covers setting up PostgreSQL databases for RENALGUARD AI using either Neon (recommended) or Supabase, and configuring Cloudflare Hyperdrive for optimal performance.
- Prerequisites
- Option A: Neon Setup (Recommended)
- Option B: Supabase Setup
- Cloudflare Hyperdrive Configuration
- Running Database Migrations
- MCP Server Setup
- Troubleshooting
Before starting, ensure you have:
- Node.js 20+ installed
- Wrangler CLI installed (
npm install -g wrangler) - A Cloudflare account (for Hyperdrive)
- Either a Neon or Supabase account
Neon is a serverless PostgreSQL platform with excellent Cloudflare integration and a generous free tier.
- Go to neon.tech and sign up
- Verify your email address
- Click "New Project"
- Configure:
- Project name:
renalguard-production - PostgreSQL version:
16(recommended) - Region: Choose closest to your Cloudflare region (e.g.,
us-east-1)
- Project name:
- Click "Create Project"
- Go to your project dashboard
- Click "Connection Details"
- Copy the connection string (looks like):
postgresql://USER:PASSWORD@ep-xxx-xxx-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require
Using the Neon Console SQL Editor or psql:
-- Create the database (if not using default 'neondb')
CREATE DATABASE renalguard;
-- Connect to the database and verify
\c renalguard
SELECT version();- Go to Account Settings → API Keys
- Click "Create new API Key"
- Name it
renalguard-mcp - Copy and save the key securely
Alternatively, use the Neon CLI for automated setup:
# Install Neon CLI
npm install -g neonctl
# Authenticate
neonctl auth
# Create project
neonctl projects create --name renalguard-production
# Get connection string
neonctl connection-string --project-id <PROJECT_ID>Supabase provides PostgreSQL with additional features like authentication and real-time subscriptions.
- Go to supabase.com and sign up
- Verify your email address
- Click "New Project"
- Configure:
- Project name:
renalguard-production - Database password: Generate a strong password (save it!)
- Region: Choose closest to your Cloudflare region
- Pricing plan: Free tier is sufficient for development
- Project name:
- Click "Create new project"
- Wait for the project to be provisioned (2-3 minutes)
- Go to Project Settings → Database
- Under Connection string, select URI
- Copy the connection string:
postgresql://postgres.[PROJECT_REF]:[PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres
Note: Use the pooler connection string (port 6543) for better performance with Cloudflare.
- Go to supabase.com/dashboard/account/tokens
- Click "Generate new token"
- Name it
renalguard-mcp - Copy and save the token securely
Hyperdrive provides connection pooling and caching for your PostgreSQL database, significantly reducing latency from Cloudflare edge.
wrangler login# For Neon
wrangler hyperdrive create renalguard-db \
--connection-string="postgresql://USER:PASSWORD@ep-xxx.neon.tech/renalguard?sslmode=require"
# For Supabase
wrangler hyperdrive create renalguard-db \
--connection-string="postgresql://postgres.xxx:PASSWORD@aws-0-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require"The command will output a Hyperdrive ID like:
Created Hyperdrive config renalguard-db with ID abc123def456...
Save this ID - you'll need it for environment configuration.
Update your Cloudflare container configuration:
# In backend/cloudflare-container.toml or via Cloudflare dashboard
[container.env]
DATABASE_URL = "hyperdrive://abc123def456" # Your Hyperdrive ID# List your Hyperdrive configurations
wrangler hyperdrive list
# Get details of specific config
wrangler hyperdrive get renalguard-dbOnce your database is set up, run the RENALGUARD migrations.
# Set your database URL
export DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=require"
# Run migrations
cd backend
node runMigration.js# Connect and run migrations manually
psql $DATABASE_URL
# Run each migration file
\i infrastructure/postgres/migrations/001_initial_schema.sql
\i infrastructure/postgres/migrations/002_...
# ... continue for all migration files# Start only postgres locally for testing
docker-compose up postgres -d
# Run migrations
docker-compose exec backend node runMigration.js-- Check applied migrations
SELECT * FROM schema_migrations ORDER BY applied_at;
-- Verify table creation
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;The MCP servers allow AI assistants to manage your databases directly.
Edit .claude/mcp-config.json with your credentials:
{
"mcpServers": {
"neon": {
"command": "npx",
"args": ["-y", "@neondatabase/mcp-server-neon"],
"env": {
"NEON_API_KEY": "neon_api_key_here"
}
},
"supabase": {
"command": "npx",
"args": ["-y", "@supabase/mcp-server"],
"env": {
"SUPABASE_ACCESS_TOKEN": "supabase_token_here"
}
},
"cloudflare": {
"command": "npx",
"args": ["-y", "@cloudflare/mcp-server-cloudflare"],
"env": {
"CLOUDFLARE_API_TOKEN": "cloudflare_token_here",
"CLOUDFLARE_ACCOUNT_ID": "account_id_here"
}
}
}
}Once configured, you can use natural language commands:
- "Create a new Neon branch called 'feature-test'"
- "Run SELECT COUNT(*) FROM patients on the renalguard database"
- "Show me all tables in the renalguard project"
- "Create a database migration for adding a new column"
- "List all tables in my Supabase project"
- "Run a query to count patients by CKD stage"
- "Generate TypeScript types for my database schema"
- "Show me the database logs from the last hour"
- "Create a new Hyperdrive configuration"
- "List all my Hyperdrive databases"
- "Deploy my Workers application"
- "Show me the status of my Cloudflare Pages deployment"
Error: "connection refused"
- Verify your IP is allowed in database firewall rules
- Check SSL mode is set correctly (
?sslmode=require)
Error: "authentication failed"
- Double-check username and password
- Ensure URL encoding for special characters in password
Error: "relation already exists"
- Migrations may have partially run
- Check
schema_migrationstable for applied migrations - Use
--forceflag if safe to re-run
Error: "permission denied"
- Verify database user has CREATE/ALTER permissions
- For Neon: Use the default user which has full permissions
- For Supabase: Use the
postgresuser
Error: "Hyperdrive not found"
- Verify Hyperdrive ID is correct
- Ensure Hyperdrive is in the same Cloudflare account
- Check Hyperdrive status:
wrangler hyperdrive get <ID>
Slow connections
- Verify Hyperdrive region matches database region
- Check caching is enabled in Hyperdrive config
- Monitor with:
wrangler hyperdrive get <ID> --json
| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
Full PostgreSQL connection string | postgresql://user:pass@host/db |
NEON_API_KEY |
Neon API key for MCP | neon_api_xxx |
SUPABASE_ACCESS_TOKEN |
Supabase access token | sbp_xxx |
CLOUDFLARE_API_TOKEN |
Cloudflare API token | xxx |
CLOUDFLARE_ACCOUNT_ID |
Cloudflare account ID | abc123 |
HYPERDRIVE_ID |
Cloudflare Hyperdrive config ID | abc123def456 |
# Neon CLI
neonctl projects list
neonctl branches list --project-id <ID>
neonctl connection-string --project-id <ID>
# Supabase CLI
npx supabase projects list
npx supabase db dump --project-ref <REF>
# Cloudflare Wrangler
wrangler hyperdrive list
wrangler hyperdrive get <ID>
wrangler hyperdrive update <ID> --max-age 120- Neon Documentation
- Neon MCP Server
- Supabase Documentation
- Supabase MCP Server
- Cloudflare Hyperdrive
- Cloudflare MCP Servers
Last Updated: January 2026