Skip to main content

Migrate mongodb seamlessly with python and mongo-migrate. Supports migration creation, upgrade, and downgrade

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongo_migrate2-0.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongo_migrate2-0.1.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mongo_migrate2-0.1.2.tar.gz.

File metadata

  • Download URL: mongo_migrate2-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mongo_migrate2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 55815ce3746a28901d9a6ae707d33ad3d5ef8a97225ad625478ef143e3d90f70
MD5 24bdd175a8299ebe01ca3cb71c1c3f92
BLAKE2b-256 31cfc6222bc9631a595a85c3cae8e9fb903b3e83fcf4d310761fc6ff24fd1792

See more details on using hashes here.

File details

Details for the file mongo_migrate2-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mongo_migrate2-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mongo_migrate2-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5de374311889c10c8c90b0bbba9ad5cabe882259fef95fa48f29217cc46188c
MD5 42ddea11884ff98a83fc1c8732620f36
BLAKE2b-256 29d8faca9ad5e905f0ee2d01dca198f248a6e5ed477a2654b153be8b9c3befd8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page