fix(event): store multiple recurrence cancel exceptions
Use bag table for recurrence_exception so canceling several WEEKLY occurrences keeps all exceptions (set key was only master_id). Refs EventHub/EventHubFront#42
This commit is contained in:
@@ -321,7 +321,9 @@ table_opts(calendar_follow) -> [{disc_copies, [node()]}, {attributes, record_inf
|
||||
table_opts(calendar_specialist) -> [{disc_copies, [node()]}, {attributes, record_info(fields, calendar_specialist)}];
|
||||
table_opts(specialist_invite) -> [{disc_copies, [node()]}, {attributes, record_info(fields, specialist_invite)}];
|
||||
table_opts(event) -> [{disc_copies, [node()]}, {attributes, record_info(fields, event)}];
|
||||
table_opts(recurrence_exception) -> [{disc_copies, [node()]}, {attributes, record_info(fields, recurrence_exception)}];
|
||||
%% bag: несколько cancel/reschedule на один master_id (ключ set = только master_id).
|
||||
table_opts(recurrence_exception) ->
|
||||
[{disc_copies, [node()]}, {type, bag}, {attributes, record_info(fields, recurrence_exception)}];
|
||||
table_opts(booking) -> [{disc_copies, [node()]}, {attributes, record_info(fields, booking)}];
|
||||
table_opts(review) -> [{disc_copies, [node()]}, {attributes, record_info(fields, review)}];
|
||||
table_opts(review_vote) -> [{disc_copies, [node()]}, {attributes, record_info(fields, review_vote)}];
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
'20260719210000_review_vote',
|
||||
'20260720210000_calendar_follow',
|
||||
'20260722150000_calendar_specialist_id',
|
||||
'20260722190000_specialist_invite'
|
||||
'20260722190000_specialist_invite',
|
||||
'20260730120000_recurrence_exception_bag'
|
||||
]).
|
||||
|
||||
%% ------------------------------
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
%% @doc recurrence_exception: set → bag, чтобы хранить несколько cancel на один master.
|
||||
-module('20260730120000_recurrence_exception_bag').
|
||||
|
||||
-export([up/0, down/0]).
|
||||
|
||||
-include("records.hrl").
|
||||
|
||||
up() ->
|
||||
case lists:member(recurrence_exception, mnesia:system_info(tables)) of
|
||||
false ->
|
||||
case mnesia:create_table(recurrence_exception, [
|
||||
{disc_copies, [node()]},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, recurrence_exception)}
|
||||
]) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, {already_exists, recurrence_exception}} -> ok;
|
||||
{aborted, Reason} -> error({create_table_failed, Reason})
|
||||
end;
|
||||
true ->
|
||||
case mnesia:table_info(recurrence_exception, type) of
|
||||
bag ->
|
||||
ok;
|
||||
_ ->
|
||||
Rows = mnesia:dirty_match_object(#recurrence_exception{_ = '_'}),
|
||||
case mnesia:delete_table(recurrence_exception) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, Reason1} -> error({delete_table_failed, Reason1})
|
||||
end,
|
||||
case mnesia:create_table(recurrence_exception, [
|
||||
{disc_copies, [node()]},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, recurrence_exception)}
|
||||
]) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, Reason2} -> error({create_table_failed, Reason2})
|
||||
end,
|
||||
lists:foreach(fun(R) -> mnesia:dirty_write(R) end, Rows),
|
||||
ok
|
||||
end
|
||||
end.
|
||||
|
||||
down() ->
|
||||
%% Откат в set потерял бы все кроме одного exception на master — не делаем.
|
||||
ok.
|
||||
Reference in New Issue
Block a user