sql migration error in 020_add_metadata_tables

- add check to verify resource_metadata is not empty
- fix check to verify insert statement is set

Change-Id: I6b7c1d4a8ebf35af2547d97baa39831597012468
Closes-Bug: #1257779
This commit is contained in:
Gordon Chung 2013-12-04 10:16:22 -05:00
parent 83199dc852
commit 765370b89f

View File

@ -50,6 +50,7 @@ def upgrade(migrate_engine):
meta_tables[t_name].create() meta_tables[t_name].create()
for row in select([meter]).execute(): for row in select([meter]).execute():
if row['resource_metadata']:
meter_id = row['id'] meter_id = row['id']
rmeta = json.loads(row['resource_metadata']) rmeta = json.loads(row['resource_metadata'])
for key, v in utils.dict_to_keyval(rmeta): for key, v in utils.dict_to_keyval(rmeta):
@ -62,7 +63,7 @@ def upgrade(migrate_engine):
ins = meta_tables['metadata_int'].insert() ins = meta_tables['metadata_int'].insert()
elif isinstance(v, float): elif isinstance(v, float):
ins = meta_tables['metadata_float'].insert() ins = meta_tables['metadata_float'].insert()
if ins: if ins is not None:
ins.values(id=meter_id, meta_key=key, value=v).execute() ins.values(id=meter_id, meta_key=key, value=v).execute()