manager command 'setup_db_indices': Adds missing database indices.
This does NOT drop and recreate existing indices, nor does it reconfigure existing indices. If you want that, drop them manually first.
This commit is contained in:
parent
6a7d3bd972
commit
d5683afb84
@ -142,6 +142,41 @@ def setup_db(admin_email):
|
||||
'is_private': False})
|
||||
|
||||
|
||||
@manager.command
|
||||
def setup_db_indices():
|
||||
"""Adds missing database indices."""
|
||||
|
||||
import pymongo
|
||||
|
||||
log.info('Adding missing database indices.')
|
||||
log.warning('This does NOT drop and recreate existing indices, '
|
||||
'nor does it reconfigure existing indices. '
|
||||
'If you want that, drop them manually first.')
|
||||
db = app.data.driver.db
|
||||
coll = db['tokens']
|
||||
coll.create_index([('user', pymongo.ASCENDING)])
|
||||
coll.create_index([('token', pymongo.ASCENDING)])
|
||||
|
||||
coll = db['notifications']
|
||||
coll.create_index([('user', pymongo.ASCENDING)])
|
||||
|
||||
coll = db['activities-subscriptions']
|
||||
coll.create_index([('context_object', pymongo.ASCENDING)])
|
||||
|
||||
coll = db['nodes']
|
||||
# This index is used for queries on project, and for queries on
|
||||
# the combination (project, node type).
|
||||
coll.create_index([('project', pymongo.ASCENDING),
|
||||
('node_type', pymongo.ASCENDING)])
|
||||
coll.create_index([('parent', pymongo.ASCENDING)])
|
||||
|
||||
coll_names = db.collection_names(include_system_collections=False)
|
||||
for coll_name in sorted(coll_names):
|
||||
stats = db.command('collStats', coll_name)
|
||||
log.info('Collection %25s takes up %.3f MiB index space',
|
||||
coll_name, stats['totalIndexSize'] / 2**20)
|
||||
|
||||
|
||||
def _default_permissions():
|
||||
"""Returns a dict of default permissions.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user