diff options
author | Patrick Uiterwijk <puiterwijk@redhat.com> | 2015-05-08 16:56:36 +0200 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2015-05-08 13:33:49 -0400 |
commit | 9b7f9756d89f0a7908d9b7323f682f34b37d200e (patch) | |
tree | a6412c22a8a1638e42d87c722f66777c1058d071 | |
parent | be55bdf7ee36ad38b25b5f79fc4b82edb2557148 (diff) | |
download | ipsilon.git-9b7f9756d89f0a7908d9b7323f682f34b37d200e.tar.gz ipsilon.git-9b7f9756d89f0a7908d9b7323f682f34b37d200e.tar.xz ipsilon.git-9b7f9756d89f0a7908d9b7323f682f34b37d200e.zip |
Add database schema versioning
With this skeleton code we can add upgrade code
if we ever change the database schema.
https://fedorahosted.org/ipsilon/ticket/56
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
-rw-r--r-- | ipsilon/util/data.py | 28 | ||||
-rwxr-xr-x | tests/pgdb.py | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py index 7fdc508..b7fde31 100644 --- a/ipsilon/util/data.py +++ b/ipsilon/util/data.py @@ -12,6 +12,7 @@ import uuid import logging +CURRENT_SCHEMA_VERSION = 1 OPTIONS_COLUMNS = ['name', 'option', 'value'] UNIQUE_DATA_COLUMNS = ['uuid', 'name', 'value'] @@ -267,6 +268,33 @@ class Store(Log): else: self._db = SqlStore.get_connection(name) self._query = SqlQuery + self._upgrade_database() + + def _upgrade_database(self): + if self.is_readonly: + # If the database is readonly, we cannot do anything to the + # schema. Let's just return, and assume people checked the + # upgrade notes + return + current_version = self.load_options('dbinfo').get('scheme', None) + if current_version is None or 'version' not in current_version: + # No version stored, storing current version + self.save_options('dbinfo', 'scheme', + {'version': CURRENT_SCHEMA_VERSION}) + current_version = CURRENT_SCHEMA_VERSION + else: + current_version = int(current_version['version']) + if current_version != CURRENT_SCHEMA_VERSION: + self.debug('Upgrading database schema from %i to %i' % ( + current_version, CURRENT_SCHEMA_VERSION)) + self._upgrade_database_from(current_version) + + def _upgrade_database_from(self, old_schema_version): + # Insert code here to upgrade from old_schema_version to + # CURRENT_SCHEMA_VERSION + raise Exception('Unable to upgrade database to current schema' + ' version: version %i is unknown!' % + old_schema_version) @property def is_readonly(self): diff --git a/tests/pgdb.py b/tests/pgdb.py index 78800ff..f9be5f0 100755 --- a/tests/pgdb.py +++ b/tests/pgdb.py @@ -27,6 +27,7 @@ idp_a = {'hostname': '${ADDRESS}:${PORT}', 'admin_user': '${TEST_USER}', 'system_user': '${TEST_USER}', 'instance': '${NAME}', + 'openid': 'False', 'secure': 'no', 'testauth': 'yes', 'pam': 'no', |