Skip to main content
Budgetron uses PostgreSQL as its database with Drizzle ORM for type-safe database access and migrations.

Database Connection

string
required
PostgreSQL connection string for database access.Format: postgresql://[user]:[password]@[host]:[port]/[database]Example: postgresql://postgres:password@localhost:5432/budgetronProduction Example: postgresql://user:pass@db.example.com:5432/production_db?sslmode=require

Connection String Format

The connection string follows the standard PostgreSQL URI format:

Components

Common Parameters

SSL Configuration

SSL is disabled by default in Drizzle configuration for local development. For production, enable SSL in your connection string:
Always use SSL (sslmode=require) for production databases to encrypt data in transit.

Drizzle Configuration

The database configuration is defined in drizzle.config.ts:

Configuration Options

Database Schema

The database schema is defined in TypeScript at src/server/db/schema.ts and includes:

Core Tables

  • user - User accounts and profiles
  • account - OAuth provider connections
  • session - Active user sessions
  • verification - Email verification tokens

Application Tables

  • budget - Budget definitions and periods
  • transaction - Financial transactions
  • category - Transaction categories
  • currency - Supported currencies and exchange rates
  • And more…

Migration Tracking

  • __drizzle_migrations - Drizzle migration history
All table names use snake_case naming convention as configured in Drizzle.

Migrations

Running Migrations

Migrations are automatically applied during Docker startup. For local development:

Migration Files

Migration files are stored in drizzle/migrations/ and include:
  • SQL migration files (.sql)
  • Metadata files (.json)
Never manually edit migration files. Always use pnpm run db:generate to create migrations from schema changes.

Docker Startup Process

When using Docker, the application:
  1. ✅ Waits for PostgreSQL to be ready
  2. ✅ Runs pending Drizzle migrations
  3. ✅ Starts the Next.js server
This is handled by the Docker entrypoint script.

Local Development Setup

Using Docker Compose

The quickest way to get started is using Docker Compose with PostgreSQL:
Then set your connection string:

Using Managed PostgreSQL

Budgetron works with any managed PostgreSQL service:

Vercel Postgres

Serverless PostgreSQL by Vercel

Supabase

Open-source Firebase alternative

Neon

Serverless Postgres with branching

Railway

PostgreSQL on Railway

Connection Pooling

For production deployments, consider using connection pooling:

PgBouncer

Many managed PostgreSQL services (Vercel, Supabase, Neon) provide built-in connection pooling. If not, use PgBouncer:

Drizzle Pooling

Drizzle uses the underlying PostgreSQL driver’s connection pooling by default.

Database Requirements

PostgreSQL Version

  • Minimum: PostgreSQL 12
  • Recommended: PostgreSQL 14+
  • Tested: PostgreSQL 16

Required Extensions

No PostgreSQL extensions are required. Budgetron uses standard PostgreSQL features.

Storage Requirements

Storage needs depend on usage:
  • Base schema: ~5 MB
  • Per user: ~100 KB
  • Per transaction: ~1 KB

Troubleshooting

Connection Refused

Solutions:
  • Verify PostgreSQL is running: pg_isready
  • Check the host and port in DB_URL
  • Ensure firewall allows connections on port 5432

Authentication Failed

Solutions:
  • Verify username and password in DB_URL
  • Check PostgreSQL pg_hba.conf for authentication rules
  • Try connecting with psql to test credentials

SSL Connection Error

Solutions:
  • Add ?sslmode=require to your DB_URL
  • For self-signed certificates, use ?sslmode=require&sslcert=/path/to/cert

Database Does Not Exist

Solutions:
  • Create the database: createdb budgetron
  • Or via SQL: CREATE DATABASE budgetron;

Security Best Practices

Follow these security guidelines for production deployments:
  1. Use strong passwords - Generate secure passwords for database users
  2. Enable SSL - Always use sslmode=require in production
  3. Restrict access - Limit database access to application servers only
  4. Regular backups - Implement automated backup strategy
  5. Separate environments - Use different databases for dev/staging/production
  6. Rotate credentials - Periodically rotate database passwords

Generating Secure Passwords

Performance Optimization

Indexes

Drizzle migrations automatically create indexes defined in the schema. Common indexes include:
  • Primary keys on all tables
  • Foreign key indexes for relationships
  • User lookup indexes

Connection Settings

For high-traffic applications, tune connection pool settings: