{"id":14956742,"url":"https://github.com/ableinc/mongrations","last_synced_at":"2025-10-16T16:19:35.943Z","repository":{"id":35048336,"uuid":"200550748","full_name":"ableinc/mongrations","owner":"ableinc","description":"A database independent migration and seeding tool for python. Compatible with MySQL, PostgreSQL and MongoDB.","archived":false,"fork":false,"pushed_at":"2023-01-11T02:13:56.000Z","size":92,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T13:23:10.010Z","etag":null,"topics":["async","automation","automation-tools","cli","database","migration","migration-tool","mongodb","mongodb-database","mongodb-migrations","mysql-migration","postgres-migration","postgresql","pymongo","pymysql","python3"],"latest_commit_sha":null,"homepage":"https://mongrations.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ableinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-04T23:13:15.000Z","updated_at":"2024-04-07T06:47:41.000Z","dependencies_parsed_at":"2023-01-15T12:44:16.285Z","dependency_job_id":null,"html_url":"https://github.com/ableinc/mongrations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fmongrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fmongrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fmongrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fmongrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ableinc","download_url":"https://codeload.github.com/ableinc/mongrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242570981,"owners_count":20151400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","automation","automation-tools","cli","database","migration","migration-tool","mongodb","mongodb-database","mongodb-migrations","mysql-migration","postgres-migration","postgresql","pymongo","pymysql","python3"],"created_at":"2024-09-24T13:13:25.763Z","updated_at":"2025-10-16T16:19:30.890Z","avatar_url":"https://github.com/ableinc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongrations\n\n![alt text](https://img.icons8.com/dusk/64/000000/database.png \"Mongrations Logo\")\nA database independent migration and seeding tool for python. Compatible with MySQL, PostgreSQL and MongoDB.\n\n## Required\n\n  - Python version 3.6 or above\n  - pip version 20.3 or above\n\n## Getting Started\n\n1 . Generate a migration file\n```bash\nmongrations create insert-into-members\n```\n2 . Contents of the generated migration file (*import and class definition are \nautogenerated* - **contents of up() and down() methods are user defined**.)\n```python\nfrom mongrations import Mongrations, Database\n\n# MongoDB example\nclass Mongration(Database):\n    def __init__(self):\n        super(Database, self).__init__()\n\n    def up(self):\n        collection = self.db['members']\n        data = {\n            'accountId': 1,\n            'username': 'admin',\n            'email': 'admin@able.digital',\n            'firstName': 'Site',\n            'lastName': 'Owner'\n        }\n        collection.insert_one(data)\n\n    def down(self):\n        collection = self.db['members']\n        collection.delete_one({'username': 'admin'})\n\n\nMongrations(Mongration)\n```\n3 . Run migrations\n```bash\nmongrations migrate\n```\n\n## Install\n\n```bash\npip install --upgrade pip\npip install -U mongrations\n\n```\nor install locally\n```bash\ngit clone https://github.com/ableinc/mongrations.git\ncd mongrations\npython -m pip install -r requirements.txt\npython -m pip install .\n```\n\n## Use\n\nMongrations comes with a CLI Tool and an import class for a pythonic migration approach. PyMongo, PyMySQL \u0026 Psycopg2 are used under\nthe hood, so follow \u003ca href=\"https://api.mongodb.com/python/current/tutorial.html#getting-a-collection\"\u003ePyMongo\u003c/a\u003e's,\n\u003ca href=\"https://github.com/PyMySQL/PyMySQL\"\u003ePyMySQL\u003c/a\u003e's, or \u003ca href=\"https://github.com/psycopg/psycopg2\"\u003ePsycopg2\u003c/a\u003e's documentation \nfor instructions on how to create your migrations. For the environment variable tool used in this application, follow \n\u003ca href='https://github.com/ableinc/pydotenvs'\u003ethis repo\u003c/a\u003e (its also installed with this package).\n\nRefer to Mongrations \u003ca href=\"https://mongrations.readthedocs.io/en/latest/\"\u003edocumentation\u003c/a\u003e for more information.\n\n**CLI**\n```bash\nUsage: mongrations [OPTIONS] COMMAND [ARGS]...\n\n  Mongrations; a database migration tool for Python 3.6 and above.\n\nOptions:\n  --version  Show the version and exit.\n  --help     Show this message and exit.\n\nCommands:\n  create\n  down\n  inspect\n  migrate\n  undo\n```\n**CLI Examples**\n```bash\nmongrations create [name]  # create new migration (w/ name)\nmongrations migrate  # run migrations\nmongrations down  # tear down migrations\nmongrations undo  # undo last migration\n```\n\n**Mongrations Class**\n```python\nfrom mongrations import MongrationsCli\n\nmigrations = MongrationsCli()\n\nmigrations.create(directory='migrations', name='file_name')\nmigrations.migrate()\nmigrations.down()\nmigrations.undo()\n```\nRun example migration in examples/ folder\n\n## Multi-instance\n\nIf your API uses multiple databases to write and read data, you can provide multiple database connections. This can be achieved by providing a connection object (```connection_obj```) to the ```Mongrations``` class in your migrations file. For a ```connection_obj``` example, please refer to the ```examples/``` folder. You can also do this by prepending the service name to your environment variables.\n\nSupported service names:\n\n  - ```MONGO_```\n  - ```MYSQL_```\n  - ```POSTGRES_```\n\nExample .env file:\n\n```properties\nMYSQL_HOST=localhost\nMYSQL_USER=root\nMYSQL_PASSWORD=password\nMYSQL_DB_NAME=myapp\nMYSQL_PORT=3306\n```\n\n**Note:** ```MONGO_``` service name does **NOT** accept ```MONGO_COLLECTION_NAME```. You will need to provide the collection name in your migration file. The synchronous and asynchronous instances of MongoDB use ```admin``` as the ```authSource``` by default. If you do not want to use ```authSource``` please use ```MONGO_AUTH_SOURCE=None```.\n\n## Issues\n\nPlease report all issues to repo.\n\nYou **MUST** have write access to your file system to use this application.\n\n##  Changelog\n\nJanuary 2023 - Version 1.1.4:\n\n  - Bugfix: CLI tool will now add service name to environment when using ```--mongrationFile.json```\n\nJanuary 2023 - Version 1.1.3:\n\n  - Updated: CLI tool to handle ```--mongrationFile``` for rollback and down command\n  - psycopg will be downloaded by the library. Installing from source is no longer an option.\n\nJanuary 2023 - Version 1.1.2:\n\n  - Bugfix: postgres connection library fix\n  - Bugfix: Database connection would close prematurely\n\nJanuary 2023 - Version 1.1.1:\n  - You can now use the ```mongrationFile.json``` file to add database connection variables. You can refer to an example of this file [here](mongrationFile.json)\n    - You can specify the environment with ```--migrationfile``` (default env is development):\n    ```bash\n    mongrations migrate --file mongrationFile.json --env development\n    ```\n  - The CLI tool can generate the ```mongrationFile.json``` file for you. Run this command:\n    ```bash\n    mongrations file\n    ```\n\nJanuary 2023 - Version 1.1.0:\n  - Fixed bug with CLI tool where directory argument wasn't being passed properly to the migrate function. \n  - The CLI tool has new arguments with better helper descriptions\n  - The database connection class has been updated to provide more enhances connection strings\n  - The cache system was rebuilt - The way mongrations caches will change in the future\n  - ```migrations``` directory will not be created until you create your first migration file\n  - Updated error codes and error messages.\n  - In the event your PYTHON_PATH is changed and points to a Python version less than 3.6 the CLI tool will prompt you.\n\nJanuary 2023 - Version 1.0.4:\n  - The cache system will now keep the cache file in the ```migrations/``` directory at root\n  - psycopg[binary,pool] will now be installed during pip installation (pip 20.3 \u003e is required)\n  - Removed the default ```pydotenvs``` import from the migration file\n  - Time (in ms) will be appended to file names instead of UUIDs\n  - The library wil be getting a rewrite and released under another name. This will be the last major release to the library under this name. Note: bug fixes will still be published.\n\nJanuary 2022 - Version 1.0.4:\n  - Squashed bugs\n  - Mongrations can now run on Linux\n  - Default: stdout error output if error occurs during caching operation\n  - Removed the psycopg2 install step from setup.py\n  - Simplified how the database connection strings are initialized\n  - Inspect will now pretty print JSON structure and provide file system location\n  - Updated ```examples/``` directory\n\nAugust 2020:\n  - Introduced the official version 1.0.0 of Mongrations!\n  - Rewrote command line tool; much easier and intuiative\n  - Extracted classes into their own files; reducing clutter\n  - Added a raw sql function that allows for much more flexibility\n  - File name rewrites (if you encounter an upgrade error run the option: --no-cache, with pip)\n  - psycopg2 is now installed optionally (refer to Notes)\n  - Super fast writing to the system\n  - Setup.py has been cleaned up. An occasional bug occured when installing\n  - Added/Updated examples (refer to Github)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fableinc%2Fmongrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fableinc%2Fmongrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fableinc%2Fmongrations/lists"}