Skip to content

Instantly share code, notes, and snippets.

@esobchenko
Created September 18, 2009 12:27
Show Gist options
  • Save esobchenko/189029 to your computer and use it in GitHub Desktop.
Save esobchenko/189029 to your computer and use it in GitHub Desktop.
create_table inside mnesia transaction
-module(test).
-compile(export_all).
-record(test, {foo, bar}).
%% fails with "{atomic,{aborted,nested_transaction}}"
add_table1() ->
F = fun() ->
% ...
mnesia:create_table( test1,
[
{ram_copies, [node()]},
{attributes, record_info(fields, test)},
{record_name, test}
]
)
end,
mnesia:transaction(F).
%% do_create_table + schema_transaction works fine
add_table2() ->
F = fun() ->
% ...
Props = [
{ram_copies, [node()]},
{attributes, record_info(fields, test)},
{record_name, test}
],
Cs = mnesia_schema:list2cs([{name, test2}|Props]),
mnesia_schema:do_create_table(Cs)
end,
mnesia_schema:schema_transaction(F).
%% do_create_table + mnesia:transaction works as well
add_table3() ->
F = fun() ->
% ...
Props = [
{ram_copies, [node()]},
{attributes, record_info(fields, test)},
{record_name, test}
],
Cs = mnesia_schema:list2cs([{name, test3}|Props]),
mnesia_schema:do_create_table(Cs)
end,
mnesia:transaction(F).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment