Skip to main content
Sonamu builds database presets from NODE_ENV, projectName, and SONAMU_DB_* environment variables. The old database.name and database.environments fields are no longer supported.

Basic Structure

database

Specifies the PostgreSQL driver. Type: "pg" | "pgnative" (optional) Default: "pg"
  • "pg": Pure JavaScript PostgreSQL driver. Recommended for most projects.
  • "pgnative": Native driver using C bindings. Use only when you need it and can support the platform requirements.

defaultOptions

Knex options shared by every generated preset.
Sonamu fills connection fields from SONAMU_DB_*. Use defaultOptions.connection only for connection options shared by every environment, such as SSL settings. Sonamu keeps host, port, user, password, and database values scoped to the environment that loaded them.

Dotenv Loading

Before importing sonamu.config.ts, Sonamu applies dotenv sources for the current environment:
  1. .env
  2. .env.${NODE_ENV}
  3. .env.local
  4. Exported process environment variables
Allowed NODE_ENV values are test, development, staging, and production. If NODE_ENV is missing, Sonamu uses development.

Database Variables

Database name resolution:
  1. Use SONAMU_DB_NAME when present.
  2. Otherwise generate ${projectName}_${environment}.
  3. Use ${projectName}_fixture for the fixture database.

Presets

Sonamu generates these presets: DB.getDB("w") resolves to the current environment’s main preset. DB.getDB("r") resolves to the current environment’s read-only preset.

Read-Only Replicas

Use SONAMU_DB_READONLY_* variables for read-only replicas. Any missing read-only field uses the current environment’s main connection value.
.env.production

Fixture DB

Fixture DB settings use the SONAMU_DB_FIXTURE_* prefix.
.env.test
If fixture-specific host, port, user, or password values are missing, Sonamu uses the regular SONAMU_DB_* values from the test environment.

Removed Fields

These fields are no longer supported:
Move those values into .env, .env.development, .env.staging, .env.production, and .env.test using SONAMU_DB_*, SONAMU_DB_READONLY_*, and SONAMU_DB_FIXTURE_*.