Skip to Content
Zenlev
Reference

Configuration

Choose project paths, environment routing, stores, and connection ownership.

Configuration precedence runs from CLI or API overrides, through dedicated configuration, through the zenlev package.json key, to defaults.

Supported dedicated files are zenlev.config.ts, zenlev.config.js, and zenlev.config.json. Discovery checks them in that order. Use --config <path> to choose a dedicated file.

Environment-aware client factory

import { defineConfig } from '@mwillbanks/zenstack-zenlev'
import { createClientForEnvironment } from './db'

export default defineConfig({
  createClient: async ({ name, cwd }) => {
    const client = await createClientForEnvironment(name, cwd)
    return {
      client,
      dispose: () => client.$disconnect(),
    }
  },
  migrationsDir: 'migrations',
  hashing: { algorithm: 'sha256', normalizeLineEndings: true },
})

The factory receives the effective environment and working directory. Select them with --env and --cwd. Your factory maps the environment name to the intended connection and credentials.

Choose one connection source per configuration. A supplied client is borrowed. A createClient factory returns an owned client and an explicit disposer. A generic adapter supplies the Kysely execution boundary.

Zenlev passes environment selection to your code without changing process globals. See Namespaces and environments for how routing relates to migration selection.

Settings

SettingDefault or purpose
cwdEffective project working directory
envNODE_ENV, or development when unset
migrationsDirmigrations, relative to effective cwd
schemaExplicit ZModel path, relative to effective cwd
namespacesOptional namespace descriptions
hashing.algorithmsha256
hashing.normalizeLineEndingstrue, normalizes CRLF to LF
diff.excludeViewstrue
pluginsPlugins in registration order
lintRecommended database lint rules and project overrides
onWarningStructured warning callback
telemetry.opentelemetry.enabledfalse

Namespace descriptions provide configuration metadata. Select migration namespaces explicitly when invoking apply, status, or tree.

SHA-512, SHA-1, and MD5 are also supported hash algorithms. Keep hash settings stable across environments that share migration files.

Lint configuration

Set lint.presets, rules, source, sql, overrides, plugins, and exceptions for database and application query policy. The default preset is recommended. Set zmodel: false for SQL-only projects and migrations: false to exclude migration source. Set dialect when SQL files need an explicit parser dialect.

Set lint.source to explicit TypeScript and JavaScript globs relative to the effective cwd, such as ['src/**/*.{ts,tsx,js,jsx}']. Its default is an empty list. Discovered migrations are exempt from application query rules, even when lint.migrations: false. Source scanning does not import application modules or acquire a connection. It runs only in offline lint, not live audits or write-plan enforcement.

Rule settings merge by ID across configuration layers. Arrays replace lower-layer arrays. Matching overrides apply in declaration order. Lint plugin specifiers resolve relative to their declaring configuration.

The offline lint command skips clientModule loading and connection acquisition. TypeScript config modules still execute when imported. Live audits use the selected environment connection. Register lintPlugin() in the existing migration plugins array for write enforcement.

See Database linting for examples and Lint rules for accepted options.

JSON configuration

Reference a project module when JSON cannot hold the client factory.

{
  "migrationsDir": "migrations",
  "clientModule": "./zenlev-client.ts"
}

Export the factory from the referenced module as its default export. Module references resolve relative to the declaring configuration file. Migration paths resolve relative to the effective project working directory.

A clientModule in the zenlev package.json key resolves relative to that manifest.

Store location

DialectDefault
PostgreSQLzenlev schema
MySQLzenlev database
SQLitezenlev_ tables

The connection must have permission to create and access the chosen store. A permission failure stops execution.

export default defineConfig({
  client: db,
  store: {
    location: 'table',
    tableName: 'application_migrations',
    lockTableName: 'application_migration_lock',
  },
})

The example assumes the defineConfig and db imports from your configuration. Table storage works across supported dialects.

Use schemaName with PostgreSQL schema storage or databaseName with MySQL database storage. SQLite uses table storage. Unsupported location combinations fail validation.

Keep each environment's store configuration stable after its first run. A different ledger presents a different history, even when the configured connection reaches the same database.

See the Dialect examples for connection permissions, PostgreSQL search paths, and DDL behavior.

On this page