Generate
migrate generate diffs your code-defined tables against the live database and
writes a SQL migration file. It does not apply it.
Syntax
Section titled “Syntax”mountsqli migrate generateThe CLI auto-detects mountsqli.config.* from the current directory.
What it does
Section titled “What it does”- Reads your tables from the config.
- Introspects the live database (or an empty schema on first run).
- Diffs the two and generates
CREATE/ALTER/DROPstatements. - Writes a timestamped migration file to your migrations directory.
Example output
Section titled “Example output”$ mountsqli migrate generateCreated migration: migrations/2026-07-16T12-00-00_add_posts.sql-- migrations/2026-07-16T12-00-00_add_posts.sqlCREATE TABLE "posts" ( "id" INTEGER PRIMARY KEY, "title" TEXT NOT NULL, "body" TEXT);Options
Section titled “Options”| Flag | Effect |
|---|---|
--name <n> |
set a custom migration name |
--dir <path> |
override the migrations directory |
Run it with your package manager:
npx mountsqli migrate generatepnpm mountsqli migrate generatebunx mountsqli migrate generateBest practices
Section titled “Best practices”- Generate after every schema change, before committing.
- Review the SQL — destructive
DROP/ALTERis shown explicitly. - Keep one logical change per migration for easy rollback reasoning.
Common mistakes
Section titled “Common mistakes”- Generating against
:memory:— nothing persists, so diffs are always full creates. - Forgetting to commit the generated file.
Related
Section titled “Related”- Apply — run the generated migration.
- How Migrations Work — the diff model.
