Skip to content

migronaut audit ​

Check the setup before you need it to work. Read-only diagnostics — audit reports, it never fixes.

bash
migronaut audit [options]

Why it exists ​

Most migration failures aren't the migration's fault: useTransaction is on against a standalone server, a crashed run left a stale lock, the URI points at the wrong database, or Node is too old to import the .ts files in migrations/. Each of those surfaces as a driver error mid-deploy, when you can least afford to debug it.

migronaut audit answers them all in one command, in a few hundred milliseconds, without applying anything.

Usage ​

bash
migronaut audit          # human-readable checklist
migronaut audit --json   # machine-readable report for CI
✔ config       Loaded (database "my_app")
✔ connection   Connected
✔ transactions Replica set "rs0"
✔ indexes      All changelog indexes present
✔ lock         No lock held
✔ checksums    No drift among applied migrations
! pending      2 pending migration(s)
✔ runtime      Node 22.18.0

No problems found (1 warning(s))

What it checks ​

CheckPasses whenNotable failures
configThe config file and flags resolve and validateFatal — the rest is skipped
connectionMongoDB is reachable with these credentialsFatal — the rest is skipped
transactionsThe server is a replica set or sharded clusterFails if useTransaction is on against a standalone; warns otherwise
indexesEvery index of the changelog collection existsWarns — a missing index costs speed, not correctness. (Migronaut's own indexes: for your collections' indexes, see converge --check.)
lockNo lock, or a lock that's still within its TTLWarns when a lock is past its TTL — likely a crashed run
checksumsNo applied migration was edited afterwardsFails, and names each drifted file
pendingNothing is waiting to be appliedWarns with the count
searchOnly when a declared collection has searchIndexes: the server has Atlas Search, and no declared search index failed to buildFails where Search is missing and converge would refuse; warns where it is missing with onSearchUnavailable: 'skip', or a build FAILED
runtimeNode can load your migration filesWarns when .ts files need Node ≥ 22.18 or a loader

config and connection are fatal because everything after them depends on a live database. Every other check is independent: one failing doesn't stop the others from running.

Options ​

OptionDescription
--jsonEmit the full AuditReport as JSON on stdout.

Plus the global flags: --uri, --db, --dir, --config.

Exit codes ​

CodeMeaning
0No check failed. Warnings do not change this.
1At least one check failed.

Warnings are advisory by design — a pending migration or a missing index is normal at some point in every project's life, and shouldn't break a pipeline. Only a genuine misconfiguration exits non-zero.

In CI ​

Run it before up so a broken environment fails fast, with a message that says what's wrong:

yaml
- run: npx migronaut audit
- run: npx migronaut up

Or inspect the report yourself:

bash
migronaut audit --json | jq -r '.checks[] | select(.status != "pass") | "\(.name): \(.detail)"'

Programmatic API ​

ts
import { MigratorKit } from '@alexify/migronaut';

const migrator = new MigratorKit({ uri, dbName: 'my_app' });
const report = await migrator.audit();   // → AuditReport

if (!report.ok) {
  for (const check of report.checks.filter((c) => c.status === 'fail')) {
    console.error(`${check.name}: ${check.detail}`);
  }
}
await migrator.disconnect();

audit() connects on its own and records a connection failure as a check rather than throwing, so it stays useful precisely when things are broken.

See also ​

Released under the MIT License.