Skip to content

Generate

migrate generate diffs your code-defined tables against the live database and writes a SQL migration file. It does not apply it.

Terminal window
mountsqli migrate generate

The CLI auto-detects mountsqli.config.* from the current directory.

  1. Reads your tables from the config.
  2. Introspects the live database (or an empty schema on first run).
  3. Diffs the two and generates CREATE / ALTER / DROP statements.
  4. Writes a timestamped migration file to your migrations directory.
$ mountsqli migrate generate
Created migration: migrations/2026-07-16T12-00-00_add_posts.sql
-- migrations/2026-07-16T12-00-00_add_posts.sql
CREATE TABLE "posts" (
"id" INTEGER PRIMARY KEY,
"title" TEXT NOT NULL,
"body" TEXT
);
Flag Effect
--name <n> set a custom migration name
--dir <path> override the migrations directory

Run it with your package manager:

Terminal window
npx mountsqli migrate generate
  • Generate after every schema change, before committing.
  • Review the SQL — destructive DROP/ALTER is shown explicitly.
  • Keep one logical change per migration for easy rollback reasoning.
  • Generating against :memory: — nothing persists, so diffs are always full creates.
  • Forgetting to commit the generated file.