forked from openlp/openlp
Handle missing tables and set the meta data to the correct value
bzr-revno: 1727
This commit is contained in:
commit
b0584ccd09
@ -79,8 +79,11 @@ def upgrade_db(url, upgrade):
|
|||||||
Provides a class for the metadata table.
|
Provides a class for the metadata table.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
load_changes = True
|
||||||
tables = upgrade.upgrade_setup(metadata)
|
try:
|
||||||
|
tables = upgrade.upgrade_setup(metadata)
|
||||||
|
except SQLAlchemyError, DBAPIError:
|
||||||
|
load_changes = False
|
||||||
metadata_table = Table(u'metadata', metadata,
|
metadata_table = Table(u'metadata', metadata,
|
||||||
Column(u'key', types.Unicode(64), primary_key=True),
|
Column(u'key', types.Unicode(64), primary_key=True),
|
||||||
Column(u'value', types.UnicodeText(), default=None)
|
Column(u'value', types.UnicodeText(), default=None)
|
||||||
@ -96,16 +99,21 @@ def upgrade_db(url, upgrade):
|
|||||||
if version > upgrade.__version__:
|
if version > upgrade.__version__:
|
||||||
return version, upgrade.__version__
|
return version, upgrade.__version__
|
||||||
version += 1
|
version += 1
|
||||||
while hasattr(upgrade, u'upgrade_%d' % version):
|
if load_changes:
|
||||||
log.debug(u'Running upgrade_%d', version)
|
while hasattr(upgrade, u'upgrade_%d' % version):
|
||||||
try:
|
log.debug(u'Running upgrade_%d', version)
|
||||||
getattr(upgrade, u'upgrade_%d' % version)(session, metadata, tables)
|
try:
|
||||||
version_meta.value = unicode(version)
|
getattr(upgrade, u'upgrade_%d' % version) \
|
||||||
except SQLAlchemyError, DBAPIError:
|
(session, metadata, tables)
|
||||||
log.exception(u'Could not run database upgrade script "upgrade_%s"'\
|
version_meta.value = unicode(version)
|
||||||
', upgrade process has been halted.', version)
|
except SQLAlchemyError, DBAPIError:
|
||||||
break
|
log.exception(u'Could not run database upgrade script '
|
||||||
version += 1
|
'"upgrade_%s", upgrade process has been halted.', version)
|
||||||
|
break
|
||||||
|
version += 1
|
||||||
|
else:
|
||||||
|
version_meta = Metadata.populate(key=u'version',
|
||||||
|
value=int(upgrade.__version__))
|
||||||
session.add(version_meta)
|
session.add(version_meta)
|
||||||
session.commit()
|
session.commit()
|
||||||
return int(version_meta.value), upgrade.__version__
|
return int(version_meta.value), upgrade.__version__
|
||||||
|
Loading…
Reference in New Issue
Block a user