Skip to main content

Welcome to mongo-migrate

Migrate Mongodb seamlessly using Python and mongo-migrate.

MongoDB is a schemaless database but most of the time the data that you store in the database will end up have a loose schema. The Python library is aimed to solve the below problem scenarios:

  1. As your project grows, the schema also changes and grows with it. When you want to go back to a specific version of the code and run that version. Most of the time, you do not remember the database schema used with the particular version of code. This is where creating a migration file and keeping it under version control along with your code helps. You can retrace the steps to that particular version of the schema.
  2. Lastly, even if your code base is in another language, you can use the Mongo-migrate package to create migrations. Exactly for this reason, mongo-migrate is coming out of the box with a lot of subcommands.

You can read my the detailed article here

The mongo-migrate library can create migrations, and perform upgrade and downgrade operations.

Installation

pip install mongo-migrate

Usage

usage: mongo-migrate [-h] {create,upgrade,downgrade} ...

positional arguments:
  {create, upgrade, downgrade}
    create              create a new migration
    upgrade             upgrade the database to the specific migration
    downgrade           downgrade the database to the specific migration

optional arguments:
  -h, --help            show this help message and exit

Key Features

Create Migrations

usage: mongo-migrate create [-h] [--host HOST] [--port PORT] [--database DATABASE] [--migrations MIGRATIONS] [--title TITLE] --message MESSAGE

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           the database host
  --port PORT           the database port
  --database DATABASE   provide the database name
  --migrations MIGRATIONS
                        provide the folder to store migrations
  --title TITLE         title will be used in the file name
  --message MESSAGE     message will be recorded as a comment inside the migration file

An example command would look like this:

mongo-migrate create --host 127.0.0.1 --port 27017 --database test --message 'first migration'

Upgrade database

usage: mongo-migrate upgrade [-h] [--host HOST] [--port PORT] [--database DATABASE] [--migrations MIGRATIONS] [--upto UPTO]

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           the database host
  --port PORT           the database port
  --database DATABASE   provide the database name
  --migrations MIGRATIONS
                        provide the folder to store migrations
  --upto UPTO           target migration timestamp

An example command would look like this:

mongo-migrate upgrade --host 127.0.0.1 --port 27017 --database test --upto 20230815092813

Downgrade database

usage: mongo-migrate downgrade [-h] [--host HOST] [--port PORT] [--database DATABASE] [--migrations MIGRATIONS] [--upto UPTO]

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           the database host
  --port PORT           the database port
  --database DATABASE   provide the database name
  --migrations MIGRATIONS
                        provide the folder to store migrations
  --upto UPTO           target migration timestamp

An example command would look like this:

mongo-migrate downgrade --host 127.0.0.1 --port 27017 --database test --upto 20230815092813

Planned Enhancements

Our commitment to continuous improvement includes planned features such as:

  • Support for connection string,
  • Support for authenticated databases
  • Configuration Files: Eliminate the need for repetitive CLI arguments.
  • More migration generation shortcuts

Get Involved

If you encounter any issues, please raise it as a ticket in the issue tracker. If you like to contribute to this open-source project, let me know.

Metadata

Release files for mongo-migrate 0.1.2

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

Source distribution (sdist)

Source distribution for mongo-migrate 0.1.2
File Size Uploaded Provenance
mongo_migrate-0.1.2.tar.gz 8.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mongo-migrate 0.1.2
File Interpreter ABI Platform
mongo_migrate-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / mongo_migrate-0.1.2.tar.gz

Download URL mongo_migrate-0.1.2.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a7572f22cb54c6b0c1fdf9ec339da8a4fe254a6098c881ae0ae31af39c2e739b
BLAKE2b-256 checksum
How to use checksums
3f624a9a05077f822d35d5360684278bd7f2ca0ee03d6729129cdae507ba5caa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / mongo_migrate-0.1.2-py3-none-any.whl

Download URL mongo_migrate-0.1.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8186c2d5478e99d745025ac59b498707440dd3c4e79691f81b3ffcb5262a0c91
BLAKE2b-256 checksum
How to use checksums
9cd6304bd5e92e4b14c19494e53338c5f9950e906a0d61cf2cb08bd4f83f6892
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Security for mongo-migrate 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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