From 8abf6474528351c0654bc72933534c3c5f631634 Mon Sep 17 00:00:00 2001 From: firest Date: Fri, 1 Jul 2022 18:23:29 +0800 Subject: [PATCH] fix(exclusive): add upgarde codes --- src/emqx_exclusive_subscription.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/emqx_exclusive_subscription.erl b/src/emqx_exclusive_subscription.erl index ab26a6bd6..487256903 100644 --- a/src/emqx_exclusive_subscription.erl +++ b/src/emqx_exclusive_subscription.erl @@ -27,6 +27,9 @@ -boot_mnesia({mnesia, [boot]}). -copy_mnesia({mnesia, [copy]}). +%% For upgrade +-export([on_add_module/0, on_delete_module/0]). + -export([ check_subscribe/2, unsubscribe/2 @@ -58,7 +61,22 @@ mnesia(boot) -> {storage_properties, StoreProps} ]); mnesia(copy) -> - ok = ekka_mnesia:copy_table(?TAB, ram_copies). + case ekka_mnesia:copy_table(?TAB, ram_copies) of + ok -> + ok; + {no_exists, _} -> + mnesia(boot) + end. + +%%-------------------------------------------------------------------- +%% Upgrade +%%-------------------------------------------------------------------- + +on_add_module() -> + mnesia(boot). + +on_delete_module() -> + mnesia:clear_table(?TAB). %%-------------------------------------------------------------------- %% APIs