Migrations
KalamDB projects store schema history under kalam/migrations/ (configured in [migrations].dir). The CLI diffs schema.sql against a local baseline, maintains a working _draft.sql, and tracks applied migrations on the server per namespace.
Migration files
| File pattern | Meaning |
|---|---|
YYYYMMDDHHMMSS_<name>.sql | Committed, ordered migration with -- UP and -- DOWN sections |
_draft.sql | Working draft generated from schema changes not yet sealed |
Draft files are not applied to production deployments until sealed into a numbered migration.
Typical development flow
During kalam dev, edits to schema.sql update _draft.sql automatically. Numbered migrations apply on startup and after each watched change; the draft waits for your confirmation unless you use kalam dev --force (which skips the prompt but still leaves sealing/applying the draft to the Apply path or explicit kalam migration seal).
Commands
kalam migration create <name>
Create a numbered migration immediately from the current diff (without going through the draft file):
kalam migration status
Report migration state for the resolved environment:
Groups: Applied, Pending, Failed, Applying.
kalam migration seal
Promote _draft.sql into the next numbered migration file (rename only — does not apply to the database):
Run kalam db migrate afterward to apply the sealed migration.
kalam db migrate
Apply all pending numbered migrations to the linked database:
- Does not include
_draft.sqlunless you sealed it first - Ensures the target namespace exists before applying
- Validates checksums for migrations already marked applied
kalam migration retry <id>
Re-queue a failed migration for another apply attempt:
kalam migration repair <id> --mark-applied
Manually mark a migration as applied on the server (use when you’ve fixed state out of band):
How drafting works
- Baseline —
kalam/.schema-baseline.sqlmirrors the last successfully applied schema - Diff — the CLI compares
schema.sqlto the baseline and generates UP/DOWN SQL - Draft — changes land in
kalam/migrations/_draft.sql - Seal —
kalam migration sealrenames the draft totimestamp_name.sql - Apply —
kalam db migrateor the dev pipeline executes UP statements and records checksums on the server - Baseline update — after apply, baseline is refreshed from
schema.sql
If the diff is empty, a stale _draft.sql is removed automatically.
Dev vs deploy behavior
| Context | Draft auto-apply | Auto-create drafts |
|---|---|---|
kalam dev | Prompted (or --force) | Yes, when migrations.auto_create = true |
kalam db migrate | No — numbered files only | No |
kalam deploy | Refused — blocks if uncommitted schema would require new migrations | No |
Production deploy applies committed migration history only. Generate and seal migrations locally before kalam deploy --env prod.
Stuck or failed migrations
During apply, the CLI may prompt when a migration was interrupted or failed previously:
- Retry — attempt apply again
- Skip / mark applied — for failed migrations when you’ve verified state manually
- Abort — stop the apply run
Pass --force on kalam dev to retry automatically in some stuck states.
For manual recovery:
Global flags
All migration commands accept:
| Flag | Description |
|---|---|
--project-dir <PATH> | Project root with kalam.toml |
--env <NAME> | Target environment |
Migration file format
Related
- Local Development — watch loop and draft prompts
- Project Init —
kalam.tomland migrations directory - SQL reference