fix(share): register calendar_share migration and rebuild old PK schema. Refs EventHub/EventHubBack#73
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
-module(calendar_share_migration_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
setup() ->
|
||||
mnesia:stop(),
|
||||
mnesia:delete_schema([node()]),
|
||||
mnesia:create_schema([node()]),
|
||||
mnesia:start(),
|
||||
{atomic, ok} = mnesia:create_table(calendar_share, [
|
||||
{ram_copies, [node()]},
|
||||
{attributes, [calendar_id, user_id, rights]}
|
||||
]),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
catch mnesia:delete_table(calendar_share),
|
||||
catch mnesia:delete_table(calendar_share_invite),
|
||||
mnesia:stop(),
|
||||
mnesia:delete_schema([node()]),
|
||||
ok.
|
||||
|
||||
calendar_share_migration_test_() ->
|
||||
{foreach, fun setup/0, fun cleanup/1, [
|
||||
{"transforms old calendar_share to id+mirror", fun test_transform_old_share/0},
|
||||
{"idempotent when already new schema", fun test_idempotent_new_schema/0}
|
||||
]}.
|
||||
|
||||
test_transform_old_share() ->
|
||||
%% Pre-#73 row shape: PK = calendar_id (no id / mirror_to_default).
|
||||
ok = mnesia:dirty_write({calendar_share, <<"cal1">>, <<"u1">>, write}),
|
||||
?assertEqual([calendar_id, user_id, rights],
|
||||
mnesia:table_info(calendar_share, attributes)),
|
||||
ok = '20260815220000_calendar_share_invite':up(),
|
||||
?assertEqual(record_info(fields, calendar_share),
|
||||
mnesia:table_info(calendar_share, attributes)),
|
||||
[Rec] = mnesia:dirty_match_object(#calendar_share{calendar_id = <<"cal1">>, _ = '_'}),
|
||||
?assertMatch(#calendar_share{user_id = <<"u1">>, rights = write,
|
||||
mirror_to_default = false}, Rec),
|
||||
?assert(is_binary(Rec#calendar_share.id)),
|
||||
?assert(lists:member(calendar_share_invite, mnesia:system_info(tables))),
|
||||
{ok, Share} = core_calendar_share:upsert(<<"cal2">>, <<"u2">>, admin, true),
|
||||
?assertEqual(admin, Share#calendar_share.rights),
|
||||
?assertEqual(true, Share#calendar_share.mirror_to_default).
|
||||
|
||||
test_idempotent_new_schema() ->
|
||||
ok = '20260815220000_calendar_share_invite':up(),
|
||||
ok = '20260815220000_calendar_share_invite':up(),
|
||||
?assertEqual(record_info(fields, calendar_share),
|
||||
mnesia:table_info(calendar_share, attributes)).
|
||||
@@ -14,7 +14,10 @@
|
||||
"20260720210000_calendar_follow",
|
||||
"20260722150000_calendar_specialist_id",
|
||||
"20260722190000_specialist_invite",
|
||||
"20260730120000_recurrence_exception_bag"
|
||||
"20260730120000_recurrence_exception_bag",
|
||||
"20260814193000_waitlist_entry",
|
||||
"20260815200000_push_subscription",
|
||||
"20260815220000_calendar_share_invite"
|
||||
]).
|
||||
|
||||
setup() ->
|
||||
|
||||
Reference in New Issue
Block a user