forked from openlp/openlp
Now with exception handling.
This commit is contained in:
parent
923261c59c
commit
ddf148449d
@ -32,7 +32,7 @@ import os
|
|||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
from sqlalchemy import Table, MetaData, Column, types, create_engine
|
from sqlalchemy import Table, MetaData, Column, types, create_engine
|
||||||
from sqlalchemy.exc import InvalidRequestError
|
from sqlalchemy.exc import SQLAlchemyError, InvalidRequestError, DBAPIError
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker, mapper
|
from sqlalchemy.orm import scoped_session, sessionmaker, mapper
|
||||||
from sqlalchemy.pool import NullPool
|
from sqlalchemy.pool import NullPool
|
||||||
|
|
||||||
@ -87,11 +87,14 @@ def upgrade_db(url, upgrade):
|
|||||||
version += 1
|
version += 1
|
||||||
while hasattr(upgrade, u'upgrade_%d' % version):
|
while hasattr(upgrade, u'upgrade_%d' % version):
|
||||||
log.debug(u'Running upgrade_%d', version)
|
log.debug(u'Running upgrade_%d', version)
|
||||||
do_upgrade = getattr(upgrade, u'upgrade_%d' % version)
|
try:
|
||||||
if not do_upgrade(session, metadata, tables):
|
getattr(upgrade, u'upgrade_%d' % version)(session, metadata, tables)
|
||||||
break
|
|
||||||
version += 1
|
version += 1
|
||||||
version_meta.value = unicode(version)
|
version_meta.value = unicode(version)
|
||||||
|
except SQLAlchemyError, DBAPIError:
|
||||||
|
log.exception(u'Could not run database upgrade script "upgrade_%s"'\
|
||||||
|
', upgrade process has been halted.', version)
|
||||||
|
break
|
||||||
session.add(version_meta)
|
session.add(version_meta)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
@ -60,4 +60,4 @@ def upgrade_1(session, metadata, tables):
|
|||||||
if metadata.bind.url.get_dialect().name != 'sqlite':
|
if metadata.bind.url.get_dialect().name != 'sqlite':
|
||||||
ForeignKeyConstraint([u'song_id'], [u'songs.id'],
|
ForeignKeyConstraint([u'song_id'], [u'songs.id'],
|
||||||
table=tables[u'media_files']).create()
|
table=tables[u'media_files']).create()
|
||||||
return True
|
|
||||||
|
Loading…
Reference in New Issue
Block a user