Apply
migrate apply runs pending migrations and records each in _mount_migrations.
It runs inside a transaction per step.
Syntax
Section titled “Syntax”mountsqli migrate applyWhat it does
Section titled “What it does”- Loads the on-disk migrations (the known set).
- Diffs them against
_mount_migrationsto find pending steps. - Applies each pending step in a transaction.
- Records the step on success.
Example output
Section titled “Example output”$ mountsqli migrate applyApplying 2026-07-16T12-00-00_add_posts.sql ... doneApplied 1 migration.Options
Section titled “Options”| Flag | Effect |
|---|---|
--dir <path> |
override the migrations directory |
--dry-run |
print SQL without executing |
In code
Section titled “In code”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);}Best practices
Section titled “Best practices”- Run
applyin CI or a deploy hook, not from a request path. - Use
--dry-runto preview in production-like environments. - Keep a backup before applying destructive alters.
Common mistakes
Section titled “Common mistakes”- Applying against
:memory:—_mount_migrationsvanishes on exit. - Expecting
statusto show pending without passing known steps (it won’t).
