mmk import
Copies the history from a migrate-mongo changelog collection into mmk, so mmk knows which migrations already ran. You do this once, when you switch. The source collection is only read, never changed.
npx mmk import [options]For the full walkthrough, see Moving from migrate-mongo.
Examples
npx mmk import --dry-run # show what would be copied, write nothing
npx mmk import # copy it
npx mmk import --from old_log # the source collection has another name$ npx mmk import
Loaded config from mmk.config.js
✔ Imported 3 record(s) from "changelog" → "_mmk_migrations"
┌─────────────────────────────────┬───────┬─────────────────────┬────────────┐
│ Migration │ Batch │ Applied At │ Checksum │
├─────────────────────────────────┼───────┼─────────────────────┼────────────┤
│ 20250301100000-create-users.js │ 1 │ 2025-03-01 15:35:00 │ recomputed │
├─────────────────────────────────┼───────┼─────────────────────┼────────────┤
│ 20250412083000-add-sku-index.js │ 2 │ 2025-04-12 14:10:00 │ recomputed │
├─────────────────────────────────┼───────┼─────────────────────┼────────────┤
│ 20250720140000-split-address.js │ 3 │ 2025-07-20 19:40:00 │ recomputed │
└─────────────────────────────────┴───────┴─────────────────────┴────────────┘Options
| Option | Default | What it does |
|---|---|---|
--from <collection> | changelog | The migrate-mongo collection to read. |
--to <collection> | your migrationsCollection | Where to write the records. |
--dry-run | off | Show what would be imported, write nothing. |
--trust-hash | off | Use migrate-mongo's stored fileHash without checking it against the file. |
--force | off | Import even though the target already has records. |
--no-lock | off | Don't take the lock. Only for local development. |
--json | off | Print the result as JSON. |
--from and --to can't be the same collection.
Checksums
The Checksum column says where each checksum came from:
- If migrate-mongo stored a
fileHashand it matches the file on disk (or you passed--trust-hash), that hash is reused. - Otherwise it's computed from the file now (
recomputed). - If the file is gone, the checksum is left empty and you get a warning.
If the target isn't empty
If mmk's history collection already has records, import stops with IMPORT_TARGET_NOT_EMPTY. --force imports anyway, and the imported batches are numbered after the existing ones. Running a forced import twice gives the same result both times.
Imported records are forward-only
Imported records are marked origin: 'migrate-mongo'. Their files use migrate-mongo's up(db, client) style, which mmk can't run safely, so mmk down and mmk redo refuse them before touching anything. Migrations you write afterwards with mmk create roll back as normal.
With a namespace
If several repos shared one migrate-mongo changelog, set a namespace in each repo and run mmk import in each:
- A repo only imports records whose file is in its own migrations folder. The others are listed as skipped (
notInRepoin--json). - Imported records get this repo's namespace.
- The "target isn't empty" check and the batch numbers only count this namespace, so other repos never get in the way.