CONFOR uses PostgreSQL 15+ with PostGIS extensions for geospatial data processing. This guide covers database setup using Docker Compose or manual installation.
# Apply all pending migrationsnpm run db:migrate# This will:# - Create database tables# - Install PostGIS and other extensions# - Set up partitioning for audit_logs# - Create indexes and constraints
The first migration installs required PostgreSQL extensions:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- UUID generationCREATE EXTENSION IF NOT EXISTS "postgis"; -- Spatial data supportCREATE EXTENSION IF NOT EXISTS "pg_trgm"; -- Trigram text searchCREATE EXTENSION IF NOT EXISTS "btree_gist"; -- Indexing support
-- Full vacuum (reclaim storage)VACUUM FULL;-- Update statistics for query plannerANALYZE;-- Both operationsVACUUM FULL ANALYZE;-- Auto-vacuum specific tableVACUUM ANALYZE audit_logs;
Symptoms:ECONNREFUSED or Connection refusedSolutions:
# Check if PostgreSQL is runningdocker compose ps postgres# or for manual installationsudo systemctl status postgresql# Check port is listeningnetstat -an | grep 5432# orss -tulpn | grep 5432# Restart servicedocker compose restart postgres# orsudo systemctl restart postgresql
PostGIS extension not found
Symptoms:ERROR: extension "postgis" is not availableSolutions:
# For Docker (should be included in postgres image)docker compose exec postgres psql -U postgres -d app_dev -c "CREATE EXTENSION postgis;"# For manual installation, install PostGIS package# Ubuntu/Debian:sudo apt-get install postgresql-15-postgis-3# Then enable in database:psql -U postgres -d app_dev -c "CREATE EXTENSION postgis;"
Migration fails with permission error
Symptoms:permission denied to create extensionSolutions:
# Grant superuser to your database userpsql -U postgres -c "ALTER USER your_user WITH SUPERUSER;"# Or connect as postgres user and run migrationsDATABASE_URL="postgresql://postgres:postgres@localhost:5432/app_dev" npx prisma migrate deploy
Prisma client out of sync
Symptoms:PrismaClientInitializationError: Prisma Client could not locate the Query EngineSolutions:
# Regenerate Prisma clientnpm run db:generate# Clear node_modules and reinstallrm -rf node_modules .nextnpm installnpm run db:generate
Audit log partition missing
Symptoms:ERROR: no partition of relation "audit_logs" foundSolutions:
# Manually create partition for current monthnpx tsx scripts/create-audit-partition.ts# Or create via SQLpsql -U postgres -d app_dev <<SQLCREATE TABLE IF NOT EXISTS audit_logs_2026_03 PARTITION OF audit_logsFOR VALUES FROM ('2026-03-01') TO ('2026-04-01');SQL
CREATE INDEX CONCURRENTLY idx_level4_org ON "PatrimonyLevel4"("organizationId");CREATE INDEX CONCURRENTLY idx_level4_level3 ON "PatrimonyLevel4"("level3Id");