Skip to main content

Simple MongoDB migrations tool.

Project description

Mongo Migrator

License PyPI version Python Versions MongoDB

logo

Summary

Mongo Migrator is a simple tool to manage MongoDB migrations. It allows you to create, run, and rollback migrations in a MongoDB database.

Features

  • Easily create migration files with a predefined template.
  • Apply migrations to the database.
  • Revert migrations quickly.
  • Validate and ensure no bifurcations in migration history.
  • Keep a clear version history of migrations.

Installation

To install Mongo-Migrator, you can use PyPI:

pip install mongo-migrator

Configuration

Mongo-Migrator uses a configuration file named mongo-migrator.config to connect to your MongoDB instance and manage migrations. Here is an example of a configuration file:

[database]
host = localhost
port = 27017
name = your_database
user = your_user
password = your_password

[migrations]
directory = migrations
collection = version_history

Configuration breakdown

  • database: MongoDB connection details.
    • host: MongoDB host address.
    • port: MongoDB port number.
    • name: The database name where migrations will be applied.
    • user: (Optional) The username for database authentication.
    • password: (Optional) The password for database authentication.
  • migrations: Migration settings.
    • directory: Directory where migration files are stored.
    • collection: Name of the collection that stores migration version information.

Usage

Mongo-Migrator provides several commands to manage your migrations. These can be executed from the command line.

Initialize the package

To initialize the package, run the following command:

mongo_migrator init

This command initializes the migration system by reading the configuration file, creating the migrations directory, and setting up the version collection in the specified MongoDB database.

Create a new migration

To create a new migration, run the following command:

mongo-migrator create "Added new field"

This command generates a new migration file with a timestamp and the provided title. The new migration file will be placed in the migrations directory.

Apply migrations

mongo-migrator upgrade

This command applies all pending migrations in the correct order. You can also specify a version to upgrade to. The argument <version> indicates the last version which will be applied.

mongo-migrator upgrade --version <version>

Rollback migrations

mongo-migrator downgrade

This command rolls back the last migration that was applied. You can also specify a version to downgrade to. The argument <version> indicates the version in which the database will be rolled back. Downgrade in migration <version> will not be applied.

mongo-migrator downgrade --version <version>

View history

mongo-migrator history

This command displays the migration history, showing the version number and the migration message.

Other commands

  • mongo-migrator [ -h | --help ]: Display the help message.
  • mongo-migrator [ -v | --version ]: Display the package version.

Examples

You can find example projects in the repository mongo-migrator-examples.

There you will find:

  • example-project: An already initialized project with some migrations created.
  • test-project: The same project as example-project but not initialized. It can be used to test the mongo-migrator package.

Contributing

By the time, contributions are not being accepted. Issues, on the other hand, will be reviewed and answered.

However, feel free to fork the repository and make your own changes if needed.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Package by Álvaro Martín López

Banner by Sergio Gallego García

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_migrator-1.0.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

mongo_migrator-1.0.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file mongo_migrator-1.0.1.tar.gz.

File metadata

  • Download URL: mongo_migrator-1.0.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.12 Linux/6.8.0-52-generic

File hashes

Hashes for mongo_migrator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 257cf03c99d4cada967e1be0eb20b50f682a1fc2bb5f916036fb8b17757fc2c4
MD5 539d504755cf69a65fe850d933da86e0
BLAKE2b-256 9d29217c1fe0574de00c8dbffe9682d49db2e99f2107f1235c11c1263df11da1

See more details on using hashes here.

File details

Details for the file mongo_migrator-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mongo_migrator-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.12 Linux/6.8.0-52-generic

File hashes

Hashes for mongo_migrator-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2141cfa1c95334cc84bc2ecdf64eec158815363c80b8525a2b20d8bdefa6d733
MD5 1808282a1e105e4be0bc8922120a448a
BLAKE2b-256 5472001959c5ecc8325f3657094d90d6aec970532aa5f364069a4cce6a9fad3c

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