diff sat/memory/sqlite.py @ 2964:17c61d09a85b

memory (sqlite): exit with an error if current db version is higher than version expected in current code
author Goffi <goffi@goffi.org>
date Fri, 21 Jun 2019 12:59:36 +0200
parents c0f6fd75af5f
children c13333fcde5e
line wrap: on
line diff
--- a/sat/memory/sqlite.py	Fri Jun 21 11:37:51 2019 +0200
+++ b/sat/memory/sqlite.py	Fri Jun 21 12:59:36 2019 +0200
@@ -21,7 +21,6 @@
 from sat.core.constants import Const as C
 from sat.core import exceptions
 from sat.core.log import getLogger
-log = getLogger(__name__)
 from sat.memory.crypto import BlockCipher, PasswordHasher
 from sat.tools.config import fixConfigOption
 from twisted.enterprise import adbapi
@@ -29,6 +28,7 @@
 from twisted.words.protocols.jabber import jid
 from twisted.python import failure
 from collections import OrderedDict
+import sys
 import re
 import os.path
 import cPickle as pickle
@@ -36,6 +36,8 @@
 import sqlite3
 import json
 
+log = getLogger(__name__)
+
 CURRENT_DB_VERSION = 8
 
 # XXX: DATABASE schemas are used in the following way:
@@ -1053,6 +1055,13 @@
                     log.warning(_(u"Here are the commands that should fix the situation, use at your own risk (do a backup before modifying database), you can go to SàT's MUC room at sat@chat.jabberfr.org for help\n### SQL###\n%s\n### END SQL ###\n") % u'\n'.join("%s;" % statement for statement in update_raw))
                     raise exceptions.DatabaseError("Database mismatch")
             else:
+                if local_version > CURRENT_DB_VERSION:
+                    log.error(_(
+                        u"You database version is higher than the one used in this SàT "
+                        u"version, are you using several version at the same time? We "
+                        u"can't run SàT with this database."))
+                    sys.exit(1)
+
                 # Database is not up-to-date, we'll do the update
                 if force_update:
                     log.info(_("Database content needs a specific processing, local database will be updated"))