From ac04a740a831c712c93bacb40a4a230131c89281 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 11:45:18 +0000 Subject: [PATCH] [Minor] Check Redis layout before converting --- lualib/rspamadm/configwizard.lua | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) 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() -- 2.39.5