mnesia_schema patch
Ulf Wiger
etxuwig@REDACTED
Mon Mar 10 16:19:05 CET 2003
The attached patch to mnesia_schema (mnesia-4.1.3) exports
the do_delete_table/1 function. This is symmetrical to the
already exported do_create_table/1.
The use of both is to be able to do something like the
following:
add_context(Context) ->
mnesia_schema:schema_transaction(
fun() ->
case mnesia:read(context, Context, read) of
[] ->
mnesia:write(#context{id=Context}),
lists:foreach(
fun({TabName, Opts}) ->
Cs = mnesia_schema:list2cs(
add_name(TabName, Opts)),
mnesia_schema:do_create_table(Cs)
end, sub_tables(Context));
_ ->
mnesia:abort({exists, Context})
end).
remove_context(Context) ->
mnesia_schema:schema_transaction(
fun() ->
case mnesia:read(context,Context, write) of
[_] ->
mnesia:delete(context,Context,write),
lists:foreach(
fun({TabName,_}) ->
mnesia_schema:do_delete_table(TabName)
end, sub_tables(Context));
[] ->
mnesia:abort({not_found, Context})
end).
...without totally messing up your database upon partial
failure.
/Uffe
--
Ulf Wiger, Senior Specialist,
/ / / Architecture & Design of Carrier-Class Software
/ / / Strategic Product & System Management
/ / / Ericsson AB, Connectivity and Control Nodes
-------------- next part --------------
102a103
> do_delete_table/1,
More information about the erlang-patches
mailing list