Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

MongoMig

Alembic-style schema evolution and migrations for MongoDB.

Built for Python services (FastAPI, Flask, workers) on PyMongo, Motor or Beanie.

Status: pre-alpha. Milestone 1 (foundation) is done. Running migrations (upgrade / downgrade), schema diff and autogenerate are coming next. See the roadmap below.

$ mongomig init
$ mongomig revision -m "add user profile"
Created revision 7be204a1c9e0 → migrations/versions/20260924_1432_7be204a1c9e0_add_user_profile.py

$ mongomig history
a1f3c9d20b44 -> 7be204a1c9e0 (head), add user profile
<base> -> a1f3c9d20b44, initial

$ mongomig current
Database: app
Current:  a1f3c9d20b44  initial
Pending:  1
  - 7be204a1c9e0  add user profile

Install

pip install mongomig          # not yet published — install from source for now

Requires Python 3.11+ and MongoDB 6.0+.

Quick start

mongomig init                                   # creates mongomig.yaml + migrations/
export MONGODB_URI="mongodb://localhost:27017"
mongomig revision -m "initial"                  # new revision file
mongomig current                                # what's applied vs pending

mongomig init creates:

mongomig.yaml                   # connection + execution settings (no secrets!)
migrations/
├── env.py                      # Python: points MongoMig at your models
├── schema_snapshot.json        # last known expected schema (used by autogenerate)
└── versions/                   # one file per revision

Configuration

database:
  uri: ${MONGODB_URI}                 # ${VAR} and ${VAR:-default} are expanded
  name: ${MONGODB_DATABASE:-app}

Per-environment overrides live in mongomig.<env>.yaml and are merged on top:

mongomig --env production current     # or MONGOMIG_ENV=production

MongoMig never prints passwords or full connection strings. It warns you if a password is written directly into the config file.

Revision files

"""add user profile"""

revision = "7be204a1c9e0"
down_revision = "a1f3c9d20b44"
reversible = True


def upgrade(ctx):
    ...


def downgrade(ctx):
    ...

Revision order comes from down_revision, not from the file name. Revision ids are random, so two developers working on separate branches never get the same id. If both branches add a revision, mongomig heads shows two heads, and mongomig revision refuses to continue until you choose a parent with --head.

Revision ids can be shortened to a unique prefix of 4 or more characters, the same way git handles commit hashes.

Commands

Command Needs MongoDB Description
init no Create config and migrations directory
revision -m MSG [--head REV] no Create a new revision
heads no Show head revision(s)
history no List revisions, newest first
current yes Applied vs pending revisions (read-only)

Global options: --config PATH, --env NAME, --json, --verbose, --version.

Exit codes: 0 success · 1 validation · 2 execution/connection · 3 configuration · 4 revision conflict · 5 lock · 6 checksum mismatch.

Roadmap

  • M1 Foundation: config, CLI, revision files, revision graph, tracking
  • M2 Migration engine: upgrade, downgrade, locking, merge, checksums, FastAPI lifespan helper
  • M3 Schema engine: @collection models, Beanie support, inspect, snapshots
  • M4 Autogenerate: diff, revision --autogenerate, index/validator diff
  • M5 Production safety: --dry-run, plan, batching, progress
  • M6 Release: validate, doctor, docs, PyPI

Development

make install        # uv venv + editable install with dev extras
make mongo-up       # MongoDB 7 single-node replica set in Docker
make check          # ruff + mypy --strict + pytest

Integration tests are skipped automatically when MongoDB isn't running. To test against another MongoDB version, run MONGO_VERSION=8.0 make mongo-up.

Releasing

  1. Bump src/mongomig/_version.py and update CHANGELOG.md, then merge to main.
  2. On GitHub, create a Release with tag v<version> (e.g. v0.1.0) and publish it.
  3. .github/workflows/release.yml checks that the tag matches the version, builds and smoke-tests the wheel, then publishes to PyPI through Trusted Publishing.

License

MIT

Release files for mongomig 0.1.0.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongomig 0.1.0.dev0
File Size Uploaded
mongomig-0.1.0.dev0.tar.gz 34.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongomig 0.1.0.dev0
File Interpreter ABI Platform
mongomig-0.1.0.dev0-py3-none-any.whl Python 3 none any Details

Total release size: 68.0 kB

Release files / mongomig-0.1.0.dev0.tar.gz

Download URL mongomig-0.1.0.dev0.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e38c94af497c84d42512278d0722ab4e4de9fc1c8230b6184edc8598bdb46077
BLAKE2b-256 checksum
How to use checksums
de13b13cd3997d4093d9ffe5bcb4a2098802e0d51a316f80354f842fb4deaca4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / mongomig-0.1.0.dev0-py3-none-any.whl

Download URL mongomig-0.1.0.dev0-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e5478cca68a1293d962f10c096d5430e0fe4adf8da671764806d1ee0cda55d8
BLAKE2b-256 checksum
How to use checksums
511c7bd22fbe3507ef8e2064b4b53f0f438f565f72d2e3df760d42a1a4c5ac77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0.dev0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page