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 db reset
Clear local dev project state and, when appropriate, drop the linked namespace on the server so the next kalam dev can re-apply migrations cleanly.
Options
--project-dir <PATH>--env <ENV>--yes— drop the namespace on a remote or non-project server without prompting (required in non-interactive shells when the server is not this project’skalam/server)
Removes locally (when present):
kalam/server/— entire local server directory (data, logs, andserver.toml)kalam/.schema-baseline.sql— schema diff baseline
Keeps:
kalam/migrations/— migration SQL files on disk
Server namespace drop (when the linked KalamDB server is reachable):
| Server | Namespace drop |
|---|---|
This project’s kalam/server on localhost (directory existed before reset) | Automatic — runs DROP NAMESPACE ... CASCADE |
Another KalamDB process on localhost (for example kalam dev reusing :2900 with no local kalam/server) | Prompts for confirmation (default No) |
| Remote URL (non-loopback) | Prompts for confirmation (default No) |
Dropping the namespace removes tables and server-side migration records for that namespace (including failed or stuck migrations in system.migrations).
If you decline the prompt, or run in a non-interactive shell without --yes, local files are still cleared but the server namespace is left unchanged. You may see migration failed previously on the next kalam dev until you run kalam db reset --yes or drop the namespace manually.
Stop kalam dev before reset when wiping kalam/server/ so RocksDB files are not locked.
After reset, run kalam dev again. Pending numbered migrations re-apply on startup.
The CLI prints each removed path, reports when nothing was present, and shows whether the namespace was dropped or skipped.
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 production 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 |
Note:
kalam deployis not supported yet. For production, seal migrations locally, runkalam db migrate --env prod, and use your own rollout process.
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