fix upgrade_db

This commit is contained in:
Phill Ridout 2015-02-18 21:13:12 +00:00
parent 5e8ad1710b
commit a6dfbdcf71

View File

@ -145,9 +145,13 @@ def upgrade_db(url, upgrade):
version_meta = session.query(Metadata).get('version') version_meta = session.query(Metadata).get('version')
if version_meta is None: if version_meta is None:
# Tables have just been created - fill the version field with the most recent version # Tables have just been created - fill the version field with the most recent version
version = upgrade.__version__ if session.query(Metadata).get('dbversion'):
version = 0
else:
version = upgrade.__version__
version_meta = Metadata.populate(key='version', value=version) version_meta = Metadata.populate(key='version', value=version)
session.add(version_meta) session.add(version_meta)
session.commit()
else: else:
version = int(version_meta.value) version = int(version_meta.value)
if version > upgrade.__version__: if version > upgrade.__version__: