[erlang-questions] Mnesia transform_table doesn't work
Chaitanya Chalasani
cchalasani@REDACTED
Sun Feb 17 11:16:00 CET 2019
Hi,
When I run mnesia:transform_table/4 on a table to add a new field, the function returns {atomic, ok} but neither the schema is updated nor the records are transformed.
The transform function is written as -
transform_fields(Tname, FieldsNew) ->
FieldsOld = mnesia:table_info(Tname, attributes),
RecordName = mnesia:table_info(Tname, record_name),
if
FieldsNew == FieldsOld ->
not_needed;
true ->
Transformer = make_transformer(RecordName, FieldsOld, FieldsNew),
mnesia:transform_table(Tname, Transformer, FieldsNew, RecordName),
end.
make_transformer(RecordName, OldFields, NewFields) ->
fun(OldRec) ->
list_to_tuple([RecordName|lists:map(
fun(NewField) ->
case string:str(OldFields, [NewField]) of
0 -> undefined;
Pos -> element(Pos + 1, OldRec)
end
end,
NewFields
)])
end.
The table I was running is -
calls : with 2917589 records occupying 2056606274 words of mem
I am running -
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
/Chaitanya
More information about the erlang-questions
mailing list