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.0.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.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mongo_migrator-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fa799a92fa1f7d3a0060e2afc11479e4a2d9314399a7ba5de20d5cef90ee9c06
MD5 d61beae4449905924f7e2679f24dcea9
BLAKE2b-256 d677c4ce3b1dac2030f47143d2471ae03d2651adf85ab4733c3edb728f053a3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mongo_migrator-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69b1c7623031767bcaa76e51f2f9358853198ade5d5a6e35c6d25b87a07c8643
MD5 737ad4e809f653925a962ae3b9897aa6
BLAKE2b-256 ca4976f40076b75a766c0b98f2540cb2749eeef70862b61ce3ef53bfde69d3f2

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