Overview
CompanyFlow uses PostgreSQL 14 or higher as its primary database. The application uses thepgx/v5 driver for database connectivity and includes a custom SQL-based migration runner.
Prerequisites
Before setting up the database, ensure you have:- PostgreSQL 14 or higher installed
- Database user with appropriate privileges
- Network access to the PostgreSQL server
Installation
Create Database
Create a new database for CompanyFlow:
For production environments, use a strong password and limit privileges to only what’s necessary.
Enable Required Extensions
CompanyFlow requires the
pgcrypto extension for UUID generation:This extension is automatically enabled when you run migrations, but you can enable it manually if needed.
Database Configuration
Connection String Format
CompanyFlow uses the following connection string format:SSL Mode Options
Controls SSL/TLS encryption for the database connection:
disable- No SSL (development only)require- SSL required, no certificate verificationverify-ca- SSL required, verify CA certificateverify-full- SSL required, verify CA and hostname
Connection Pooling
CompanyFlow usespgxpool for connection pooling. The default pool settings are managed by the pgx library, which typically creates:
- Maximum connections: Based on system resources
- Minimum connections: 0 (connections created on demand)
- Connection lifetime: Automatic cleanup of idle connections
Custom Pool Configuration
To customize connection pool settings, you can modify the connection string inconfig/config.go:27:
Schema Overview
The CompanyFlow database includes the following main tables:- companies - Multi-tenant company records
- tenants - Subscription and plan information
- employees - Employee records with authentication
- departments - Organizational departments
- designations - Job titles and positions
- levels - Employee hierarchy levels
- roles - RBAC roles
- permissions - Role-based permissions
- leaves - Leave request records
- memos - Internal communications
- approvals - Approval workflow records
- audit_logs - System activity tracking
- schema_migrations - Migration tracking table
Testing Database Setup
Create Test Database
For running tests, create a separate test database:Configure Test Environment
Set test database variables in your environment or.env file:
Troubleshooting
Connection Refused
If you see “connection refused” errors:-
Check if PostgreSQL is running:
-
Verify PostgreSQL is listening on the correct port:
Authentication Failed
If authentication fails:- Check
pg_hba.confconfiguration file - Ensure password authentication is enabled for your connection type
- Verify username and password are correct