Skip to content

Configuration

dbsh uses a two-tier configuration: a global migration.json file and per-environment overrides.

Global config

Database/Config/migration.json:

json
{
  "migration": {
    "version": "1.0.0",
    "database": {
      "provider": "postgresql",
      "connectionString": "${DB_CONNECTION_STRING}"
    },
    "scripts": {
      "path": "./Database/Migrations",
      "pattern": "*.sql"
    },
    "tracking": {
      "schema": "public",
      "tableName": "__migration_history"
    },
    "execution": {
      "lockTimeoutSeconds": 300,
      "commandTimeoutSeconds": 3600,
      "batchSize": 10,
      "stopOnFailure": true
    },
    "approval": {
      "requireApproval": ["staging", "production"]
    }
  }
}

Options reference

OptionDefaultDescription
version1.0.0Configuration schema version
database.providerDatabase engine: postgresql, sqlserver, mysql, or sqlite
database.connectionStringConnection string (supports ${VAR} expansion)
scripts.path./Database/MigrationsRelative path to migration scripts
scripts.pattern*.sqlFile glob for migration scripts
tracking.schemapublicDatabase schema for tracking tables
tracking.tableName__migration_historyBase name for tracking tables
execution.lockTimeoutSeconds300Distributed lock timeout
execution.commandTimeoutSeconds3600Per-SQL-command timeout
execution.batchSize10Migrations per batch
execution.stopOnFailuretrueHalt on first failure
approval.requireApproval[]Environments requiring approval

Per-environment files

Database/Config/environments/<name>.json:

json
{
  "name": "production",
  "database": {
    "connectionString": "${PROD_DB_CONNECTION_STRING}"
  },
  "migration": {
    "requireApproval": true,
    "allowRollback": true,
    "lockTimeoutSeconds": 300,
    "maxBatchSize": 5
  },
  "deploymentWindow": {
    "enabled": true,
    "startTime": "02:00",
    "endTime": "06:00",
    "allowedDays": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
  }
}

Environment options

OptionDescription
nameEnvironment name (must match the filename)
database.connectionStringOverride connection string for this environment
database.host, port, name, schemaIndividual connection components
migration.requireApprovalRequire an approver identity to deploy
migration.allowRollbackAllow rollback operations
migration.lockTimeoutSecondsOverride lock timeout
migration.maxBatchSizeMaximum migrations per batch
deploymentWindow.enabledEnable time-based deployment gating
deploymentWindow.startTimeWindow opens at (HH:mm, local time)
deploymentWindow.endTimeWindow closes at (HH:mm, local time)
deploymentWindow.allowedDaysDays of week when deploys are allowed

Environment variable expansion

All ${VAR} tokens in configuration files are expanded from environment variables at load time. This means secrets never need to be committed to source control.

json
{
  "database": {
    "connectionString": "${DB_CONNECTION_STRING}"
  }
}
bash
export DB_CONNECTION_STRING="Host=localhost;Database=myapp;Username=postgres"
dbsh migrate

Connection string resolution order

When dbsh migrate runs, the connection string is resolved in this order:

  1. --connection-string CLI flag (highest priority)
  2. DB_CONNECTION_STRING environment variable
  3. environments/<name>.json -> database.connectionString
  4. migration.json -> database.connectionString (lowest priority)

Each step is skipped if the value is not set or empty. The first non-empty value wins.

Validating your config

bash
dbsh info

Shows your current configuration, resolved provider, available environments, and file paths.

Released under the MIT License.