Skip to main content

Overview

Quail BI requires two database services:

MongoDB

Stores user data, connections, dashboards, and chat history

Supabase

Handles user authentication and session management

MongoDB Setup

1

Create Account

Sign up for a free account at mongodb.com/cloud/atlas
2

Create Cluster

  1. Click Create to create a new cluster
  2. Choose the Free Shared tier (M0)
  3. Select a cloud provider and region close to your users
  4. Name your cluster (e.g., quail-production)
  5. Click Create Cluster
3

Configure Network Access

  1. Navigate to Network Access in the sidebar
  2. Click Add IP Address
  3. Choose Allow Access from Anywhere (0.0.0.0/0) for development
  4. For production, whitelist specific IPs
4

Create Database User

  1. Navigate to Database Access
  2. Click Add New Database User
  3. Choose Password authentication
  4. Create a username and secure password
  5. Set Database User Privileges to Read and write to any database
  6. Click Add User
5

Get Connection String

  1. Go to Database and click Connect on your cluster
  2. Choose Connect your application
  3. Copy the connection string:
mongodb+srv://<username>:<password>@cluster.mongodb.net/<database>?retryWrites=true&w=majority
  1. Replace <username>, <password>, and <database> with your values
6

Configure Environment

Add the connection string to .env.local:
MONGODB_URI=mongodb+srv://username:[email protected]/quail?retryWrites=true&w=majority
Never commit your connection string to version control. Keep it in .env.local only.

Option 2: Local MongoDB

For development, you can run MongoDB locally:
# Install via Homebrew
brew tap mongodb/brew
brew install [email protected]

# Start MongoDB
brew services start [email protected]

# Connection string
MONGODB_URI=mongodb://localhost:27017/quail

MongoDB Database Schema

Quail automatically creates these collections:
Stores user account information (synced with Supabase).
{
  "_id": "ObjectId",
  "supabaseId": "uuid",
  "email": "[email protected]",
  "createdAt": "ISODate",
  "updatedAt": "ISODate"
}
Indexes: { supabaseId: 1 } (unique), { email: 1 }
Stores encrypted database connection strings.
{
  "_id": "ObjectId",
  "userId": "ObjectId",
  "name": "Production DB",
  "type": "postgresql",
  "encryptedConnectionString": "encrypted-data-here",
  "createdAt": "ISODate",
  "updatedAt": "ISODate",
  "lastConnected": "ISODate"
}
Indexes: { userId: 1 }, { userId: 1, name: 1 }
Stores dashboard configurations.
{
  "_id": "ObjectId",
  "userId": "ObjectId",
  "name": "Sales Dashboard",
  "layout": [],
  "filters": [],
  "createdAt": "ISODate",
  "updatedAt": "ISODate"
}
Indexes: { userId: 1 }, { userId: 1, createdAt: -1 }
Stores chart configurations.
{
  "_id": "ObjectId",
  "userId": "ObjectId",
  "dashboardId": "ObjectId",
  "connectionId": "ObjectId",
  "name": "Monthly Revenue",
  "type": "line",
  "config": {},
  "query": "SELECT ...",
  "createdAt": "ISODate",
  "updatedAt": "ISODate"
}
Indexes: { userId: 1 }, { dashboardId: 1 }
Stores chat conversation history.
{
  "_id": "ObjectId",
  "userId": "ObjectId",
  "connectionId": "ObjectId",
  "messages": [],
  "createdAt": "ISODate",
  "updatedAt": "ISODate"
}
Indexes: { userId: 1 }, { userId: 1, createdAt: -1 }

Creating Indexes

For optimal performance, create indexes manually:
// Connect to your database
use quail;

// User indexes
db.users.createIndex({ "supabaseId": 1 }, { unique: true });
db.users.createIndex({ "email": 1 });

// Connection indexes
db.connections.createIndex({ "userId": 1 });
db.connections.createIndex({ "userId": 1, "name": 1 });

// Dashboard indexes
db.dashboards.createIndex({ "userId": 1 });
db.dashboards.createIndex({ "userId": 1, "createdAt": -1 });

