ensure collections created on upgrade

upgrade does not check that collections exists. this can cause
issues when running upgrade before any data is inserted. this patch
creates collection on upgrade of db2nosql as it does for mongodb.

Change-Id: Iea79688ed81866c0b00aaa80f101b6f045af5bc1
This commit is contained in:
gordon chung 2015-04-20 10:19:05 -04:00
parent 1b593e9b00
commit b244fb14c3
4 changed files with 19 additions and 5 deletions

View File

@ -64,11 +64,7 @@ class Connection(pymongo_base.Connection):
self.upgrade()
def upgrade(self):
# create collection if not present
if 'alarm' not in self.db.conn.collection_names():
self.db.conn.create_collection('alarm')
if 'alarm_history' not in self.db.conn.collection_names():
self.db.conn.create_collection('alarm_history')
super(Connection, self).upgrade()
# Establish indexes
ttl = cfg.CONF.database.alarm_history_time_to_live
impl_mongodb.Connection.update_ttl(

View File

@ -54,6 +54,13 @@ class Connection(base.Connection):
AVAILABLE_STORAGE_CAPABILITIES,
)
def upgrade(self):
# create collection if not present
if 'alarm' not in self.db.conn.collection_names():
self.db.conn.create_collection('alarm')
if 'alarm_history' not in self.db.conn.collection_names():
self.db.conn.create_collection('alarm_history')
def update_alarm(self, alarm):
"""Update alarm."""
data = alarm.as_dict()

View File

@ -55,6 +55,11 @@ class Connection(pymongo_base.Connection):
self.upgrade()
def upgrade(self):
# create collection if not present
if 'event' not in self.db.conn.collection_names():
self.db.conn.create_collection('event')
def clear(self):
# drop_database command does nothing on db2 database since this has
# not been implemented. However calling this method is important for

View File

@ -156,6 +156,12 @@ class Connection(pymongo_base.Connection):
return init_str
def upgrade(self, version=None):
# create collection if not present
if 'resource' not in self.db.conn.collection_names():
self.db.conn.create_collection('resource')
if 'meter' not in self.db.conn.collection_names():
self.db.conn.create_collection('meter')
# Establish indexes
#
# We need variations for user_id vs. project_id because of the