Skip to content

Latest commit

 

History

History
151 lines (109 loc) · 3.88 KB

File metadata and controls

151 lines (109 loc) · 3.88 KB

Database Setup Guide

This guide will help you set up your Neon database for the Malify email client.

1. Create a Neon Database

  1. Go to Neon Console
  2. Sign up or log in to your account
  3. Click "Create Project"
  4. Choose a project name (e.g., "malify")
  5. Select a region close to your users
  6. Click "Create Project"

2. Get Your Database Connection String

  1. In your Neon project dashboard, click on "Connection Details"
  2. Copy the connection string that looks like:
    postgresql://username:password@ep-xxx-xxx.region.aws.neon.tech/dbname?sslmode=require
    

3. Set Up Environment Variables

  1. Create a .env.local file in your project root:

    touch .env.local
  2. Add your environment variables to .env.local:

    # Neon Database
    DATABASE_URL="your_neon_connection_string_here"
    
    # JWT Secret for authentication (generate a random string)
    JWT_SECRET="your_super_secret_jwt_key_here_make_it_long_and_random"
    
    # Next.js
    NEXTAUTH_URL="http://localhost:3000"
    NEXTAUTH_SECRET="your_nextauth_secret_here"

    Important: Replace the placeholder values with your actual values:

    • DATABASE_URL: Your Neon connection string
    • JWT_SECRET: A long, random string (at least 32 characters)
    • NEXTAUTH_SECRET: Another random string for NextAuth

4. Install Dependencies

npm install

5. Generate and Push Database Schema

  1. Generate the database migration:

    npm run db:generate
  2. Push the schema to your Neon database:

    npm run db:push

6. Start the Development Server

npm run dev

7. Create Your First User

  1. Open http://localhost:3000
  2. Click "create a new account"
  3. Fill in your details and register
  4. You'll be automatically logged in to your Gmail clone!

Database Schema Overview

The application uses the following main tables:

Users

  • Stores user account information
  • Handles authentication

Folders

  • System folders (Inbox, Sent, Drafts, etc.)
  • Custom user-created folders

Emails

  • All email data including content, metadata, and status
  • Supports threading, attachments, and labels

Labels

  • Custom labels for organizing emails

Attachments

  • File attachments for emails

Optional: Database Studio

To view and manage your database with a GUI:

npm run db:studio

This will open Drizzle Studio in your browser where you can:

  • View all tables and data
  • Run queries
  • Manage your database schema

Environment Variables Reference

Variable Description Example
DATABASE_URL Neon database connection string postgresql://user:pass@host/db?sslmode=require
JWT_SECRET Secret key for JWT tokens your-super-secret-key-here
NEXTAUTH_URL Your app's URL http://localhost:3000
NEXTAUTH_SECRET NextAuth secret key another-secret-key

Troubleshooting

Connection Issues

  • Ensure your DATABASE_URL is correct
  • Check that your Neon database is running
  • Verify your IP is allowed (Neon allows all IPs by default)

Migration Issues

  • Make sure you've run npm run db:generate before npm run db:push
  • Check that your DATABASE_URL environment variable is set

Authentication Issues

  • Verify JWT_SECRET is set and is a long, random string
  • Clear your browser cookies and try again

Production Deployment

For production deployment:

  1. Set up your production environment variables
  2. Use a production-ready JWT_SECRET
  3. Update NEXTAUTH_URL to your production domain
  4. Consider setting up database connection pooling for better performance

Security Notes

  • Never commit .env.local to version control
  • Use strong, unique secrets for JWT_SECRET and NEXTAUTH_SECRET
  • Regularly rotate your secrets in production
  • Consider using environment-specific databases (dev, staging, prod)