# **Mongrate**
A lightweight MongoDB migration tool.
---
## **Overview**
Mongrate simplifies managing schema changes in MongoDB. It provides a robust migration system to track, apply, and rollback changes to your MongoDB database.
---
## **Features**
- Initialize a MongoDB migration system with a single command.
- Create migration scripts effortlessly.
- Apply migrations incrementally or all at once.
- Rollback specific migrations or all migrations.
- View migration history, including applied and pending migrations.
---
## **Installation**
Install Mongrate using pip:
```bash
pip install mongrate
```
---
## **Getting Started**
### 1. Initialize the System
Set up Mongrate in your project:
```bash
mongrate init
```
This command creates a configuration file (`mongrate_config.yaml`) and a migrations directory.
### 2. Configuration
Update the `mongrate_config.yaml` file with your database details:
```yaml
db_url: "mongodb://localhost:27017"
db_name: "my_database"
migrations_dir: "migrations"
```
### 3. Create a Migration
Generate a new migration file:
```bash
mongrate create add_users_collection
```
This creates a new script in the migrations directory.
### 4. Define Migration
Edit the generated migration script to specify your database changes:
```python
# Example: 20241228230118_add_users_collection.py
def upgrade(db):
db.create_collection("users")
db["users"].insert_one({"name": "admin", "role": "superuser"})
def downgrade(db):
db.drop_collection("users")
```
### 5. Apply Migrations
Apply all pending migrations:
```bash
mongrate upgrade all
```
Apply a specific migration:
```bash
mongrate upgrade 20241228230118_add_users_collection.py
```
### 6. Rollback Migrations
Rollback all migrations:
```bash
mongrate downgrade all
```
Rollback a specific migration:
```bash
mongrate downgrade 20241228230118_add_users_collection.py
```
### 7. View Migration History
Check applied and pending migrations:
```bash
mongrate history
```
Example output:
```yaml
Applied Migrations:
- 20241228230118_add_users_collection.py
Pending Migrations:
- 20241228233045_add_orders_collection.py
```
---
## **Commands Overview**
| Command | Description |
|--------------------------------|---------------------------------------|
| `mongrate init` | Initializes the migration system. |
| `mongrate create <name>` | Creates a new migration script. |
| `mongrate upgrade all` | Applies all pending migrations. |
| `mongrate upgrade <file>` | Applies a specific migration. |
| `mongrate downgrade all` | Rolls back all applied migrations. |
| `mongrate downgrade <file>` | Rolls back a specific migration. |
| `mongrate history` | Displays applied and pending migrations. |
---
## **Example Workflow**
### Initialize Mongrate:
```bash
mongrate init
```
### Create a migration:
```bash
mongrate create add_users_collection
```
### Edit the migration file:
```python
def upgrade(db):
db.create_collection("users")
```
### Apply migrations:
```bash
mongrate upgrade all
```
### View migration history:
```bash
mongrate history
```
### Rollback a migration:
```bash
mongrate downgrade add_users_collection.py
```
---
## **Why Use Mongrate?**
- Simplifies MongoDB migration management.
- Tracks applied and pending migrations automatically.
- Provides an easy-to-use CLI.
- Designed specifically for MongoDB workflows.
---
## **License**
Mongrate is licensed under the MIT License.
---
Raw data
{
"_id": null,
"home_page": "https://github.com/Happy-Kumar-Sharma/mongo-migrate",
"name": "mongrate",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "MongoDB Migration, mongodb-migrator, python mongodb module, best mongodb migration library",
"author": "Happy Sharma",
"author_email": "happycse54@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/63/f7/ccf7a65ff8c2ec8cd9e6f2742e6feddd1f1cd009621aafa04558dcdeda5f/mongrate-0.0.5.tar.gz",
"platform": null,
"description": "# **Mongrate**\nA lightweight MongoDB migration tool.\n\n---\n\n## **Overview**\nMongrate simplifies managing schema changes in MongoDB. It provides a robust migration system to track, apply, and rollback changes to your MongoDB database.\n\n---\n\n## **Features**\n- Initialize a MongoDB migration system with a single command.\n- Create migration scripts effortlessly.\n- Apply migrations incrementally or all at once.\n- Rollback specific migrations or all migrations.\n- View migration history, including applied and pending migrations.\n\n---\n\n## **Installation**\n\nInstall Mongrate using pip:\n\n```bash\npip install mongrate\n```\n\n---\n\n## **Getting Started**\n\n### 1. Initialize the System\nSet up Mongrate in your project:\n\n```bash\nmongrate init\n```\n\nThis command creates a configuration file (`mongrate_config.yaml`) and a migrations directory.\n\n### 2. Configuration\nUpdate the `mongrate_config.yaml` file with your database details:\n\n```yaml\ndb_url: \"mongodb://localhost:27017\"\ndb_name: \"my_database\"\nmigrations_dir: \"migrations\"\n```\n\n### 3. Create a Migration\nGenerate a new migration file:\n\n```bash\nmongrate create add_users_collection\n```\n\nThis creates a new script in the migrations directory.\n\n### 4. Define Migration\nEdit the generated migration script to specify your database changes:\n\n```python\n# Example: 20241228230118_add_users_collection.py\n\ndef upgrade(db):\n db.create_collection(\"users\")\n db[\"users\"].insert_one({\"name\": \"admin\", \"role\": \"superuser\"})\n\ndef downgrade(db):\n db.drop_collection(\"users\")\n```\n\n### 5. Apply Migrations\nApply all pending migrations:\n\n```bash\nmongrate upgrade all\n```\n\nApply a specific migration:\n\n```bash\nmongrate upgrade 20241228230118_add_users_collection.py\n```\n\n### 6. Rollback Migrations\nRollback all migrations:\n\n```bash\nmongrate downgrade all\n```\n\nRollback a specific migration:\n\n```bash\nmongrate downgrade 20241228230118_add_users_collection.py\n```\n\n### 7. View Migration History\nCheck applied and pending migrations:\n\n```bash\nmongrate history\n```\n\nExample output:\n\n```yaml\nApplied Migrations:\n - 20241228230118_add_users_collection.py\n\nPending Migrations:\n - 20241228233045_add_orders_collection.py\n```\n\n---\n\n## **Commands Overview**\n\n| Command | Description |\n|--------------------------------|---------------------------------------|\n| `mongrate init` | Initializes the migration system. |\n| `mongrate create <name>` | Creates a new migration script. |\n| `mongrate upgrade all` | Applies all pending migrations. |\n| `mongrate upgrade <file>` | Applies a specific migration. |\n| `mongrate downgrade all` | Rolls back all applied migrations. |\n| `mongrate downgrade <file>` | Rolls back a specific migration. |\n| `mongrate history` | Displays applied and pending migrations. |\n\n---\n\n## **Example Workflow**\n\n### Initialize Mongrate:\n\n```bash\nmongrate init\n```\n\n### Create a migration:\n\n```bash\nmongrate create add_users_collection\n```\n\n### Edit the migration file:\n\n```python\ndef upgrade(db):\n db.create_collection(\"users\")\n```\n\n### Apply migrations:\n\n```bash\nmongrate upgrade all\n```\n\n### View migration history:\n\n```bash\nmongrate history\n```\n\n### Rollback a migration:\n\n```bash\nmongrate downgrade add_users_collection.py\n```\n\n---\n\n## **Why Use Mongrate?**\n- Simplifies MongoDB migration management.\n- Tracks applied and pending migrations automatically.\n- Provides an easy-to-use CLI.\n- Designed specifically for MongoDB workflows.\n\n---\n\n## **License**\nMongrate is licensed under the MIT License.\n\n---\n",
"bugtrack_url": null,
"license": null,
"summary": "A MongoDB migration tool.",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://github.com/Happy-Kumar-Sharma/mongo-migrate"
},
"split_keywords": [
"mongodb migration",
" mongodb-migrator",
" python mongodb module",
" best mongodb migration library"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f69ca9432e728de350df9a12977175178c971b057682357922b517547620f701",
"md5": "ef1a09672ea7d9a0527c608b848b1e3a",
"sha256": "66e824fe2fdc2429fd84c236e20ddd7ccc3f679e252ac6297073e7944c8ca078"
},
"downloads": -1,
"filename": "mongrate-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ef1a09672ea7d9a0527c608b848b1e3a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7664,
"upload_time": "2024-12-29T12:46:04",
"upload_time_iso_8601": "2024-12-29T12:46:04.475220Z",
"url": "https://files.pythonhosted.org/packages/f6/9c/a9432e728de350df9a12977175178c971b057682357922b517547620f701/mongrate-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "63f7ccf7a65ff8c2ec8cd9e6f2742e6feddd1f1cd009621aafa04558dcdeda5f",
"md5": "2e18df18dfaa9ebf152fb257e546da68",
"sha256": "f61b081d6ae5a0a2d98c91d05a98692bb7a36ce9f214fdd67f0f5be0f60c2b70"
},
"downloads": -1,
"filename": "mongrate-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "2e18df18dfaa9ebf152fb257e546da68",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6738,
"upload_time": "2024-12-29T12:46:10",
"upload_time_iso_8601": "2024-12-29T12:46:10.007201Z",
"url": "https://files.pythonhosted.org/packages/63/f7/ccf7a65ff8c2ec8cd9e6f2742e6feddd1f1cd009621aafa04558dcdeda5f/mongrate-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-29 12:46:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Happy-Kumar-Sharma",
"github_project": "mongo-migrate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "mongrate"
}