Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2963:c90a2586fdf9 | 2964:17c61d09a85b |
---|---|
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core import exceptions | 22 from sat.core import exceptions |
23 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
24 log = getLogger(__name__) | |
25 from sat.memory.crypto import BlockCipher, PasswordHasher | 24 from sat.memory.crypto import BlockCipher, PasswordHasher |
26 from sat.tools.config import fixConfigOption | 25 from sat.tools.config import fixConfigOption |
27 from twisted.enterprise import adbapi | 26 from twisted.enterprise import adbapi |
28 from twisted.internet import defer | 27 from twisted.internet import defer |
29 from twisted.words.protocols.jabber import jid | 28 from twisted.words.protocols.jabber import jid |
30 from twisted.python import failure | 29 from twisted.python import failure |
31 from collections import OrderedDict | 30 from collections import OrderedDict |
31 import sys | |
32 import re | 32 import re |
33 import os.path | 33 import os.path |
34 import cPickle as pickle | 34 import cPickle as pickle |
35 import hashlib | 35 import hashlib |
36 import sqlite3 | 36 import sqlite3 |
37 import json | 37 import json |
38 | |
39 log = getLogger(__name__) | |
38 | 40 |
39 CURRENT_DB_VERSION = 8 | 41 CURRENT_DB_VERSION = 8 |
40 | 42 |
41 # XXX: DATABASE schemas are used in the following way: | 43 # XXX: DATABASE schemas are used in the following way: |
42 # - 'current' key is for the actual database schema, for a new base | 44 # - 'current' key is for the actual database schema, for a new base |
1051 update_data = self.generateUpdateData(local_sch, current_sch, True) | 1053 update_data = self.generateUpdateData(local_sch, current_sch, True) |
1052 update_raw = yield self.update2raw(update_data) | 1054 update_raw = yield self.update2raw(update_data) |
1053 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)) | 1055 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)) |
1054 raise exceptions.DatabaseError("Database mismatch") | 1056 raise exceptions.DatabaseError("Database mismatch") |
1055 else: | 1057 else: |
1058 if local_version > CURRENT_DB_VERSION: | |
1059 log.error(_( | |
1060 u"You database version is higher than the one used in this SàT " | |
1061 u"version, are you using several version at the same time? We " | |
1062 u"can't run SàT with this database.")) | |
1063 sys.exit(1) | |
1064 | |
1056 # Database is not up-to-date, we'll do the update | 1065 # Database is not up-to-date, we'll do the update |
1057 if force_update: | 1066 if force_update: |
1058 log.info(_("Database content needs a specific processing, local database will be updated")) | 1067 log.info(_("Database content needs a specific processing, local database will be updated")) |
1059 else: | 1068 else: |
1060 log.info(_("Database schema has changed, local database will be updated")) | 1069 log.info(_("Database schema has changed, local database will be updated")) |