Files
EventHubBack/src/migrations/20260720210000_calendar_follow.erl
T
aleksey 59220b955e
CI / test (push) Failing after 6m39s
CI / deploy-ift (push) Has been skipped
CI / e2e-ift (push) Has been skipped
CI / deploy-stage (push) Has been skipped
CI / e2e-stage (push) Has been skipped
feat: calendar follow API (POST/DELETE follow, GET following). Refs EventHub/EventHubFront#9
2026-07-20 22:10:48 +03:00

38 lines
1.1 KiB
Erlang
Executable File

%% @doc Create calendar_follow table and indexes if missing.
-module('20260720210000_calendar_follow').
-export([up/0, down/0]).
-include("records.hrl").
up() ->
ensure_table(calendar_follow, record_info(fields, calendar_follow)),
ensure_index(calendar_follow, calendar_id),
ensure_index(calendar_follow, user_id),
ok.
down() ->
_ = mnesia:delete_table(calendar_follow),
ok.
ensure_table(Table, Attrs) ->
case lists:member(Table, mnesia:system_info(tables)) of
true ->
ok;
false ->
case mnesia:create_table(Table, [{disc_copies, [node()]}, {attributes, Attrs}]) of
{atomic, ok} -> ok;
{aborted, {already_exists, Table}} -> ok;
{aborted, Reason} -> error({create_table_failed, Table, Reason})
end
end.
ensure_index(Table, Attr) ->
case mnesia:add_table_index(Table, Attr) of
{atomic, ok} -> ok;
{aborted, {already_exists, Table, _Pos}} -> ok;
{aborted, {already_exists, Table, Attr}} -> ok;
{aborted, {already_exists, _}} -> ok;
{aborted, Reason} -> error({add_index_failed, Table, Attr, Reason})
end.