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:
@@ -0,0 +1,41 @@
|
||||
%% @doc month_snapshot table (Back#76). disc_only — blobs not in RAM.
|
||||
-module('20260817140000_month_snapshot').
|
||||
|
||||
-export([up/0, down/0]).
|
||||
|
||||
-include("records.hrl").
|
||||
|
||||
up() ->
|
||||
ensure_table(),
|
||||
ensure_index(month_snapshot, calendar_id),
|
||||
ensure_index(month_snapshot, year_month),
|
||||
ok.
|
||||
|
||||
down() ->
|
||||
_ = mnesia:delete_table(month_snapshot),
|
||||
ok.
|
||||
|
||||
ensure_table() ->
|
||||
case lists:member(month_snapshot, mnesia:system_info(tables)) of
|
||||
true ->
|
||||
ok;
|
||||
false ->
|
||||
Attrs = record_info(fields, month_snapshot),
|
||||
case mnesia:create_table(month_snapshot, [
|
||||
{disc_only_copies, [node()]},
|
||||
{attributes, Attrs}
|
||||
]) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, {already_exists, month_snapshot}} -> ok;
|
||||
{aborted, Reason} -> error({create_table_failed, month_snapshot, 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.
|
||||
Reference in New Issue
Block a user