Skip to main content

CustomMigrationTask

A migration task that runs an arbitrary function instead of a SQL script or row insert — for anything a .task.sql/.task.json file can't express.

PropertyTypeRequiredDescription
fn(connection: any, adapter: MigrationAdapter) => void | Promise<void>yesFunction invoked with the active database connection and the current MigrationAdapter.
titlestringnoHuman-readable title. Defaults to "Run custom function" when loaded from a manifest file.
filenamestringnoSource file this task was loaded from, if any.
import type { CustomMigrationTask } from '@sqb/migrator';

const task: CustomMigrationTask = {
title: 'Backfill full-text search index',
fn: async connection => {
await connection.execute('REINDEX INDEX customers_search_idx');
},
};

See Writing Migration Tasks for how a .task.ts/.task.js file resolves to this shape.