aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-06-27 20:48:35 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-06-27 20:48:35 -0500
commit2527754202ea9530c9046270e63d71581923dc77 (patch)
treece0a2c2084ef010847a535eec7ee19b7a4d47257
parent1f7749995dbbc2b6063d93e59948e008e60567eb (diff)
downloadmediagoblin-2527754202ea9530c9046270e63d71581923dc77.tar.lz
mediagoblin-2527754202ea9530c9046270e63d71581923dc77.tar.xz
mediagoblin-2527754202ea9530c9046270e63d71581923dc77.zip
Documenging index utils and adjusting how remove_deprecated_indexes gets arguments
More specifically, we now just take a dictionary of lists, like: {'collection': ['index_identifier1', 'index_identifier2']} Previously we took something with more info like in add_new_indexes, but that extra info isn't really necessary.
-rw-r--r--mediagoblin/db/util.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py
index 219617ec..46f899f7 100644
--- a/mediagoblin/db/util.py
+++ b/mediagoblin/db/util.py
@@ -41,6 +41,16 @@ def add_new_indexes(database, active_indexes=ACTIVE_INDEXES):
"""
Add any new indexes to the database.
+ Args:
+ - database: pymongo or mongokit database instance.
+ - active_indexes: indexes to possibly add in the pattern of:
+ {'collection_name': {
+ 'identifier': {
+ 'index': [index_foo_goes_here],
+ 'unique': True}}
+ where 'index' is the index to add and all other options are
+ arguments for collection.create_index.
+
Returns:
A list of indexes added in form ('collection', 'index_name')
"""
@@ -68,16 +78,21 @@ def remove_deprecated_indexes(database, deprecated_indexes=DEPRECATED_INDEXES):
"""
Remove any deprecated indexes from the database.
+ Args:
+ - database: pymongo or mongokit database instance.
+ - deprecated_indexes: the indexes to deprecate in the pattern of:
+ {'collection': ['index_identifier1', 'index_identifier2']}
+
Returns:
A list of indexes removed in form ('collection', 'index_name')
"""
indexes_removed = []
- for collection_name, indexes in deprecated_indexes.iteritems():
+ for collection_name, index_names in deprecated_indexes.iteritems():
collection = database[collection_name]
collection_indexes = collection.index_information().keys()
- for index_name, index_data in indexes.iteritems():
+ for index_name in index_names:
if index_name in collection_indexes:
collection.drop_index(index_name)