Migrations for MongoEngine ODM inspired by Django
Project description
Mongoengine-migrate
Work in progress
Schema migrations for Mongoengine ODM. Inspired by Django migrations system.
How it works
Let's suppose that we already have the following Document declaration:
from mongoengine import Document, fields
class Books(Document):
name = fields.StringField()
year = fields.StringField(max_length=4)
isbn = fields.StringField()
Then we changed couple of things:
# Add Author Document
class Author(Document):
name = fields.StringField(required=True)
class Books(Document):
caption = fields.StringField(required=True) # Make required and rename
year = fields.fields.IntField() # Change type to IntField
# Removed field isbn
author = fields.ReferenceField(Author) # Add field
Such changes should be reflected in database during upgrading. To detect changes run the command:
mongoengine-migrate makemigrations -m myproject.db
New migration file will be created:
from mongoengine_migrate.actions import *
dependencies = [
'my_migration'
]
forward = [
CreateDocument('Author', collection='author'),
CreateField('Author', 'name', choices=None, db_field='name', default=None, max_length=None,
min_length=None, null=False, primary_key=False, regex=None, required=True,
sparse=False, type_key='StringField', unique=False, unique_with=None),
RenameField('Books', 'name', new_name='caption'),
AlterField('Books', 'caption', required=True, db_field='caption'),
AlterField('Books', 'year', type_key='IntField', min_value=None, max_value=None),
DropField('Books', 'isbn'),
CreateField('Books', 'author', choices=None, db_field='author', dbref=False, default=None,
target_doctype='Author', null=False, primary_key=False, required=False, sparse=False,
type_key='ReferenceField', unique=False, unique_with=None),
]
Now in order to migrate database to the last migration, just run the command:
mongoengine-migrate migrate
Or to migrate to the certain migration:
mongoengine-migrate migrate my_migration
...to be continued
Roadmap
- Migrations graph utilities and core code
- Basic collection actions
- Basic field actions
- User-defined code action
- Basic data type fields support (string, integer, float, etc.)
- Dictionary, list fields support
- Reference fields support
- Embedded documents support + actions
- Geo fields support
- GridFS fields support
- Altering fields in embedded documents
- Document inheritance support
- Dynamic documents support
- Index support
- Generic* fields support
- Interactive mode
- Schema repair tools
- Alpha release
Author
Igor Derkach, gosha753951@gmail.com
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
Close
Hashes for mongoengine-migrate-0.0.1a1.dev2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 416a79c7d445e982238f718eb61f24c86fee2c3197f768c02e2199159d8790a1 |
|
MD5 | 73e8fa5fb3da01ba74023468f02b3e7d |
|
BLAKE2b-256 | 5234704c5ff423b8d116b0981386ff487d042232f634f3f24fea2d00b3e8be96 |