Database & Services
The backend runs without any backing service by default: persistence is disabled in
the default settings preset (app.disable_persistence = true in
src/settings/defaults.ts), NATS is replaced with a dummy implementation, and the
Keyv cache falls back to in-memory storage. Enable each service only when the feature
you work on needs it.
Start everything with Docker Compose
docker-compose.yml defines the three backing services:
| Service | Image | Ports |
|---|---|---|
postgres | postgres:16-alpine | ${DB_PORT:-5432}:5432 |
redis | redis:8-alpine | 6379 |
nats | nats:2-alpine (JetStream via -js) | 4222, 6222, 8222 |
docker-compose up -d
# or scoped to one instance's env file (custom project name + DB_PORT):
docker-compose --env-file .env.<instance> up -dEnable persistence
-
Set
app.disable_persistence = falsein the settings preset you run with. -
Add DB settings to
.env:DB_HOST=localhost DB_USER=postgres DB_PASSWORD=postgrespw DB_NAME=repliers_portal DB_PORT=5432 -
Run migrations:
npm run db:migrate
Features that need persistence: user roles/ACL, uploaded assets, virtual tours,
social-account links, people sync, webhooks. The flag does not turn them into no-ops:
APP_DISABLE_PERSISTENCE only skips the ACL lookup at token generation and the release
migration, and every other repository call fails at run time without a database — see
Running without a database.
Migrations
Migrations live in src/migrations/ and run through knex
(src/knexfile.ts simply re-exports config.db, so migrations use the same
env-driven connection as the app):
npm run knex migrate:make <name> # create
npm run db:migrate # apply latest (dev)
npm run db:migrate:test # apply to the test database (port 5555)In production the release process of the Procfile runs db:migrate:prod, which
compiles pending migrations if needed and applies them against dist/. It skips
silently when the environment variable APP_DISABLE_PERSISTENCE=true and fails on any
value other than true, false or unset — see Deployment.
Managed Postgres services that require TLS need DB_USE_SSL=true.
Test database
Tests load test.env (npm run test sets DOT_ENV_CONFIG=test.env). The local
convention keeps the test Postgres on port 5555 so it never collides with the dev
database — test:local and db:migrate:test both pin DB_PORT=5555:
npm run db:migrate:test
npm run test:local