Files
EventHubBack/src/migrations/20260722150000_calendar_specialist_id.erl
T
aleksey af5f506866
CI / test (push) Successful in 6m44s
CI / deploy-ift (push) Successful in 4m2s
CI / e2e-ift (push) Successful in 1m25s
CI / deploy-stage (push) Successful in 2m25s
CI / e2e-stage (push) Successful in 1m12s
Implement commercial calendars: booking_open, specialists, expire without type downgrade.
Refs EventHub/EventHubBack#54
2026-07-22 16:12:52 +03:00

48 lines
1.5 KiB
Erlang
Executable File

%% @doc calendar_specialist: PK id (было calendar_id — один specialist на календарь).
%% Таблица не использовалась в API — безопасно пересоздать.
-module('20260722150000_calendar_specialist_id').
-export([up/0, down/0]).
-include("records.hrl").
up() ->
case lists:member(calendar_specialist, mnesia:system_info(tables)) of
true ->
Attrs = mnesia:table_info(calendar_specialist, attributes),
case Attrs =:= record_info(fields, calendar_specialist) of
true ->
ok;
false ->
_ = mnesia:delete_table(calendar_specialist),
create_table()
end;
false ->
create_table()
end,
ensure_index(calendar_id),
ensure_index(user_id),
ok.
down() ->
%% откат к старому layout без id не восстанавливаем данные
ok.
create_table() ->
case mnesia:create_table(calendar_specialist, [
{disc_copies, [node()]},
{attributes, record_info(fields, calendar_specialist)}
]) of
{atomic, ok} -> ok;
{aborted, {already_exists, calendar_specialist}} -> ok;
{aborted, Reason} -> error({create_table_failed, calendar_specialist, Reason})
end.
ensure_index(Attr) ->
case mnesia:add_table_index(calendar_specialist, Attr) of
{atomic, ok} -> ok;
{aborted, {already_exists, _, _}} -> ok;
{aborted, {already_exists, _}} -> ok;
{aborted, Reason} -> error({add_index_failed, calendar_specialist, Attr, Reason})
end.