forked from openlp/openlp
Error Handling improvements
This commit is contained in:
parent
3f078a553f
commit
67894aa8d9
@ -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)
|
||||||
@ -90,22 +93,27 @@ def upgrade_db(url, upgrade):
|
|||||||
version_meta = session.query(Metadata).get(u'version')
|
version_meta = session.query(Metadata).get(u'version')
|
||||||
if version_meta is None:
|
if version_meta is None:
|
||||||
version_meta = Metadata.populate(key=u'version', value=u'0')
|
version_meta = Metadata.populate(key=u'version', value=u'0')
|
||||||
version = 0 if tables else upgrade.__version__;
|
version = 0
|
||||||
else:
|
else:
|
||||||
version = int(version_meta.value)
|
version = int(version_meta.value)
|
||||||
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__
|
||||||
|
@ -42,18 +42,15 @@ def upgrade_setup(metadata):
|
|||||||
upgrade process. If you want to drop a table, you need to remove it from
|
upgrade process. If you want to drop a table, you need to remove it from
|
||||||
here, and add it to your upgrade function.
|
here, and add it to your upgrade function.
|
||||||
"""
|
"""
|
||||||
try:
|
tables = {
|
||||||
tables = {
|
u'authors': Table(u'authors', metadata, autoload=True),
|
||||||
u'authors': Table(u'authors', metadata, autoload=True),
|
u'media_files': Table(u'media_files', metadata, autoload=True),
|
||||||
u'media_files': Table(u'media_files', metadata, autoload=True),
|
u'song_books': Table(u'song_books', metadata, autoload=True),
|
||||||
u'song_books': Table(u'song_books', metadata, autoload=True),
|
u'songs': Table(u'songs', metadata, autoload=True),
|
||||||
u'songs': Table(u'songs', metadata, autoload=True),
|
u'topics': Table(u'topics', metadata, autoload=True),
|
||||||
u'topics': Table(u'topics', metadata, autoload=True),
|
u'authors_songs': Table(u'authors_songs', metadata, autoload=True),
|
||||||
u'authors_songs': Table(u'authors_songs', metadata, autoload=True),
|
u'songs_topics': Table(u'songs_topics', metadata, autoload=True)
|
||||||
u'songs_topics': Table(u'songs_topics', metadata, autoload=True)
|
}
|
||||||
}
|
|
||||||
except:
|
|
||||||
tables = None
|
|
||||||
return tables
|
return tables
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,12 +40,9 @@ def upgrade_setup(metadata):
|
|||||||
upgrade process. If you want to drop a table, you need to remove it from
|
upgrade process. If you want to drop a table, you need to remove it from
|
||||||
here, and add it to your upgrade function.
|
here, and add it to your upgrade function.
|
||||||
"""
|
"""
|
||||||
try:
|
tables = {
|
||||||
tables = {
|
u'songusage_data': Table(u'songusage_data', metadata, autoload=True)
|
||||||
u'songusage_data': Table(u'songusage_data', metadata, autoload=True)
|
}
|
||||||
}
|
|
||||||
except:
|
|
||||||
tables = None
|
|
||||||
return tables
|
return tables
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user