Skip to content

Commit

Permalink
Fix handling of mqtt_pub table definition from mysql.sql and fix shou…
Browse files Browse the repository at this point in the history
…ld_update_schema/1 in ejabberd_sql_schema.erl
  • Loading branch information
alexeyshch committed May 18, 2024
1 parent 66a08b6 commit cb49fcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/ejabberd_sql_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,15 @@ string_to_type(SType) ->
<<"integer">> -> integer;
<<"int">> -> integer;
<<"int(", _/binary>> -> integer;
<<"int ", _/binary>> -> integer;
<<"smallint">> -> smallint;
<<"smallint(", _/binary>> -> smallint;
<<"numeric">> -> numeric;
<<"decimal", _/binary>> -> numeric;
<<"bigserial">> -> bigserial;
<<"boolean">> -> boolean;
<<"tinyint(1)">> -> boolean;
<<"tinyint", _/binary>> -> smallint;
<<"bytea">> -> blob;
<<"blob">> -> blob;
<<"timestamp", _/binary>> -> timestamp;
Expand Down Expand Up @@ -340,6 +342,8 @@ check_columns_compatibility(RequiredColumns, Columns) ->
{integer, bigint} -> true;
{integer, numeric} -> true;
{bigint, numeric} -> true;
%% a workaround for MySQL definition of mqtt_pub
{bigint, integer} -> true;
{bigserial, integer} -> true;
{bigserial, bigint} -> true;
{bigserial, numeric} -> true;
Expand Down Expand Up @@ -768,7 +772,17 @@ should_update_schema(Host) ->
true ->
case ejabberd_sql:use_new_schema() of
true ->
Host == ejabberd_config:get_myname();
%% TODO: not efficient when there are many hosts
case lists:search(
fun(H) ->
lists:member(
sql, ejabberd_option:auth_method(H))
end, ejabberd_option:hosts()) of
{value, Host} ->
true;
_ ->
false
end;
false ->
true
end;
Expand Down
2 changes: 1 addition & 1 deletion src/mod_mqtt_sql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sql_schemas() ->
#sql_column{name = <<"content_type">>, type = text},
#sql_column{name = <<"response_topic">>, type = text},
#sql_column{name = <<"correlation_data">>, type = blob},
#sql_column{name = <<"user_property">>, type = blob},
#sql_column{name = <<"user_properties">>, type = blob},
#sql_column{name = <<"expiry">>, type = bigint}],
indices = [#sql_index{
columns = [<<"topic">>, <<"server_host">>],
Expand Down

0 comments on commit cb49fcf

Please sign in to comment.