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