← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bug-835427 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-835427 into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)
Related bugs:
  Bug #835427 in OpenLP: "OpenLP crashes when no databases exists"
  https://bugs.launchpad.net/openlp/+bug/835427

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-835427/+merge/73146

Handle missing tables and set the meta data to the correct value
-- 
https://code.launchpad.net/~trb143/openlp/bug-835427/+merge/73146
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/db.py'
--- openlp/core/lib/db.py	2011-08-26 19:09:25 +0000
+++ openlp/core/lib/db.py	2011-08-27 18:46:25 +0000
@@ -79,8 +79,11 @@
         Provides a class for the metadata table.
         """
         pass
-
-    tables = upgrade.upgrade_setup(metadata)
+    load_changes = True
+    try:
+        tables = upgrade.upgrade_setup(metadata)
+    except SQLAlchemyError, DBAPIError:
+        load_changes = False
     metadata_table = Table(u'metadata', metadata,
         Column(u'key', types.Unicode(64), primary_key=True),
         Column(u'value', types.UnicodeText(), default=None)
@@ -96,16 +99,21 @@
     if version > upgrade.__version__:
         return version, upgrade.__version__
     version += 1
-    while hasattr(upgrade, u'upgrade_%d' % version):
-        log.debug(u'Running upgrade_%d', version)
-        try:
-            getattr(upgrade, u'upgrade_%d' % version)(session, metadata, tables)
-            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
-        version += 1
+    if load_changes:
+        while hasattr(upgrade, u'upgrade_%d' % version):
+            log.debug(u'Running upgrade_%d', version)
+            try:
+                getattr(upgrade, u'upgrade_%d' % version) \
+                    (session, metadata, tables)
+                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
+            version += 1
+    else:
+        version_meta = Metadata.populate(key=u'version',
+            value=int(upgrade.__version__))
     session.add(version_meta)
     session.commit()
     return int(version_meta.value), upgrade.__version__


Follow ups