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,20 +50,21 @@ def upgrade(migrate_engine):
meta_tables[t_name].create()
for row in select([meter]).execute():
meter_id = row['id']
rmeta = json.loads(row['resource_metadata'])
for key, v in utils.dict_to_keyval(rmeta):
ins = None
if isinstance(v, basestring) or v is None:
ins = meta_tables['metadata_text'].insert()
elif isinstance(v, bool):
ins = meta_tables['metadata_bool'].insert()
elif isinstance(v, (int, long)):
ins = meta_tables['metadata_int'].insert()
elif isinstance(v, float):
ins = meta_tables['metadata_float'].insert()
if ins:
ins.values(id=meter_id, meta_key=key, value=v).execute()
if row['resource_metadata']:
meter_id = row['id']
rmeta = json.loads(row['resource_metadata'])
for key, v in utils.dict_to_keyval(rmeta):
ins = None
if isinstance(v, basestring) or v is None:
ins = meta_tables['metadata_text'].insert()
elif isinstance(v, bool):
ins = meta_tables['metadata_bool'].insert()
elif isinstance(v, (int, long)):
ins = meta_tables['metadata_int'].insert()
elif isinstance(v, float):
ins = meta_tables['metadata_float'].insert()
if ins is not None:
ins.values(id=meter_id, meta_key=key, value=v).execute()
def downgrade(migrate_engine):