Comparison

plugins/mod_storage_sql.lua @ 13833:497efa2cbf2c 13.0

mod_storage_sql: Add shell command to create tables and indices (again) This is meant as a way to diagnose e.g. issues creating indices. It would have been nice to capture e.g. PostgreSQL notices, but LuaDBI would need support for this first, see https://github.com/mwild1/luadbi/issues/62
author Kim Alvefur <zash@zash.se>
date Wed, 09 Apr 2025 15:06:48 +0200
parent 13832:5973a5d22ab5
child 13836:c600794cafb6
comparison
equal deleted inserted replaced
13832:5973a5d22ab5 13833:497efa2cbf2c
894 end); 894 end);
895 if not success then 895 if not success then
896 module:log("error", "Failed to delete obsolete index \"prosody_index\""); 896 module:log("error", "Failed to delete obsolete index \"prosody_index\"");
897 return false; 897 return false;
898 end 898 end
899 end
900 if not indices["prosody_unique_index"] then
901 module:log("error", "New index \"prosody_unique_index\" does not exist!");
902 return false;
899 end 903 end
900 end 904 end
901 return changes; 905 return changes;
902 end 906 end
903 907
1042 else 1046 else
1043 print("Available commands:"); 1047 print("Available commands:");
1044 print("","upgrade - Perform database upgrade"); 1048 print("","upgrade - Perform database upgrade");
1045 end 1049 end
1046 end 1050 end
1051
1052 module:add_item("shell-command", {
1053 section = "sql";
1054 section_desc = "SQL management commands";
1055 name = "create";
1056 desc = "Create the tables and indices used by Prosody (again)";
1057 args = { { name = "host"; type = "string" } };
1058 host_selector = "host";
1059 handler = function(shell, _host)
1060 local logger = require "prosody.util.logger";
1061 local writing = false;
1062 local sink = logger.add_simple_sink(function (source, level, message)
1063 local print = shell.session.print;
1064 if writing or source ~= "sql" then return; end
1065 writing = true;
1066 print(message);
1067 writing = false;
1068 end);
1069
1070 local debug_enabled = engine._debug;
1071 engine:debug(true);
1072 create_table(engine);
1073 engine:debug(debug_enabled);
1074
1075 if not logger.remove_sink(sink) then
1076 module:log("warn", "Unable to remove log sink");
1077 end
1078 end;
1079 })