Fix database upgrades from partially initialized schema 1 databases
authorPatrick Uiterwijk <puiterwijk@redhat.com>
Thu, 3 Sep 2015 19:36:20 +0000 (21:36 +0200)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Fri, 4 Sep 2015 02:42:02 +0000 (04:42 +0200)
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
ipsilon/util/data.py

index 835924d..fcf058d 100644 (file)
@@ -342,7 +342,8 @@ class Store(Log):
             fallback_version = self.load_options('dbinfo').get('scheme',
                                                                {})
             if 'version' in fallback_version:
-                return int(fallback_version['version'])
+                # Explanation for this is in def upgrade_database(self)
+                return -1
             else:
                 return None
 
@@ -388,6 +389,14 @@ class Store(Log):
             # Just initialize a new schema
             self._initialize_schema()
             self._store_new_schema_version(self._code_schema_version())
+        elif old_schema_version == -1:
+            # This is a special-case from 1.0: we only created tables at the
+            # first time they were actually used, but the upgrade code assumes
+            # that the tables exist. So let's fix this.
+            self._initialize_schema()
+            # The old version was schema version 1
+            self._store_new_schema_version(1)
+            self.upgrade_database()
         elif old_schema_version != self._code_schema_version():
             # Upgrade from old_schema_version to code_schema_version
             self.debug('Upgrading from schema version %i' % old_schema_version)