Skip to content

Search the guides, deployment pages, and API reference.

generateD1Migrations

import { generateD1Migrations } from "@pitlane/data-table-d1/migrations";
function generateD1Migrations(options): Promise<GeneratedD1Migration[]>;

Writes one <id>_<name>.sql per migration into options.to, then deletes generated files with no migration behind them, so the output directory is a pure function of the input one.

The SQL is copied verbatim. Splitting it into statements is the job of whatever executes the file, and a splitter naive enough to write here would corrupt any migration containing a semicolon inside a string literal or a begin ... end trigger body.

Parameters

options

GenerateD1MigrationsOptions

Where to read migrations from, and where to write SQL to.

Returns

Promise<GeneratedD1Migration[]>

The generated files, ordered by migration id.

Throws

If options.from holds no migrations, or one of them has an empty up. Both mean the output directory is about to be wrong, and a migration runner is the worst place to discover that.

Example

import { generateD1Migrations } from "@pitlane/data-table-d1/migrations";
await generateD1Migrations({ to: "db/d1-migrations" });

See

Cloudflare D1 guide: Migrations