Skip to content

CLI cheatsheet ​

Every command and flag on one page. Click a command for the details and real output.

Global flags ​

These work on every command and beat environment variables and the config file:

FlagDescription
--uri <uri>MongoDB connection URI
--db <name>Database name
--dir <path>Migrations directory
--config <path>Path to a config file (overrides auto-discovery)
--jsonOne JSON document on stdout; everything else, including your own code's console.log, goes to stderr (on every command that reads or changes migrations; on init it means "make a JSON config")

Running migrations ​

CommandDescription
mmk upRun all pending migrations
mmk up <file>Run a single migration
mmk up --stepApply each file as its own batch
mmk up <file> --force --yesRun an already-applied file again
mmk up --strictAbort on a checksum mismatch
mmk up --no-lockDon't take the lock (local development only)
mmk downRoll back the last batch
mmk down <file>Roll back a single migration
mmk down --batch <n>Roll back a specific batch
mmk down --steps <n>Roll back the last N migrations
mmk down --forceRoll back even if a file changed since it ran (asks first)
mmk redoRoll back and re-apply the most recent migration
mmk redo <file>Roll back and re-apply one file

Looking around ​

CommandDescription
mmk statusFull status table
mmk status --checkExit 1 if anything is pending (for CI)
mmk status --all-namespacesEvery repo's records on a shared database (read-only)
mmk list --pendingOnly pending migrations
mmk list --appliedOnly applied migrations
mmk dry-run upPreview what would apply
mmk dry-run downPreview what would revert
mmk dry-run down --steps <n>Preview reverting the last N
mmk lockWho holds the migration lock, and whether it has gone stale (changes nothing)
mmk configThe settings mmk resolved, and where each came from (never connects)

Creating files ​

CommandDescription
mmk create <name>Create a migration (default .js)
mmk create <name> --tsCreate a .ts migration
mmk create <name> --jsCreate a .js migration
mmk create <name> --template <path>Use a custom template
mmk create <name> --author <name>Set the author line (default: your git name and email)
mmk initGenerate mmk.config.js
mmk init --ts / --jsonGenerate .ts / .json config
mmk init --secret-providerGenerate a secret-manager config
mmk init --forceOverwrite an existing config
mmk init --namespace <ns>Write this repo's namespace into the config

Maintenance ​

CommandDescription
mmk importCopy a migrate-mongo history into mmk
mmk import --from <c> / --to <c>Source / target collection
mmk import --dry-runShow what would be imported
mmk import --trust-hashReuse migrate-mongo's fileHash
mmk import --forceImport even if mmk's history isn't empty
mmk unlockForce-release a stuck lock
mmk unlock --yesRelease without confirmation
mmk namespace adoptMove older records into this repo's new namespace
mmk namespace adopt --dry-runPreview what would move

Exit codes ​

CodeMeaning
0It worked, or there was nothing to do
1Something failed, or status --check found pending migrations

Released under the MIT License.