Database Overview
The PDF Form Parser uses PostgreSQL 9.3+ as its database system with multiple databases for different purposes:- Primary database - Main application data
- Cache database - Solid Cache for Rails caching
- Queue database - Solid Queue for background jobs
- Cable database - Solid Cable for Action Cable
PostgreSQL Installation
Ubuntu/Debian
macOS
Database Configuration
The database configuration is located inconfig/database.yml:
Development Environment
- Database name:
form_processor_development - Connection: Unix domain socket (localhost)
- Pool size: 5 connections (configurable via
RAILS_MAX_THREADS)
Test Environment
Production Environment
Production uses multiple databases with theDATABASE_URL environment variable:
Database Setup
Creating Databases
For development and test environments:form_processor_developmentform_processor_test
Running Migrations
Apply all pending migrations:Rails 8 uses separate migration paths for Solid Cache, Queue, and Cable. These are automatically managed when you run
db:migrate.Database Schema
The application includes these primary tables:- users - User accounts (Devise authentication)
- roles - User role assignments
- customers - Customer information
- properties - Property records
- inspections - Inspection data
- form_templates - PDF form templates
- form_fills - Completed form data with JSONB storage
- deficiencies - Inspection deficiencies
- active_storage_blobs - File storage metadata
- active_storage_attachments - File attachments
- active_storage_variant_records - Image variants
Checking Migration Status
PostgreSQL Extensions
The application requires theplpgsql extension, which is enabled by default:
Environment-Specific Configuration
Local Development with Custom Settings
If you need custom database settings in development, uncomment and modify these inconfig/database.yml:
Production with DATABASE_URL
The recommended approach for production is using theDATABASE_URL environment variable:
database.yml are merged on top of DATABASE_URL values.
Docker Build Environment
The application includes a specialbuild environment for Docker image creation:
bin/rails assets:precompile in the Dockerfile.
Connection Pooling
The application uses connection pooling to manage database connections efficiently:- Default pool size: 5 connections
- Configurable via:
RAILS_MAX_THREADSenvironment variable - Production recommendation: Set to match your Puma worker threads
If you’re using Puma with 5 threads and 2 workers, you need 10 database connections (5 threads × 2 workers).
Common Database Tasks
Reset Database
Drop, recreate, and migrate the database:Seed Database
Load seed data:Drop Database
Rollback Migration
Rollback the last migration:View Schema
The current database schema is indb/schema.rb. This file is auto-generated and should be committed to version control.
JSONB Data Storage
Theform_fills table uses PostgreSQL’s JSONB type for flexible data storage:
Multiple Database Configuration (Rails 8)
Rails 8’s Solid libraries use multiple databases:- db/migrate/ - Primary database migrations
- db/cache_migrate/ - Solid Cache migrations
- db/queue_migrate/ - Solid Queue migrations
- db/cable_migrate/ - Solid Cable migrations
Backup and Restore
Backup Database
Restore Database
Troubleshooting
Connection Refused
If you see “connection refused” errors:-
Check PostgreSQL is running:
-
Start PostgreSQL:
Permission Denied
Create the PostgreSQL user with database creation privileges:Database Does Not Exist
Simply run:Migration Pending Error
Run pending migrations:Production Considerations
Database Sizing
- Monitor connection pool usage
- Adjust
RAILS_MAX_THREADSbased on load - Use connection pooling at the database level (pgBouncer)
Performance
- Enable query logging in development:
config.active_record.verbose_query_logs = true - Use database indexes appropriately
- Monitor slow queries
- Regular VACUUM and ANALYZE operations
Security
- Use SSL connections in production
- Restrict database access to application servers only
- Use strong passwords
- Regular security updates
- Never expose
DATABASE_URLin logs or error messages
Next Steps
- Configure Active Storage for file uploads
- Set up authentication with Devise
- Learn about creating templates and PDF processing