From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 11:45:18 +0000 (+0000) Subject: [Minor] Check Redis layout before converting X-Git-Tag: 1.7.0~121 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ac04a740a831c712c93bacb40a4a230131c89281;p=rspamd.git [Minor] Check Redis layout before converting --- diff --git a/lualib/rspamadm/configwizard.lua b/lualib/rspamadm/configwizard.lua index 3d3530b0c..b5bff38ce 100644 --- a/lualib/rspamadm/configwizard.lua +++ b/lualib/rspamadm/configwizard.lua @@ -351,10 +351,7 @@ local function check_redis_classifier(cls, changes) end end - if not cls.new_schema then - printf("You are using an old schema for %s/%s", symbol_ham, symbol_spam) - try_convert() - else + local function get_version() local _,conn = lua_redis.redis_connect_sync(parsed_redis, true) -- We still need to check versions local lua_script = [[ @@ -369,7 +366,33 @@ return ver ]] conn:add_cmd('EVAL', {lua_script, '1', symbol_spam}) local _,ver = conn:exec() - if tonumber(ver) ~= 2 then + + return tonumber(ver) + end + + if not cls.new_schema then + local ver = get_version() + + if ver ~= 2 then + printf("You are using an old schema for %s/%s", symbol_ham, symbol_spam) + try_convert() + else + printf("You have configured an old schema for %s/%s but your data has new layout", + symbol_ham, symbol_spam) + + if ask_yes_no("Switch config to the new schema?", true) then + changes.l['classifier_bayes'] = { + new_schema = true, + } + + if expire then + changes.l['classifier_bayes'].expire = expire + end + end + end + else + local ver = get_version() + if ver ~= 2 then printf("You have configured new schema for %s/%s but your DB has old data", symbol_spam, symbol_ham) try_convert()