Create mongodb schema migrations for your project. Supports migration creation, upgrade and downgrade. Can also use this tool as part of your own script
Project description
mongo-migrate
Create Mongodb migrations using Python.
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:
- 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.
- 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.
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
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 Features
- Support for the connection string,
- Support for authenticated databases
- Support for configuration files to eliminate retyping the CLI arguments.
- More shortcuts for migration generation
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mongo_migrate-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6421fec53cb75e66d9a2966972b25558253bdc73207f0ac30645fc2677608311 |
|
MD5 | d9040fe1b88925070739417f31e8ddda |
|
BLAKE2b-256 | ba3de49c545dbfdf592dda25c46b244c15c0d8bf4d17eebcbcbf0296cd195b0c |