我有这个记录:
-record(person, {id, token, password, pin, key, salt, pin_salt, subscription_date, first_name, last_name, alias, gender, created_at, birth_year, birth_month, birth_date}).
我有这个创建表person_backup的函数
testcreate()->
mnesia:create_table(person_backup,[{disc_copies, [node()]},{attributes, record_info(fields, person)},
{record_name, person}]).
我有这个函数将数据从表 person 传输到 person_backup
testbackup()->
mnesia:transaction(fun() ->
Records = mnesia:select(person, [{'_', [], ['$_']}]),
[ok = mnesia:write(person_backup, Record, write) || Record <- Records]
end).
我的目标是对我的主要功能进行测试
check(Counter)->
if Counter =:= 40 ->
model:testbackup();
model:reset():
true-> io:format(" it not ok")
end.
但我的问题是当我这样做时 :model:reset()
表 person_backup 将被删除
我的目标是在执行 model:reset() 之前,我们应该将数据从 person 传输到 person_backup
这是reset() 、 destroy() 、 create()的代码
reset() ->
stop(),
destroy(),
create(),
start(),
{ok}.
destroy() ->
mnesia:start(),
mnesia:delete_table(counter),
mnesia:delete_table(person),
mnesia:stop(),
mnesia:delete_schema([node()]).
create() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(counter, [{attributes, record_info(fields, counter)}, {disc_copies, [node()]}]),
mnesia:create_table(person, [{attributes, record_info(fields, person)}, {disc_copies, [node()]}]),
mnesia:create_table(person_backup,[{disc_copies, [node()]},{attributes, record_info(fields, person)},
{record_name, person}]),
mnesia:stop().