Skip to main content

DbMigratorOptions

Options accepted by DbMigrator.execute().

PropertyTypeRequiredDescription
connectionClientConfigurationyesConnection info for the target database. connection.dialect (required) selects the migration adapter — 'postgres', 'oracle', 'mysql', 'mariadb', 'mssql', or 'sqlite'; for SQLite, connection.driver ('sqlite' or 'sqljs') picks between the two SQLite adapters.
migrationPackageMigrationPackage | MigrationPackageConfigyesThe migrations to apply.
infoSchemastringnoSchema the migrator's bookkeeping tables (migration_summary, migration_events) live under — or, for dialects with no real schema concept (Oracle, SQLite), a table-name prefix. Defaults to __migration.
scriptVariablesRecord<string, string>noAdditional $(name) substitution variables for .task.sql scripts, merged with the adapter's own dialect-specific defaults (schema, tablespace, owner) and connection.schema.
targetVersionnumbernoMigrate up to (and including) this version. Defaults to the package's highest version.
transaction'run' | 'migration' | 'none'noHow the run is wrapped in transactions: one for the whole run, one per migration, or none (the default). Only the PostgreSQL, sqlite and sqljs adapters support 'run'/'migration'; the others throw a TypeError. Since v6.3.0.
dryRunbooleannoRuns every pending migration in one transaction, emits the same events, then rolls back instead of committing. Implies transaction: 'run'; any other transaction mode is refused. Since v6.3.0.

ClientConfiguration is defined by @sqb/connect — see its interface reference.

import type { DbMigratorOptions } from '@sqb/migrator';

const options: DbMigratorOptions = {
connection: { dialect: 'postgres', database: 'my_database' },
migrationPackage: { name: 'my-app', migrations: ['migrations/**/*'] },
targetVersion: 14,
};

MigrationTransactionMode ('run' | 'migration' | 'none') is exported as a type for the transaction option. See Running Migrations for usage, and Transactional runs and dry runs for the semantics.