Commit 04f6d9c3 authored by Julien Muchembled's avatar Julien Muchembled

storage: update backend version between each migration step

parent 875fc1b9
......@@ -161,11 +161,14 @@ class DatabaseManager(object):
"The database can not be upgraded because you have unfinished"
" transactions. Use an older version of NEO to verify them.")
def _getVersion(self):
def migrate(self):
version = int(self.getConfiguration("version") or 0)
if self.VERSION < version:
raise DatabaseFailure("The database can not be downgraded.")
return version
while version < self.VERSION:
version += 1
getattr(self, '_migrate%s' % version)()
self.setConfiguration("version", version)
def doOperation(self, app):
pass
......
......@@ -176,6 +176,10 @@ class MySQLDatabaseManager(DatabaseManager):
if e.args[0] != NO_SUCH_TABLE:
raise
def _migrate1(self):
self._checkNoUnfinishedTransactions()
self.query("DROP TABLE IF EXISTS ttrans")
def _setup(self, dedup=False):
self._config.clear()
q = self.query
......@@ -188,14 +192,9 @@ class MySQLDatabaseManager(DatabaseManager):
name VARBINARY(255) NOT NULL PRIMARY KEY,
value VARBINARY(255) NULL
) ENGINE=""" + engine)
self._setConfiguration("version", self.VERSION)
else:
# Automatic migration.
version = self._getVersion()
if version < 1:
self._checkNoUnfinishedTransactions()
q("DROP TABLE IF EXISTS ttrans")
self._setConfiguration("version", self.VERSION)
self.migrate()
# The table "pt" stores a partition table.
q("""CREATE TABLE IF NOT EXISTS pt (
......
......@@ -112,6 +112,10 @@ class SQLiteDatabaseManager(DatabaseManager):
if not e.args[0].startswith("no such table:"):
raise
def _migrate1(self):
self._checkNoUnfinishedTransactions()
self.query("DROP TABLE IF EXISTS ttrans")
def _setup(self, dedup=False):
# SQLite does support transactional Data Definition Language statements
# but unfortunately, the built-in Python binding automatically commits
......@@ -126,14 +130,9 @@ class SQLiteDatabaseManager(DatabaseManager):
q("CREATE TABLE IF NOT EXISTS config ("
" name TEXT NOT NULL PRIMARY KEY,"
" value TEXT)")
self._setConfiguration("version", self.VERSION)
else:
# Automatic migration.
version = self._getVersion()
if version < 1:
self._checkNoUnfinishedTransactions()
q("DROP TABLE IF EXISTS ttrans")
self._setConfiguration("version", self.VERSION)
self.migrate()
# The table "pt" stores a partition table.
q("""CREATE TABLE IF NOT EXISTS pt (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment