Database Operations
Connection Information
| Field | Default |
|---|---|
| Host | localhost |
| Port | 5432 |
| Database | hereby_platform |
| User | hereby_admin |
| DBMS | PostgreSQL 16 (TimescaleDB + pgvector) |
pgAdmin Access
- Navigate to
http://localhost:5050 - Login:
admin@hereby.platform/admin123 - When adding a server, use
postgres(Docker network name) as host
Migrations
Check Migration Status
bash
pnpm --filter @hereby/database typeorm migration:show -d src/config/data-source.tsExecuted migrations show [X], pending show [ ].
Run Migrations
bash
make db-migrateRevert Migration
bash
pnpm --filter @hereby/database typeorm migration:revert -d src/config/data-source.tsWARNING
Revert only rolls back the most recent migration. Repeat to revert multiple.
Generate New Migration
From entity changes:
bash
pnpm --filter @hereby/database typeorm migration:generate \
-- src/migrations/DescriptiveName \
-d src/config/data-source.tsEmpty migration:
bash
pnpm --filter @hereby/database typeorm migration:create \
-- src/migrations/DescriptiveNameBackup & Recovery
Full Database Backup
bash
docker exec hereby_postgres pg_dump \
-U hereby_admin \
-d hereby_platform \
-F c \
-f /tmp/backup_$(date +%Y%m%d_%H%M%S).dump
# Copy to host
docker cp hereby_postgres:/tmp/backup_*.dump ./backups/Data-Only Backup
bash
docker exec hereby_postgres pg_dump \
-U hereby_admin \
-d hereby_platform \
--data-only \
-F c \
-f /tmp/data_backup.dumpRestore
bash
docker exec -i hereby_postgres pg_restore \
-U hereby_admin \
-d hereby_platform \
-c \
/tmp/backup.dumpDANGER
The -c flag drops existing data. Always backup current data first.
Automated Backup Schedule (crontab)
bash
# Daily backup at 2 AM
0 2 * * * docker exec hereby_postgres pg_dump -U hereby_admin -d hereby_platform -F c -f /backups/daily_$(date +\%Y\%m\%d).dumpPostgreSQL Shell
bash
make db-shellUseful Queries
sql
-- List tables
\dt
-- Table sizes
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname || '.' || tablename))
FROM pg_tables WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname || '.' || tablename) DESC;
-- Active connections
SELECT count(*) FROM pg_stat_activity WHERE state = 'active';
-- Slow queries (>1s)
SELECT pid, now() - query_start AS duration, query
FROM pg_stat_activity
WHERE state != 'idle'
AND now() - query_start > interval '1 seconds'
ORDER BY duration DESC;Seed Data
bash
make db-seedTest accounts after seeding:
| Role | Password | |
|---|---|---|
| Admin | admin@hereby.com | admin123 |
| Developer | dev.lee@hereby.com | dev123 |
| HR Manager | hr.kim@hereby.com | hr123 |
| Sales | sales.park@hereby.com | sales123 |