1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| %%%-------------------------------------------------------------------
| %%% @author pansen
| %%% @copyright (C) 2018, <COMPANY>
| %%% @doc
| %%%
| %%% @end
| %%% Created : 01. 八月 2018 16:07
| %%%-------------------------------------------------------------------
| -author("pansen").
|
| -compile(export_all).
|
| %%
| %% 启动数据库,并延时等待数据变更
| %%
| mnesiaDbStart(WaiteTime) ->
| Ret = mnesia:start(),
| if
| Ret == ok ->
| io:format("start wait_for_tables: ~p ~n", [mnesia:system_info(tables)]),
| mnesia:wait_for_tables([mnesia:system_info(tables)], WaiteTime);
| true ->
| io:format(" mnesia:start fail ~p ~n", [Ret])
| end,
| Ret.
|
| %%查看数据库状态
| i() ->
| mnesia:system_info().
|
| %%
| %% 创建数据库的基本表,
| %%
| createDb(Nodes) ->
| io:format("Nodes is [~p]~n", [Nodes]),
| create_schema(Nodes),
| %%%#todo
| device_info:create_deviceInfotable(Nodes, 'device_info'),
| clusterInfo:create_ClusterInfoTable(Nodes, 'cluster_info'),
| %%%#todo
| sys_o_tables:create_sys_table(Nodes, 'sys_o_tables'),
| tableType:create_tableType([node()], 'tableType'),
| i(),
| ok.
|
| %%
| %% 创建数据库的schema
| %% 不对外提供该函数,因其可能删除现在已有数据
| create_schema(Nodes) ->
| mnesia:stop(),
| mnesia:delete_schema([node()]),
| mnesia:start(),
| Re = mnesia:create_schema(Nodes),
| io:format(" mnesia:create_schema(Nodes) ~p~n", [Re]),
| Rtn = mnesia:change_table_copy_type(schema, node(), disc_copies),
| io:format("mnesia:change_table_copy_type ~p~n", [Rtn]).
|
|