Now with exception handling.

This commit is contained in:
Raoul Snyman 2011-08-25 13:47:07 +02:00
parent 923261c59c
commit ddf148449d
2 changed files with 9 additions and 6 deletions

View File

@ -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()

View File

@ -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