feat(archive): month snapshots on the same node, drop extra-node and HTML /view.
Fixes EventHub/EventHubBack#76 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -99,7 +99,8 @@ ensure_indexes(Tables) when is_list(Tables) ->
|
||||
{push_subscription, [user_id, endpoint]},
|
||||
{auth_session, [family_id, subject_id]},
|
||||
{report, [resolved_by]},
|
||||
{ticket, [assigned_to]}
|
||||
{ticket, [assigned_to]},
|
||||
{month_snapshot, [calendar_id, year_month]}
|
||||
]),
|
||||
ok.
|
||||
|
||||
@@ -204,7 +205,9 @@ table_opts(node_metric) ->
|
||||
[{ram_copies, [node()]}, {local_content, true},
|
||||
{attributes, record_info(fields, node_metric)}];
|
||||
table_opts(schema_migration) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, schema_migration)}].
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, schema_migration)}];
|
||||
table_opts(month_snapshot) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, month_snapshot)}].
|
||||
|
||||
%%%===================================================================
|
||||
%%% Domain seeds
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
-module(logic_month_archive_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
-define(TABLES, [event, month_snapshot, booking, calendar]).
|
||||
-define(CAL, <<"cal_arch_1">>).
|
||||
|
||||
setup() ->
|
||||
eh_test_support:start_mnesia(),
|
||||
eh_test_support:ensure_tables(?TABLES),
|
||||
Tmp = filename:join("/tmp", "eh_arch_" ++ integer_to_list(erlang:unique_integer([positive]))),
|
||||
ok = filelib:ensure_dir(filename:join(Tmp, "dummy")),
|
||||
true = os:putenv("UPLOAD_DIR", Tmp),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
eh_test_support:clear_tables(?TABLES),
|
||||
eh_test_support:delete_tables(?TABLES),
|
||||
eh_test_support:stop_mnesia(),
|
||||
ok.
|
||||
|
||||
logic_month_archive_test_() ->
|
||||
{foreach, fun setup/0, fun cleanup/1, [
|
||||
{"closed month is not writable", fun test_assert_writable/0},
|
||||
{"snapshot removes hot event and serves json", fun test_snapshot_roundtrip/0}
|
||||
]}.
|
||||
|
||||
test_assert_writable() ->
|
||||
{{Y, M, _}, _} = calendar:universal_time(),
|
||||
?assertEqual(ok, logic_month_archive:assert_writable({{Y, M, 15}, {12, 0, 0}})),
|
||||
?assertEqual({error, archived},
|
||||
logic_month_archive:assert_writable({{2020, 1, 10}, {12, 0, 0}})).
|
||||
|
||||
test_snapshot_roundtrip() ->
|
||||
{ok, Ev} = core_event:create(?CAL, <<"old">>, {{2020, 6, 10}, {10, 0, 0}}, 60),
|
||||
ok = logic_month_archive:snapshot_month(?CAL, 2020, 6),
|
||||
?assertEqual([], mnesia:dirty_read(event, Ev#event.id)),
|
||||
Json = logic_month_archive:events_json_in_range(
|
||||
?CAL, {{2020, 6, 1}, {0, 0, 0}}, {{2020, 6, 30}, {23, 59, 59}}),
|
||||
?assertEqual(1, length(Json)),
|
||||
[Map] = Json,
|
||||
Id = maps:get(<<"id">>, Map, maps:get(id, Map, undefined)),
|
||||
?assertEqual(Ev#event.id, Id).
|
||||
@@ -18,7 +18,8 @@
|
||||
"20260814193000_waitlist_entry",
|
||||
"20260815200000_push_subscription",
|
||||
"20260815220000_calendar_share_invite",
|
||||
"20260816180000_auth_session_device"
|
||||
"20260816180000_auth_session_device",
|
||||
"20260817140000_month_snapshot"
|
||||
]).
|
||||
|
||||
setup() ->
|
||||
|
||||
Reference in New Issue
Block a user