// Chart indexes
db.charts.createIndex({ "userId": 1 });
db.charts.createIndex({ "dashboardId": 1 });

// Chat indexes
db.chats.createIndex({ "userId": 1 });
db.chats.createIndex({ "userId": 1, "createdAt": -1 });

Supabase Setup

Create Supabase Project

1

Sign Up

Create an account at supabase.com
2

Create Project

  1. Click New Project
  2. Enter a project name (e.g., quail-production)
  3. Set a secure database password (save this!)
  4. Choose a region close to your users
  5. Click Create new project
Wait 2-3 minutes for the project to initialize.
3

Get API Keys

  1. Go to Settings → API in the sidebar
  2. Copy three values:
    • Project URL (e.g., https://abc123.supabase.co)
    • anon public key (under “Project API keys”)
    • service_role secret key (click “Reveal” to see it)
4

Configure Environment

Add these to .env.local:
.env.local
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here
The service_role key bypasses Row Level Security. Keep it secret and never expose it to the client.

Configure Authentication

1

Enable Email Authentication

  1. Go to Authentication → Providers
  2. Ensure Email is enabled
  3. Configure email templates (optional)
2

Configure Email Templates (Optional)

  1. Go to Authentication → Email Templates
  2. Customize the confirmation and password reset emails
  3. Add your branding and domain
3

Set Up Redirect URLs

  1. Go to Authentication → URL Configuration
  2. Add your site URL (e.g., https://quail.yourdomain.com)
  3. Add redirect URLs:
    • http://localhost:3000/** (for development)
    • https://yourdomain.com/** (for production)

Configure Row Level Security (Optional)

For additional security, enable Row Level Security (RLS) on Supabase tables:
Quail stores most data in MongoDB, so RLS is optional. However, if you add tables to Supabase, enable RLS.
-- Enable RLS on a table
ALTER TABLE your_table ENABLE ROW LEVEL SECURITY;

-- Allow users to read their own data
CREATE POLICY "Users can view own data"
ON your_table
FOR SELECT
USING (auth.uid() = user_id);

-- Allow users to insert their own data
CREATE POLICY "Users can insert own data"
ON your_table
FOR INSERT
WITH CHECK (auth.uid() = user_id);

Testing Authentication

Verify authentication is working:
import { createClient } from '@supabase/supabase-js';

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);

// Test sign up
const { data, error } = await supabase.auth.signUp({
  email: '[email protected]',
  password: 'securepassword123',
});

if (error) {
  console.error('Auth error:', error);
} else {
  console.log('Sign up successful:', data);
}

Production Considerations

MongoDB

Backups

Enable automated backups in MongoDB Atlas or set up regular mongodump backups

Monitoring

Use MongoDB Atlas monitoring or tools like Datadog, New Relic

Scaling

Upgrade to a larger cluster tier as usage grows

Security

Use IP whitelisting and strong passwords

Supabase

Custom Domain

Configure a custom domain for authentication emails

Rate Limiting

Monitor API usage and configure rate limits

Upgrade Plan

Free tier has limits; upgrade for production

Email Provider

Configure a custom SMTP provider for better deliverability

Troubleshooting

Check these common issues:
  1. Connection string format: Ensure no extra spaces or line breaks
  2. Network access: Verify IP is whitelisted in MongoDB Atlas
  3. Credentials: Check username and password are correct
  4. Database name: Ensure the database name exists
Test connection with MongoDB Compass:
# Download MongoDB Compass and test the connection string
Common issues:
  1. Wrong keys: Verify you’re using the correct anon and service_role keys
  2. URL mismatch: Check the project URL matches your Supabase project
  3. Email not confirmed: Check inbox for confirmation email
  4. Redirect URL: Add your site URL to allowed redirect URLs
Test in Supabase dashboard:
  1. Go to Authentication → Users
  2. Try creating a test user
Environment variables are not loaded:
  1. Verify .env.local exists in project root
  2. Restart the dev server after adding variables
  3. Check variable names match exactly (case-sensitive)

Next Steps

Environment Variables

Configure all environment variables

Configuration

Advanced configuration options

Security

Secure your databases

Troubleshooting

Fix common database issues

Build docs developers (and LLMs) love