Implement commercial calendars: booking_open, specialists, expire without type downgrade.
Refs EventHub/EventHubBack#54
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
%% @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.
|
||||
Reference in New Issue
Block a user