Database Connection
PostgreSQL connection string for database access.Format:
postgresql://[user]:[password]@[host]:[port]/[database]Example: postgresql://postgres:password@localhost:5432/budgetronProduction Example: postgresql://user:[email protected]:5432/production_db?sslmode=requireConnection String Format
The connection string follows the standard PostgreSQL URI format:Components
| Component | Description | Required | Example |
|---|---|---|---|
username | Database user | ✅ Yes | postgres, admin, budgetron_user |
password | User password | ✅ Yes | mySecurePassword123 |
host | Database server hostname or IP | ✅ Yes | localhost, db.example.com, 192.168.1.10 |
port | Database server port | No (default: 5432) | 5432, 5433 |
database | Database name | ✅ Yes | budgetron, production_db |
parameters | Additional connection options | No | sslmode=require |
Common Parameters
| Parameter | Description | Example |
|---|---|---|
sslmode | SSL connection mode | require, disable, prefer |
connect_timeout | Connection timeout in seconds | 10 |
application_name | Application identifier | budgetron |
SSL Configuration
SSL is disabled by default in Drizzle configuration for local development. For production, enable SSL in your connection string:Drizzle Configuration
The database configuration is defined indrizzle.config.ts:
Configuration Options
| Option | Value | Description |
|---|---|---|
dialect | postgresql | Database dialect |
out | ./drizzle/migrations | Migration files directory |
schema | ./src/server/db/schema.ts | Database schema definition |
casing | snake_case | Database column naming convention |
strict | true | Strict type checking |
migrations.schema | public | PostgreSQL schema for tables |
migrations.table | __drizzle_migrations | Migration tracking table |
Database Schema
The database schema is defined in TypeScript atsrc/server/db/schema.ts and includes:
Core Tables
user- User accounts and profilesaccount- OAuth provider connectionssession- Active user sessionsverification- Email verification tokens
Application Tables
budget- Budget definitions and periodstransaction- Financial transactionscategory- Transaction categoriescurrency- 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 indrizzle/migrations/ and include:
- SQL migration files (
.sql) - Metadata files (
.json)
Docker Startup Process
When using Docker, the application:- ✅ Waits for PostgreSQL to be ready
- ✅ Runs pending Drizzle migrations
- ✅ Starts the Next.js server
Local Development Setup
Using Docker Compose
The quickest way to get started is using Docker Compose with PostgreSQL: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
- Verify PostgreSQL is running:
pg_isready - Check the host and port in
DB_URL - Ensure firewall allows connections on port 5432
Authentication Failed
- Verify username and password in
DB_URL - Check PostgreSQL
pg_hba.conffor authentication rules - Try connecting with
psqlto test credentials
SSL Connection Error
- Add
?sslmode=requireto yourDB_URL - For self-signed certificates, use
?sslmode=require&sslcert=/path/to/cert
Database Does Not Exist
- Create the database:
createdb budgetron - Or via SQL:
CREATE DATABASE budgetron;
Security Best Practices
Follow these security guidelines for production deployments:
- Use strong passwords - Generate secure passwords for database users
- Enable SSL - Always use
sslmode=requirein production - Restrict access - Limit database access to application servers only
- Regular backups - Implement automated backup strategy
- Separate environments - Use different databases for dev/staging/production
- 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:Related Configuration
- Environment Variables - Complete environment reference
- Deployment Guide - Production deployment setup