Changed default collection naming
Also added upgrade text
This commit is contained in:
@@ -5,6 +5,7 @@ Changelog
|
||||
Changes in dev
|
||||
==============
|
||||
|
||||
- Updated default collection naming convention
|
||||
- Added Document Mixin support
|
||||
- Fixed queryet __repr__ mid iteration
|
||||
- Added hint() support, so cantell Mongo the proper index to use for the query
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
MongoEngine User Documentation
|
||||
==============================
|
||||
|
||||
MongoEngine is an Object-Document Mapper, written in Python for working with
|
||||
MongoEngine is an Object-Document Mapper, written in Python for working with
|
||||
MongoDB. To install it, simply run
|
||||
|
||||
.. code-block:: console
|
||||
@@ -15,7 +15,7 @@ To get help with using MongoEngine, use the `MongoEngine Users mailing list
|
||||
<http://groups.google.com/group/mongoengine-users>`_ or come chat on the
|
||||
`#mongoengine IRC channel <irc://irc.freenode.net/mongoengine>`_.
|
||||
|
||||
If you are interested in contributing, join the developers' `mailing list
|
||||
If you are interested in contributing, join the developers' `mailing list
|
||||
<http://groups.google.com/group/mongoengine-dev>`_.
|
||||
|
||||
.. toctree::
|
||||
@@ -26,6 +26,7 @@ If you are interested in contributing, join the developers' `mailing list
|
||||
apireference
|
||||
django
|
||||
changelog
|
||||
upgrading
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
73
docs/upgrade.rst
Normal file
73
docs/upgrade.rst
Normal file
@@ -0,0 +1,73 @@
|
||||
=========
|
||||
Upgrading
|
||||
=========
|
||||
|
||||
0.4 to 0.5
|
||||
===========
|
||||
|
||||
There have been the following backwards incompatibilities from 0.4 to 0.5:
|
||||
|
||||
#. Default collection naming.
|
||||
|
||||
Previously it was just lowercase, its now much more pythonic and readable as its
|
||||
lowercase and underscores, previously ::
|
||||
|
||||
class MyAceDocument(Document):
|
||||
pass
|
||||
|
||||
MyAceDocument._meta['collection'] == myacedocument
|
||||
|
||||
In 0.5 this will change to ::
|
||||
|
||||
class MyAceDocument(Document):
|
||||
pass
|
||||
|
||||
MyAceDocument._get_collection_name() == my_ace_document
|
||||
|
||||
To upgrade use a Mixin class to set meta like so ::
|
||||
|
||||
class BaseMixin(object):
|
||||
meta = {
|
||||
'collection': lambda c: c.__name__.lower()
|
||||
}
|
||||
|
||||
class MyAceDocument(Document, BaseMixin):
|
||||
pass
|
||||
|
||||
MyAceDocument._get_collection_name() == myacedocument
|
||||
|
||||
Alternatively, you can rename your collections eg ::
|
||||
|
||||
from mongoengine.connection import _get_db
|
||||
from mongoengine.base import _document_registry
|
||||
|
||||
def rename_collections():
|
||||
db = _get_db()
|
||||
|
||||
failure = False
|
||||
|
||||
collection_names = [d._get_collection_name() for d in _document_registry.values()]
|
||||
|
||||
for new_style_name in collection_names:
|
||||
if not new_style_name: # embedded documents don't have collections
|
||||
continue
|
||||
old_style_name = new_style_name.replace('_', '')
|
||||
|
||||
if old_style_name == new_style_name:
|
||||
continue # Nothing to do
|
||||
|
||||
existing = db.collection_names()
|
||||
if old_style_name in existing:
|
||||
if new_style_name in existing:
|
||||
failure = True
|
||||
print "FAILED to rename: %s to %s (already exists)" % (
|
||||
old_style_name, new_style_name)
|
||||
else:
|
||||
db[old_style_name].rename(new_style_name)
|
||||
print "Renamed: %s to %s" % (old_style_name, new_style_name)
|
||||
|
||||
if failure:
|
||||
print "Upgrading collection names failed"
|
||||
else:
|
||||
print "Upgraded collection names"
|
||||
|
||||
Reference in New Issue
Block a user