项目作者: bdragon300

项目描述 :
Migrations for MongoEngine inspired by Django
高级语言: Python
项目地址: git://github.com/bdragon300/mongoengine-migrate.git
创建时间: 2020-03-31T17:10:43Z
项目社区:https://github.com/bdragon300/mongoengine-migrate

开源协议:Apache License 2.0

下载


Mongoengine-migrate

version
pyversions
travis
license

Framework-agnostic schema migrations for Mongoengine ODM.
Inspired by Django migrations system.

Read documentation

WARNING: this is an unstable version of software. Please backup your data before migrating

Installation

```shell script
pip3 install mongoengine-migrate

  1. ## Features
  2. * Documents
  3. * Creating, dropping, renaming
  4. * Renaming a collection
  5. * Creating, dropping, renaming of fields
  6. * Converting to/from a `DynamicDocument`
  7. * Inheritance
  8. * Embedded documents
  9. * Recursive creating, dropping
  10. * Renaming
  11. * Recursive creating, dropping, renaming of fields
  12. * Converting to/from a `DynamicEmbeddedDocument`
  13. * Inheritance
  14. * Altering fields in document and embedded documents
  15. * Changing of init parameters such as `db_field`, `required`, etc.
  16. * Convertion between field types (if possible)
  17. * Indexes
  18. * Creating, dropping, renaming
  19. * Handling fields constraints such as `unique` and `unique_with`
  20. * Automatic select a query or a python loop to perform an update depending on MongoDB version
  21. * Two policies of how to work with existing data which does not meet to mongoengine schema
  22. All mongoengine field types are supported, including simple types, lists, dicts, references,
  23. GridFS, geo types, generic types.
  24. ## Typical migration file
  25. ```python
  26. from mongoengine_migrate.actions import *
  27. # Existing data processing policy
  28. # Possible values are: strict, relaxed
  29. policy = "strict"
  30. # Names of migrations which the current one is dependent by
  31. dependencies = [
  32. 'previous_migration'
  33. ]
  34. # Action chain
  35. actions = [
  36. CreateDocument('Author', collection='author'),
  37. CreateField('Author', 'name', choices=None, db_field='name', default=None, max_length=None,
  38. min_length=None, null=False, primary_key=False, regex=None, required=False,
  39. sparse=False, type_key='StringField', unique=False, unique_with=None),
  40. RenameField('Book', 'name', new_name='caption'),
  41. AlterField('Book', 'caption', required=True, db_field='caption'),
  42. AlterField('Book', 'year', type_key='IntField', min_value=None, max_value=None),
  43. DropField('Book', 'isbn'),
  44. CreateField('Book', 'author', choices=None, db_field='author', dbref=False, default=None,
  45. target_doctype='Author', null=False, primary_key=False, required=False, sparse=False,
  46. type_key='ReferenceField', unique=False, unique_with=None),
  47. ]