./ct_report/coverage/mongoose_graphql_mnesia_admin_mutation.COVER.html

1 -module(mongoose_graphql_mnesia_admin_mutation).
2 -behaviour(mongoose_graphql).
3
4 -export([execute/4]).
5
6 -import(mongoose_graphql_helper, [make_error/2, make_error/3]).
7
8 -ignore_xref([execute/4]).
9
10 -include("../mongoose_graphql_types.hrl").
11
12 execute(_Ctx, mnesia, <<"setMaster">>, #{<<"node">> := Node}) ->
13 4 case mnesia_api:set_master(Node) of
14 4 {ok, _} -> {ok, "Master node set"};
15
:-(
Error -> make_error(Error, #{node => Node})
16 end;
17 execute(_Ctx, mnesia, <<"backup">>, #{<<"path">> := Path}) ->
18 8 case mnesia_api:backup_mnesia(binary_to_list(Path)) of
19 4 {ok, _} -> {ok, "Mnesia backup was successfully created"};
20 4 Error -> make_error(Error, #{path => Path})
21 end;
22 execute(_Ctx, mnesia, <<"changeNodename">>, #{<<"fromString">> := FromString,
23 <<"toString">> := ToString, <<"source">> := Source, <<"target">> := Target}) ->
24 6 case mnesia_api:mnesia_change_nodename(FromString, ToString,
25 binary_to_list(Source), binary_to_list(Target)) of
26 2 {ok, _} -> {ok, "Name of the node in the backup was successfully changed"};
27 4 Error -> make_error(Error, #{fromString => FromString, toString => ToString,
28 source => Source, target => Target})
29 end;
30 execute(_Ctx, mnesia, <<"restore">>, #{<<"path">> := Path}) ->
31 10 case mnesia_api:restore_mnesia(binary_to_list(Path)) of
32 2 {ok, _} -> {ok, "Mnesia was successfully restored"};
33 8 Error -> make_error(Error, #{path => Path})
34 end;
35 execute(_Ctx, mnesia, <<"dump">>, #{<<"path">> := Path}) ->
36 6 case mnesia_api:dump_mnesia(binary_to_list(Path)) of
37 4 {ok, _} -> {ok, "Mnesia successfully dumped"};
38 2 Error -> make_error(Error, #{path => Path})
39 end;
40 execute(_Ctx, mnesia, <<"dumpTable">>, #{<<"path">> := Path, <<"table">> := Table}) ->
41 6 case mnesia_api:dump_table(binary_to_list(Path), binary_to_list(Table)) of
42 2 {ok, _} -> {ok, "Mnesia table successfully dumped"};
43 4 Error -> make_error(Error, #{path => Path, table => Table})
44 end;
45 execute(_Ctx, mnesia, <<"load">>, #{<<"path">> := Path}) ->
46 8 case mnesia_api:load_mnesia(binary_to_list(Path)) of
47 2 {ok, _} -> {ok, "Mnesia was successfully loaded"};
48 6 Error -> make_error(Error, #{path => Path})
49 end;
50 execute(_Ctx, mnesia, <<"installFallback">>, #{<<"path">> := Path}) ->
51 2 case mnesia_api:install_fallback_mnesia(binary_to_list(Path)) of
52
:-(
{ok, _} -> {ok, "Fallback installed"};
53 2 Error -> make_error(Error, #{path => Path})
54 end.
Line Hits Source