Created
September 18, 2009 12:27
-
-
Save esobchenko/189029 to your computer and use it in GitHub Desktop.
create_table inside mnesia transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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