Skip to content

Apply

migrate apply runs pending migrations and records each in _mount_migrations. It runs inside a transaction per step.

Terminal window
mountsqli migrate apply
  1. Loads the on-disk migrations (the known set).
  2. Diffs them against _mount_migrations to find pending steps.
  3. Applies each pending step in a transaction.
  4. Records the step on success.
$ mountsqli migrate apply
Applying 2026-07-16T12-00-00_add_posts.sql ... done
Applied 1 migration.
Flag Effect
--dir <path> override the migrations directory
--dry-run print SQL without executing

You can drive the Migrator directly:

import { Migrator } from "@mountsqli/migration";
const migrator = new Migrator(driver, migrationsDir);
const { pending } = await migrator.status(knownSteps);
for (const step of pending) {
await migrator.apply(step);
}
  • Run apply in CI or a deploy hook, not from a request path.
  • Use --dry-run to preview in production-like environments.
  • Keep a backup before applying destructive alters.
  • Applying against :memory:_mount_migrations vanishes on exit.
  • Expecting status to show pending without passing known steps (it won’t).
  • Status — see what is pending.
  • Generate — create the migration first.