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. Type:DatabaseConfig (Knex.Config with connection narrowed to a PostgreSQL Knex.PgConnectionConfig object)
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.
Default Query Timeout
Outside the test environment, theDB.getDB("w") and DB.getDB("r") pools apply a default statement_timeout of 15 seconds, and PostgreSQL cancels longer queries with error 57014. Connections that name a preset directly (such as DB.getDB("production")), migrations, and workflows do not get this default.
connection.options or connection.statement_timeout already sets a value. The pgnative driver does not receive connection.statement_timeout, so prefer options as shown above. To extend the limit for one query, run SET LOCAL statement_timeout = '30s' inside a transaction.
Dotenv Loading
Before importingsonamu.config.ts, Sonamu applies dotenv sources for the current environment:
.env.env.${NODE_ENV}.env.local- Exported process environment variables
NODE_ENV values are test, development, staging, and production. For how Sonamu
chooses the environment when NODE_ENV is missing, see .env Setup.
Database Variables
- Use
SONAMU_DB_NAMEwhen present. - Otherwise generate
${projectName}_${environment}. - Use
${projectName}_fixturefor 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
UseSONAMU_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 theSONAMU_DB_FIXTURE_* prefix.
.env.test
SONAMU_DB_* values from the test environment.
Removed Fields
These fields are no longer supported:.env, .env.development, .env.staging, .env.production, and
.env.test using SONAMU_DB_*, SONAMU_DB_READONLY_*, and SONAMU_DB_FIXTURE_*.