MongoDB Migrations for Python 3.5+
Project description
Mongrations
A migrations tool for Python 3.5+. Mongrations started as a MongoDB migrations tool but has introduced MySQL & Postgres
as compatible servers for the Mongrations tool.
Steps
1 . Generate a migration file
mongrations -C true --name insert-into-members
2 . Contents of the generated migration file (import and class definition are autogenerated for migration file - contents of up() and down() are user defined.)
from mongrations import Mongrations, ClassType class Mongration: def __init__(self): pass @staticmethod def up(db: ClassType): collection = db['members'] data = { 'accountId': 1, 'username': 'admin', 'email': 'admin@able.digital', 'firstName': 'Site', 'lastName': 'Owner' } collection.insert_one(data) @staticmethod def down(db: ClassType): collection = db['members'] collection.delete_one({'username': 'admin'}) Mongrations(Mongration, 'sync')
3 . Run migrations
mongrations -M true
Install
pip install --upgrade mongrations
or install locally
python setup.py build sudo python setup.py install
Use
Mongrations comes with a CLI Tool as well as a class for a pythonic migration approach. PyMongo, PyMySQL & Psycopg2 are used under the hood, so follow PyMongo's, PyMySQL's, or Psycopg2's documentation for instructions on how to create your migrations. For the environment variable tool used in this application, follow this repo (its also installed with this package).
CLI
Usage: mongrations [OPTIONS] Options: -M, --migrate BOOLEAN Run migrations -C, --create BOOLEAN Create new migration -N, --name TEXT Name for newly created migration -F, --file_path TEXT File path for newly created migration -U, --undo BOOLEAN Undo last migration -D, --down BOOLEAN Revert database --version Show the version and exit. --help Show this message and exit.
CLI Examples
mongrations -C true --name [migration_name] # create new migration mongrations -M true # run migrations mongrations -D true # tear down migrations mongrations -U true # undo last migration
Mongrations Class
from mongrations import MongrationsCli migrations = MongrationsCli() migrations.create(file_path='file/path', name='file_name') migrations.migrate() migrations.down() migrations.undo()
Run example migration in examples/ folder
Issues
Please report all issues to repo.
Notes
You can install psycopg2 from source via setup.py develop build or refer to their repo.
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size mongrations-0.0.2-py3-none-any.whl (7.4 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size mongrations-0.0.2.tar.gz (6.5 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for mongrations-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dd3b94ce3f91260157e3adb8b149ebb41a0ce8804ce728badf23c28a496f893 |
|
MD5 | 66e8a9c0c3223ba61a4d315ec59fa8e2 |
|
BLAKE2-256 | b21b0b45ee3dbaf85e713a98061b349ac1eeaea85390e0abc74b9d039e7b2a70 |