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): ...@@ -161,11 +161,14 @@ class DatabaseManager(object):
"The database can not be upgraded because you have unfinished" "The database can not be upgraded because you have unfinished"
" transactions. Use an older version of NEO to verify them.") " transactions. Use an older version of NEO to verify them.")
def _getVersion(self): def migrate(self):
version = int(self.getConfiguration("version") or 0) version = int(self.getConfiguration("version") or 0)
if self.VERSION < version: if self.VERSION < version:
raise DatabaseFailure("The database can not be downgraded.") 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): def doOperation(self, app):
pass pass
......
...@@ -176,6 +176,10 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -176,6 +176,10 @@ class MySQLDatabaseManager(DatabaseManager):
if e.args[0] != NO_SUCH_TABLE: if e.args[0] != NO_SUCH_TABLE:
raise raise
def _migrate1(self):
self._checkNoUnfinishedTransactions()
self.query("DROP TABLE IF EXISTS ttrans")
def _setup(self, dedup=False): def _setup(self, dedup=False):
self._config.clear() self._config.clear()
q = self.query q = self.query
...@@ -188,14 +192,9 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -188,14 +192,9 @@ class MySQLDatabaseManager(DatabaseManager):
name VARBINARY(255) NOT NULL PRIMARY KEY, name VARBINARY(255) NOT NULL PRIMARY KEY,
value VARBINARY(255) NULL value VARBINARY(255) NULL
) ENGINE=""" + engine) ) ENGINE=""" + engine)
else:
# Automatic migration.
version = self._getVersion()
if version < 1:
self._checkNoUnfinishedTransactions()
q("DROP TABLE IF EXISTS ttrans")
self._setConfiguration("version", self.VERSION) self._setConfiguration("version", self.VERSION)
else:
self.migrate()
# The table "pt" stores a partition table. # The table "pt" stores a partition table.
q("""CREATE TABLE IF NOT EXISTS pt ( q("""CREATE TABLE IF NOT EXISTS pt (
......
...@@ -112,6 +112,10 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -112,6 +112,10 @@ class SQLiteDatabaseManager(DatabaseManager):
if not e.args[0].startswith("no such table:"): if not e.args[0].startswith("no such table:"):
raise raise
def _migrate1(self):
self._checkNoUnfinishedTransactions()
self.query("DROP TABLE IF EXISTS ttrans")
def _setup(self, dedup=False): def _setup(self, dedup=False):
# SQLite does support transactional Data Definition Language statements # SQLite does support transactional Data Definition Language statements
# but unfortunately, the built-in Python binding automatically commits # but unfortunately, the built-in Python binding automatically commits
...@@ -126,14 +130,9 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -126,14 +130,9 @@ class SQLiteDatabaseManager(DatabaseManager):
q("CREATE TABLE IF NOT EXISTS config (" q("CREATE TABLE IF NOT EXISTS config ("
" name TEXT NOT NULL PRIMARY KEY," " name TEXT NOT NULL PRIMARY KEY,"
" value TEXT)") " value TEXT)")
else:
# Automatic migration.
version = self._getVersion()
if version < 1:
self._checkNoUnfinishedTransactions()
q("DROP TABLE IF EXISTS ttrans")
self._setConfiguration("version", self.VERSION) self._setConfiguration("version", self.VERSION)
else:
self.migrate()
# The table "pt" stores a partition table. # The table "pt" stores a partition table.
q("""CREATE TABLE IF NOT EXISTS pt ( 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