Рефакторинг обработчиков. Финальное тестирование #21

This commit is contained in:
2026-05-18 14:37:59 +03:00
parent 40806df62a
commit 3abf5c94ee
21 changed files with 630 additions and 89 deletions
+36 -4
View File
@@ -6,7 +6,7 @@
-include("records.hrl").
-export([start_link/0, init_tables/0, wait_for_tables/0]).
-export([start_link/0, init_tables/0, wait_for_tables/0, wait_for_table/1]).
-export([add_cluster_nodes/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -54,6 +54,8 @@ handle_call(init_tables, _From, State) ->
case ExtraNodes of
[] ->
ok = maybe_recreate_schema();
%% ok = migration_engine:init_migrations_table(),
%% _ = migration_engine:apply_pending(); //todo выключил - обваливает кластер, нужно разбираться
_ ->
ok = join_cluster(ExtraNodes)
end,
@@ -61,8 +63,7 @@ handle_call(init_tables, _From, State) ->
ok = create_indices(),
ok = stats_collector:subscribe(),
ok = start_cleanup_timer(),
ok = migration_engine:init_migrations_table(),
_ = migration_engine:apply_pending(),
init_default_admins(),
{reply, ok, State};
handle_call({add_nodes, Nodes}, _From, State) ->
@@ -91,7 +92,7 @@ maybe_recreate_schema() ->
MnesiaDir = mnesia:system_info(directory),
case filelib:is_dir(MnesiaDir) of
false ->
io:format("Mnesia directory not found. Creating fresh schema...~n"),
io:format("Mnesia directory (~s) not found. Creating fresh schema...~n", [MnesiaDir]),
mnesia:stop(),
mnesia:delete_schema([node()]),
mnesia:create_schema([node()]),
@@ -184,6 +185,37 @@ prune_dead_nodes() ->
catch mnesia:del_table_copy(schema, Node)
end, DeadNodes).
%% ---------- Инициализация администраторов ----------
init_default_admins() ->
case core_admin:list_all() of
[] ->
% Суперадмин
SuperEmail = list_to_binary(os:getenv("ADMIN_SUPER_EMAIL", "superadmin@eventhub.local")),
SuperPass = list_to_binary(os:getenv("ADMIN_SUPER_PASSWORD", "123456")),
{ok, _} = core_admin:create(SuperEmail, SuperPass, superadmin),
io:format("Default superadmin created: ~s~n", [SuperEmail]),
% Админ
AdminEmail = list_to_binary(os:getenv("ADMIN_EMAIL", "admin@eventhub.local")),
AdminPass = list_to_binary(os:getenv("ADMIN_PASSWORD", "123456")),
{ok, _} = core_admin:create(AdminEmail, AdminPass, admin),
io:format("Default admin created: ~s~n", [AdminEmail]),
% Модератор
ModerEmail = list_to_binary(os:getenv("ADMIN_MODER_EMAIL", "moderator@eventhub.local")),
ModerPass = list_to_binary(os:getenv("ADMIN_MODER_PASSWORD", "123456")),
{ok, _} = core_admin:create(ModerEmail, ModerPass, moderator),
io:format("Default moderator created: ~s~n", [ModerEmail]),
% Поддержка
SupportEmail = list_to_binary(os:getenv("ADMIN_SUPPORT_EMAIL", "support@eventhub.local")),
SupportPass = list_to_binary(os:getenv("ADMIN_SUPPORT_PASSWORD", "123456")),
{ok, _} = core_admin:create(SupportEmail, SupportPass, support),
io:format("Default support created: ~s~n", [SupportEmail]);
_ ->
io:format("Admins already exist. Skipping creation.~n")
end.
%% ===================================================================
%% Создание / открытие таблиц
%% ===================================================================